[x264-devel] Add out-of-tree build support

Oka Motofumi git at videolan.org
Mon Jan 16 02:11:54 CET 2012


x264 | branch: master | Oka Motofumi <chikuzen.mo at gmail.com> | Thu Jan  5 14:23:50 2012 -0800| [bc6c98cf4f76c779c8c07f43aa97ac29b1150bc0] | committer: Jason Garrett-Glaser

Add out-of-tree build support

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=bc6c98cf4f76c779c8c07f43aa97ac29b1150bc0
---

 Makefile   |   11 ++++++++---
 configure  |   18 +++++++++++++-----
 version.sh |    1 +
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index c9505d3..0858cc7 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,11 @@
 
 include config.mak
 
+vpath %.c $(SRCPATH)
+vpath %.h $(SRCPATH)
+vpath %.S $(SRCPATH)
+vpath %.asm $(SRCPATH)
+
 all: default
 
 SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
@@ -86,7 +91,7 @@ ASFLAGS += -DARCH_X86_64
 endif
 
 ifdef ARCH_X86
-ASFLAGS += -Icommon/x86/
+ASFLAGS += -I$(SRCPATH)/common/x86/
 SRCS   += common/x86/mc-c.c common/x86/predict-c.c
 OBJASM  = $(ASMSRC:%.asm=%.o)
 $(OBJASM): common/x86/x86inc.asm common/x86/x86util.asm
@@ -177,7 +182,7 @@ $(OBJS) $(OBJASM) $(OBJSO) $(OBJCLI) $(OBJCHK): .depend
 
 .depend: config.mak
 	@rm -f .depend
-	@$(foreach SRC, $(SRCS) $(SRCCLI) $(SRCSO), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:%.c=%.o) $(DEPMM) 1>> .depend;)
+	@$(foreach SRC, $(addprefix $(SRCPATH)/, $(SRCS) $(SRCCLI) $(SRCSO)), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:$(SRCPATH)/%.c=%.o) $(DEPMM) 1>> .depend;)
 
 config.mak:
 	./configure
@@ -229,7 +234,7 @@ install-lib-dev:
 	install -d $(DESTDIR)$(includedir)
 	install -d $(DESTDIR)$(libdir)
 	install -d $(DESTDIR)$(libdir)/pkgconfig
-	install -m 644 x264.h $(DESTDIR)$(includedir)
+	install -m 644 $(SRCPATH)/x264.h $(DESTDIR)$(includedir)
 	install -m 644 x264_config.h $(DESTDIR)$(includedir)
 	install -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig
 
diff --git a/configure b/configure
index 4e474ec..43f363a 100755
--- a/configure
+++ b/configure
@@ -212,6 +212,10 @@ die() {
 
 rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest*
 
+SRCPATH="$(cd $(dirname $0); pwd)"
+[ "$SRCPATH" = "$(pwd)" ] && SRCPATH=.
+[ -n "$(echo $SRCPATH | grep ' ')" ] && die "Out of tree builds are impossible with whitespace in source path."
+
 prefix='/usr/local'
 exec_prefix='${prefix}'
 bindir='${exec_prefix}/bin'
@@ -241,7 +245,7 @@ bit_depth="8"
 chroma_format="all"
 compiler="GNU"
 
-CFLAGS="$CFLAGS -Wall -I."
+CFLAGS="$CFLAGS -Wall -I. -I\$(SRCPATH)"
 LDFLAGS="$LDFLAGS"
 LDFLAGSCLI="$LDFLAGSCLI"
 ASFLAGS="$ASFLAGS"
@@ -380,10 +384,10 @@ RANLIB="${RANLIB-${cross_prefix}ranlib}"
 STRIP="${STRIP-${cross_prefix}strip}"
 
 if [ "x$host" = x ]; then
-    host=`./config.guess`
+    host=`${SRCPATH}/config.guess`
 fi
 # normalize a triplet into a quadruplet
-host=`./config.sub $host`
+host=`${SRCPATH}/config.sub $host`
 
 # split $host
 host_cpu="${host%%-*}"
@@ -997,6 +1001,7 @@ EOF
 # generate config files
 
 cat > config.mak << EOF
+SRCPATH=$SRCPATH
 prefix=$prefix
 exec_prefix=$exec_prefix
 bindir=$bindir
@@ -1036,7 +1041,7 @@ if [ "$cli" = "yes" ]; then
 fi
 
 if [ "$shared" = "yes" ]; then
-    API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ')
+    API=$(grep '#define X264_BUILD' < ${SRCPATH}/x264.h | cut -f 3 -d ' ')
     if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
         echo "SONAME=libx264-$API.dll" >> config.mak
         if [ $compiler = ICL ]; then
@@ -1087,7 +1092,7 @@ fi
 echo "LDFLAGSCLI = $LDFLAGSCLI" >> config.mak
 echo "CLI_LIBX264 = $CLI_LIBX264" >> config.mak
 
-./version.sh >> x264_config.h
+${SRCPATH}/version.sh "${SRCPATH}" >> x264_config.h
 
 pclibs="-L$libdir -lx264 $libpthread"
 
@@ -1139,6 +1144,9 @@ cat conftest.log >> config.log
 cat conftest.log
 rm conftest.log
 
+[ "$SRCPATH" != "." ] && ln -sf ${SRCPATH}/Makefile ./Makefile
+mkdir -p common/{arm,ppc,sparc,x86} encoder extras filters/video input output tools
+
 echo
 echo "You can run 'make' or 'make fprofiled' now."
 
diff --git a/version.sh b/version.sh
index 7f06c7c..9a415c6 100755
--- a/version.sh
+++ b/version.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+[ -n "$1" ] && cd $1
 git rev-list HEAD | sort > config.git-hash
 LOCALVER=`wc -l config.git-hash | awk '{print $1}'`
 if [ $LOCALVER \> 1 ] ; then



More information about the x264-devel mailing list