From 3f09b90d211a86c1d002a786a5ffc34b72fba780 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Fri, 14 Dec 2012 17:18:03 +0100 Subject: [PATCH] build: fix VPATH builds * configure (fn_dirname): New. Use it to ensure the creation of proper symlinks to Makefiles. (config.mak): Define top_builddir and top_srcdir. (CPPFLAGS): Be sure to find the headers. * Makefile, lib/Makefile, tests/Makefile, tests2/Makefile: Adjust to set VPATH properly. Fix confusion between top_builddir and top_srcdir. --- Makefile | 5 +++-- README | 10 ++++++++++ configure | 40 +++++++++++++++++++++++++++++----------- lib/Makefile | 3 +-- tests/Makefile | 13 +++++++------ tests2/Makefile | 9 +++++---- 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 48ce6975..48a83946 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ TOP ?= . include $(TOP)/config.mak +VPATH = $(top_srcdir) CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC CFLAGS_P=$(CFLAGS) -pg -static @@ -356,11 +357,11 @@ tcc-doc.html: tcc-doc.texi -texi2html -monolithic -number $< tcc.1: tcc-doc.texi - -./texi2pod.pl $< tcc.pod + -$(top_srcdir)/texi2pod.pl $< tcc.pod -pod2man --section=1 --center=" " --release=" " tcc.pod > $@ tcc-doc.info: tcc-doc.texi - -makeinfo tcc-doc.texi + -makeinfo $< .PHONY: all clean tar distclean install uninstall FORCE diff --git a/README b/README index 0ead1eea..eedc71cc 100644 --- a/README +++ b/README @@ -35,6 +35,16 @@ Documentation: make test make install +Alternatively, VPATH builds are supported: you may use different +directories to old build objects, kept separate from your source tree: + + mkdir _build + cd _build + ../configure + make + make test + make install + By default, tcc is installed in /usr/local/bin. ./configure --help shows configuration options. diff --git a/configure b/configure index a400524a..b4ac3281 100755 --- a/configure +++ b/configure @@ -2,6 +2,14 @@ # # tcc configure script (c) 2003 Fabrice Bellard +fn_dirname() +{ + case $1 in + */*) echo "$1" | sed -e 's,/[^/]*,,';; + *) echo '.' + esac +} + # set temporary file name if test ! -z "$TMPDIR" ; then TMPDIR1="${TMPDIR}" @@ -411,10 +419,13 @@ echo "#define GCC_MAJOR $gcc_major" >> $TMPH echo "HOST_CC=$host_cc" >> config.mak echo "AR=$ar" >> config.mak echo "STRIP=$strip -s -R .comment -R .note" >> config.mak -echo "CFLAGS=$CFLAGS" >> config.mak -echo "LDFLAGS=$LDFLAGS" >> config.mak -echo "LIBSUF=$LIBSUF" >> config.mak -echo "EXESUF=$EXESUF" >> config.mak +cat >> config.mak <> config.mak @@ -491,16 +502,23 @@ echo "@set VERSION $version" > config.texi # build tree in object directory if source path is different from current one if test "$source_path_used" = "yes" ; then - DIRS="tests" - FILES="Makefile tests/Makefile" - for dir in $DIRS ; do - mkdir -p $dir - done + FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile" for f in $FILES ; do - ln -sf $source_path/$f $f + dir=`fn_dirname "$f"` + test -d "$dir" || mkdir -p "$dir" + back=`echo "$source_path/$dir/" | sed 's,/\./,/,g;s,[^/]*/,../,g'` + back=$back$f + ln -sf $back $f done fi -echo "SRC_PATH=$source_path" >> config.mak +cat >>config.mak <>config.mak diff $TMPH config.h >/dev/null 2>&1 if test $? -ne 0 ; then diff --git a/lib/Makefile b/lib/Makefile index 6813052b..a3e2cd1a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -4,6 +4,7 @@ TOP = .. include $(TOP)/config.mak +VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib ifndef TARGET ifdef CONFIG_WIN64 @@ -42,8 +43,6 @@ X86_64_O = libtcc1.o alloca86_64.o WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o -VPATH = $(TOP)/lib $(TOP)/win32/lib - ifeq "$(TARGET)" "i386-win32" OBJ = $(addprefix $(DIR)/,$(WIN32_O)) TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE diff --git a/tests/Makefile b/tests/Makefile index 116178f7..c1833423 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,6 +4,7 @@ TOP = .. include $(TOP)/Makefile +VPATH = $(top_srcdir)/tests # what tests to run TESTS = libtest \ @@ -56,7 +57,7 @@ endif # run local version of tcc with local libraries and includes TCC = ../tcc -B.. $(NATIVE_DEFINES) ifdef CONFIG_WIN32 - TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP) + TCC := $(TCC) -I $(top_srcdir)/win32/include -L$(top_build) endif RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B.. DISAS=objdump -d @@ -77,8 +78,8 @@ libtest: libtcc_test$(EXESUF) $(LIBTCC1) @echo ------------ $@ ------------ ./libtcc_test$(EXESUF) lib_path=.. -libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC) - $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) +libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC) + $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) # test.ref - generate using gcc # copy only tcclib.h so GCC's stddef and stdarg will be used @@ -169,9 +170,9 @@ btest: boundtest.c ../bcheck.o speedtest: ex2 ex3 @echo ------------ $@ ------------ time ./ex2 1238 2 3 4 10 13 4 - time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4 + time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4 time ./ex3 35 - time $(TCC) -run ../examples/ex3.c 35 + time $(TCC) -run $(top_srcdir)/examples/ex3.c 35 weaktest: test.ref $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) @@ -180,7 +181,7 @@ weaktest: test.ref objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" -ex%: ../examples/ex%.c +ex%: $(top_srcdir)/examples/ex%.c $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) # tiny assembler testing diff --git a/tests2/Makefile b/tests2/Makefile index b6833bd7..d328ce7d 100644 --- a/tests2/Makefile +++ b/tests2/Makefile @@ -1,5 +1,6 @@ TOP = .. include $(TOP)/Makefile +VPATH = $(top_srcdir)/tests2 ifeq ($(TARGETOS),Darwin) CFLAGS+=-Wl,-flat_namespace,-undefined,warning @@ -77,15 +78,15 @@ ifdef CONFIG_WIN32 TESTS := $(filter-out 28_strings.test,$(TESTS)) endif -%.test: %.expect %.c +%.test: %.c %.expect @echo Test: $*... @if [ "x`echo $* | grep args`" != "x" ]; \ then \ - ../tcc -B.. $(TCCFLAGS) -run $*.c - arg1 arg2 arg3 arg4 2>&1 >$*.output; \ + ../tcc -B.. $(TCCFLAGS) -run $< - arg1 arg2 arg3 arg4 2>&1 >$*.output; \ else \ - ../tcc -B.. $(TCCFLAGS) -run $*.c 2>&1 >$*.output; \ + ../tcc -B.. $(TCCFLAGS) -run $< 2>&1 >$*.output; \ fi - @if diff -bu $*.expect $*.output ; \ + @if diff -bu $(<:.c=.expect) $*.output ; \ then \ rm -f $*.output \ else \