i assume, that you are writing a PKGBUILD for the thing you want to compile ...
for gnome (you mentioned /opt/gnome/...), there is a profile file that should be used for building-process. an example build() for PKGBUILD would look like this:
Code:
build() {
[ "$GNOMEDIR" = "" ] && source /etc/profile.d/gnome.sh
cd $startdir/src/$pkgname-$pkgver
./configure --prefix=/opt/gnome \
--disable-schemas-install
make all || return 1
make DESTDIR=$startdir/pkg install
}