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
4 4
5TOP ?= .5TOP ?= .
6include $(TOP)/config.mak6include $(TOP)/config.mak
7VPATH = $(top_srcdir)
7 8
8CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC9CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC
9CFLAGS_P=$(CFLAGS) -pg -static10CFLAGS_P=$(CFLAGS) -pg -static
@@ -356,11 +357,11 @@ tcc-doc.html: tcc-doc.texi · 346 unmodified lines
356 -texi2html -monolithic -number $<357 -texi2html -monolithic -number $<
357 358
358tcc.1: tcc-doc.texi359tcc.1: tcc-doc.texi
359 -./texi2pod.pl $< tcc.pod360 -$(top_srcdir)/texi2pod.pl $< tcc.pod
360 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@361 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
361 362
362tcc-doc.info: tcc-doc.texi363tcc-doc.info: tcc-doc.texi
363 -makeinfo tcc-doc.texi364 -makeinfo $<
364 365
365.PHONY: all clean tar distclean install uninstall FORCE366.PHONY: all clean tar distclean install uninstall FORCE
366 367
README+10−0
@@ -35,6 +35,16 @@ Documentation: · 34 unmodified lines
35 make test35 make test
36 make install36 make install
37 37
38Alternatively, VPATH builds are supported: you may use different
39directories 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
38By default, tcc is installed in /usr/local/bin.48By default, tcc is installed in /usr/local/bin.
39./configure --help shows configuration options.49./configure --help shows configuration options.
40 50
configure+29−11
@@ -2,6 +2,14 @@ · 1 unmodified line
2#2#
3# tcc configure script (c) 2003 Fabrice Bellard3# tcc configure script (c) 2003 Fabrice Bellard
4 4
5fn_dirname()
6{
7 case $1 in
8 */*) echo "$1" | sed -e 's,/[^/]*,,';;
9 *) echo '.'
10 esac
11}
12
5# set temporary file name13# set temporary file name
6if test ! -z "$TMPDIR" ; then14if test ! -z "$TMPDIR" ; then
7 TMPDIR1="${TMPDIR}"15 TMPDIR1="${TMPDIR}"
@@ -411,10 +419,13 @@ echo "#define GCC_MAJOR $gcc_major" >> $TMPH · 403 unmodified lines
411echo "HOST_CC=$host_cc" >> config.mak419echo "HOST_CC=$host_cc" >> config.mak
412echo "AR=$ar" >> config.mak420echo "AR=$ar" >> config.mak
413echo "STRIP=$strip -s -R .comment -R .note" >> config.mak421echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
414echo "CFLAGS=$CFLAGS" >> config.mak422cat >> config.mak <<EOF
415echo "LDFLAGS=$LDFLAGS" >> config.mak423CPPFLAGS = -I. -I\$(top_srcdir)
416echo "LIBSUF=$LIBSUF" >> config.mak424CFLAGS=$CFLAGS
417echo "EXESUF=$EXESUF" >> config.mak425LDFLAGS=$LDFLAGS
426LIBSUF=$LIBSUF
427EXESUF=$EXESUF
428EOF
418 429
419if test "$cpu" = "x86" ; then430if test "$cpu" = "x86" ; then
420 echo "ARCH=i386" >> config.mak431 echo "ARCH=i386" >> config.mak
@@ -491,16 +502,23 @@ echo "@set VERSION $version" > config.texi · 70 unmodified lines
491 502
492# build tree in object directory if source path is different from current one503# build tree in object directory if source path is different from current one
493if test "$source_path_used" = "yes" ; then504if test "$source_path_used" = "yes" ; then
494 DIRS="tests"505 FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile"
495 FILES="Makefile tests/Makefile"
496 for dir in $DIRS ; do
497 mkdir -p $dir
498 done
499 for f in $FILES ; do506 for f in $FILES ; do
500 ln -sf $source_path/$f $f507 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
501 done512 done
502fi513fi
503echo "SRC_PATH=$source_path" >> config.mak514cat >>config.mak <<EOF
515SRC_PATH = $source_path
516top_builddir = \$(TOP)
517EOF
518case $source_path in
519 /*) echo 'top_srcdir = $(SRC_PATH)';;
520 *) echo 'top_srcdir = $(TOP)/$(SRC_PATH)';;
521esac >>config.mak
504 522
505diff $TMPH config.h >/dev/null 2>&1523diff $TMPH config.h >/dev/null 2>&1
506if test $? -ne 0 ; then524if test $? -ne 0 ; then
lib/Makefile+1−2
@@ -4,6 +4,7 @@ · 3 unmodified lines
4 4
5TOP = ..5TOP = ..
6include $(TOP)/config.mak6include $(TOP)/config.mak
7VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib
7 8
8ifndef TARGET9ifndef TARGET
9 ifdef CONFIG_WIN6410 ifdef CONFIG_WIN64
@@ -42,8 +43,6 @@ X86_64_O = libtcc1.o alloca86_64.o · 32 unmodified lines
42WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o43WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
43WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o44WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
44 45
45VPATH = $(TOP)/lib $(TOP)/win32/lib
46
47ifeq "$(TARGET)" "i386-win32"46ifeq "$(TARGET)" "i386-win32"
48 OBJ = $(addprefix $(DIR)/,$(WIN32_O))47 OBJ = $(addprefix $(DIR)/,$(WIN32_O))
49 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE48 TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
tests/Makefile+7−6
@@ -4,6 +4,7 @@ · 3 unmodified lines
4 4
5TOP = ..5TOP = ..
6include $(TOP)/Makefile6include $(TOP)/Makefile
7VPATH = $(top_srcdir)/tests
7 8
8# what tests to run9# what tests to run
9TESTS = libtest \10TESTS = libtest \
@@ -56,7 +57,7 @@ endif · 46 unmodified lines
56# run local version of tcc with local libraries and includes57# run local version of tcc with local libraries and includes
57TCC = ../tcc -B.. $(NATIVE_DEFINES)58TCC = ../tcc -B.. $(NATIVE_DEFINES)
58ifdef CONFIG_WIN3259ifdef CONFIG_WIN32
59 TCC := $(TCC) -I $(TOP)/win32/include -L$(TOP)60 TCC := $(TCC) -I $(top_srcdir)/win32/include -L$(top_build)
60endif61endif
61RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..62RUN_TCC = $(NATIVE_DEFINES) -run -DONE_SOURCE ../tcc.c -B..
62DISAS=objdump -d63DISAS=objdump -d
@@ -77,8 +78,8 @@ libtest: libtcc_test$(EXESUF) $(LIBTCC1) · 14 unmodified lines
77 @echo ------------ $@ ------------78 @echo ------------ $@ ------------
78 ./libtcc_test$(EXESUF) lib_path=..79 ./libtcc_test$(EXESUF) lib_path=..
79 80
80libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC)81libtcc_test$(EXESUF): libtcc_test.c $(top_builddir)/$(LIBTCC)
81 $(CC) -o $@ $^ -I.. $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)82 $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS)
82 83
83# test.ref - generate using gcc84# test.ref - generate using gcc
84# copy only tcclib.h so GCC's stddef and stdarg will be used85# 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
169speedtest: ex2 ex3170speedtest: ex2 ex3
170 @echo ------------ $@ ------------171 @echo ------------ $@ ------------
171 time ./ex2 1238 2 3 4 10 13 4172 time ./ex2 1238 2 3 4 10 13 4
172 time $(TCC) -run ../examples/ex2.c 1238 2 3 4 10 13 4173 time $(TCC) -run $(top_srcdir)/examples/ex2.c 1238 2 3 4 10 13 4
173 time ./ex3 35174 time ./ex3 35
174 time $(TCC) -run ../examples/ex3.c 35175 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
175 176
176weaktest: test.ref177weaktest: test.ref
177 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)178 $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
@@ -180,7 +181,7 @@ weaktest: test.ref · 2 unmodified lines
180 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt181 objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
181 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"182 diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
182 183
183ex%: ../examples/ex%.c184ex%: $(top_srcdir)/examples/ex%.c
184 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)185 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
185 186
186# tiny assembler testing187# tiny assembler testing
tests2/Makefile+5−4
@@ -1,5 +1,6 @@
1TOP = ..1TOP = ..
2include $(TOP)/Makefile2include $(TOP)/Makefile
3VPATH = $(top_srcdir)/tests2
3 4
4ifeq ($(TARGETOS),Darwin)5ifeq ($(TARGETOS),Darwin)
5 CFLAGS+=-Wl,-flat_namespace,-undefined,warning6 CFLAGS+=-Wl,-flat_namespace,-undefined,warning
@@ -77,15 +78,15 @@ ifdef CONFIG_WIN32 · 71 unmodified lines
77 TESTS := $(filter-out 28_strings.test,$(TESTS))78 TESTS := $(filter-out 28_strings.test,$(TESTS))
78endif79endif
79 80
80%.test: %.expect %.c81%.test: %.c %.expect
81 @echo Test: $*...82 @echo Test: $*...
82 @if [ "x`echo $* | grep args`" != "x" ]; \83 @if [ "x`echo $* | grep args`" != "x" ]; \
83 then \84 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; \
85 else \86 else \
86 ../tcc -B.. $(TCCFLAGS) -run $*.c 2>&1 >$*.output; \87 ../tcc -B.. $(TCCFLAGS) -run $< 2>&1 >$*.output; \
87 fi88 fi
88 @if diff -bu $*.expect $*.output ; \89 @if diff -bu $(<:.c=.expect) $*.output ; \
89 then \90 then \
90 rm -f $*.output \91 rm -f $*.output \
91 else \92 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