History

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.

Akim Demaille committed 13 years ago

Commit 3f09b901 parent d8158966 files · +55 −25Browse files

Unified · Split

6 files
  1. Makefile +3 −2
  2. README +10 −0
  3. configure +29 −11
  4. lib/Makefile +1 −2
  5. tests/Makefile +7 −6
  6. tests2/Makefile +5 −4
Makefile+3−2
@@ -4,6 +4,7 @@ · 3 unmodified lines
44
55 TOP ?= .
66 include $(TOP)/config.mak
7+VPATH = $(top_srcdir)
78
89 CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC
910 CFLAGS_P=$(CFLAGS) -pg -static
@@ -356,11 +357,11 @@ tcc-doc.html: tcc-doc.texi · 346 unmodified lines
356357 -texi2html -monolithic -number $<
357358
358359 tcc.1: tcc-doc.texi
359− -./texi2pod.pl $< tcc.pod
360+ -$(top_srcdir)/texi2pod.pl $< tcc.pod
360361 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
361362
362363 tcc-doc.info: tcc-doc.texi
363− -makeinfo tcc-doc.texi
364+ -makeinfo $<
364365
365366 .PHONY: all clean tar distclean install uninstall FORCE
366367
README+10−0
@@ -35,6 +35,16 @@ Documentation: · 34 unmodified lines
3535 make test
3636 make install
3737
38+Alternatively, VPATH builds are supported: you may use different
39+directories to old build objects, kept separate from your source tree:
40+
41+ mkdir _build
42+ cd _build
43+ ../configure
44+ make
45+ make test
46+ make install
47+
3848 By default, tcc is installed in /usr/local/bin.
3949 ./configure --help shows configuration options.
4050
configure+29−11
@@ -2,6 +2,14 @@ · 1 unmodified line
22 #
33 # tcc configure script (c) 2003 Fabrice Bellard
44
5+fn_dirname()
6+{
7+ case $1 in
8+ */*) echo "$1" | sed -e 's,/[^/]*,,';;
9+ *) echo '.'
10+ esac
11+}
12+
513 # set temporary file name
614 if test ! -z "$TMPDIR" ; then
715 TMPDIR1="${TMPDIR}"
@@ -411,10 +419,13 @@ echo "#define GCC_MAJOR $gcc_major" >> $TMPH · 403 unmodified lines
411419 echo "HOST_CC=$host_cc" >> config.mak
412420 echo "AR=$ar" >> config.mak
413421 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
414−echo "CFLAGS=$CFLAGS" >> config.mak
415−echo "LDFLAGS=$LDFLAGS" >> config.mak
416−echo "LIBSUF=$LIBSUF" >> config.mak
417−echo "EXESUF=$EXESUF" >> config.mak
422+cat >> config.mak <<EOF
423+CPPFLAGS = -I. -I\$(top_srcdir)
424+CFLAGS=$CFLAGS
425+LDFLAGS=$LDFLAGS
426+LIBSUF=$LIBSUF
427+EXESUF=$EXESUF
428+EOF
418429
419430 if test "$cpu" = "x86" ; then
420431 echo "ARCH=i386" >> config.mak
@@ -491,16 +502,23 @@ echo "@set VERSION $version" > config.texi · 70 unmodified lines
491502
492503 # build tree in object directory if source path is different from current one
493504 if test "$source_path_used" = "yes" ; then
494− DIRS="tests"
495− FILES="Makefile tests/Makefile"
496− for dir in $DIRS ; do
497− mkdir -p $dir
498− done
505+ FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile"
499506 for f in $FILES ; do
500− ln -sf $source_path/$f $f
507+ dir=`fn_dirname "$f"`
508+ test -d "$dir" || mkdir -p "$dir"
509+ back=`echo "$source_path/$dir/" | sed 's,/\./,/,g;s,[^/]*/,../,g'`
510+ back=$back$f
511+ ln -sf $back $f
501512 done
502513 fi
503−echo "SRC_PATH=$source_path" >> config.mak
514+cat >>config.mak <<EOF
515+SRC_PATH = $source_path
516+top_builddir = \$(TOP)
517+EOF
518+case $source_path in
519+ /*) echo 'top_srcdir = $(SRC_PATH)';;
520+ *) echo 'top_srcdir = $(TOP)/$(SRC_PATH)';;
521+esac >>config.mak
504522
505523 diff $TMPH config.h >/dev/null 2>&1
506524 if test $? -ne 0 ; then
lib/Makefile+1−2
@@ -4,6 +4,7 @@ · 3 unmodified lines
44
55 TOP = ..
66 include $(TOP)/config.mak
7+VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib
78
89 ifndef TARGET
910 ifdef CONFIG_WIN64
@@ -42,8 +43,6 @@ X86_64_O = libtcc1.o alloca86_64.o · 32 unmodified lines
4243 WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
4344 WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
4445
45−VPATH = $(TOP)/lib $(TOP)/win32/lib
46−
4746 ifeq "$(TARGET)" "i386-win32"
4847 OBJ = $(addprefix $(DIR)/,$(WIN32_O))
4948 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
tests/Makefile+7−6
@@ -4,6 +4,7 @@ · 3 unmodified lines
44
55 TOP = ..
66 include $(TOP)/Makefile
7+VPATH = $(top_srcdir)/tests
78
89 # what tests to run
910 TESTS = libtest \
@@ -56,7 +57,7 @@ endif · 46 unmodified lines
5657 # run local version of tcc with local libraries and includes
5758 TCC = ../tcc -B.. $(NATIVE_DEFINES)
5859 ifdef CONFIG_WIN32
59− TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP)
60+ TCC := $(TCC) -I $(top_srcdir)/win32/include -L$(top_build)
6061 endif
6162 RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
6263 DISAS=objdump -d
@@ -77,8 +78,8 @@ libtest: libtcc_test$(EXESUF) $(LIBTCC1) · 14 unmodified lines
7778 @echo ------------ $@ ------------
7879 ./libtcc_test$(EXESUF) lib_path=..
7980
80−libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)
81− $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
81+libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
82+ $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
8283
8384 # test.ref - generate using gcc
8485 # copy only tcclib.h so GCC's stddef and stdarg will be used
@@ -169,9 +170,9 @@ btest: boundtest.c ../bcheck.o · 84 unmodified lines
169170 speedtest: ex2 ex3
170171 @echo ------------ $@ ------------
171172 time ./ex2 1238 2 3 4 10 13 4
172− time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4
173+ time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
173174 time ./ex3 35
174− time $(TCC) -run ../examples/ex3.c 35
175+ time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
175176
176177 weaktest: test.ref
177178 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
@@ -180,7 +181,7 @@ weaktest: test.ref · 2 unmodified lines
180181 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
181182 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
182183
183−ex%: ../examples/ex%.c
184+ex%: $(top_srcdir)/examples/ex%.c
184185 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
185186
186187 # tiny assembler testing
tests2/Makefile+5−4
@@ -1,5 +1,6 @@
11 TOP = ..
22 include $(TOP)/Makefile
3+VPATH = $(top_srcdir)/tests2
34
45 ifeq ($(TARGETOS),Darwin)
56 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
@@ -77,15 +78,15 @@ ifdef CONFIG_WIN32 · 71 unmodified lines
7778 TESTS := $(filter-out 28_strings.test,$(TESTS))
7879 endif
7980
80−%.test: %.expect %.c
81+%.test: %.c %.expect
8182 @echo Test: $*...
8283 @if [ "x`echo $* | grep args`" != "x" ]; \
8384 then \
84− ../tcc -B.. $(TCCFLAGS) -run $*.c - arg1 arg2 arg3 arg4 2>&1 >$*.output; \
85+ ../tcc -B.. $(TCCFLAGS) -run $< - arg1 arg2 arg3 arg4 2>&1 >$*.output; \
8586 else \
86− ../tcc -B.. $(TCCFLAGS) -run $*.c 2>&1 >$*.output; \
87+ ../tcc -B.. $(TCCFLAGS) -run $< 2>&1 >$*.output; \
8788 fi
88− @if diff -bu $*.expect $*.output ; \
89+ @if diff -bu $(<:.c=.expect) $*.output ; \
8990 then \
9091 rm -f $*.output \
9192 else \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t