tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] VPATH builds


From: Akim Demaille
Subject: [Tinycc-devel] VPATH builds
Date: Sat, 15 Dec 2012 08:16:40 +0100

Hi all,

The VPATH build in TCC seems to be broken.   I use only VPATH builds for many 
reasons, including the facility to use several compilers in parallel to check a 
single source tree.  The patch below fixes the VPATH builds.

Regards,

        Akim

commit 6200894bd08894c3b2926aed621ec6ab649195de
Author: Akim Demaille <address@hidden>
Date:   Fri Dec 14 17:18:03 2012 +0100

  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.

diff --git a/Makefile b/Makefile
index 48ce697..48a8394 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/configure b/configure
index a400524..b4ac328 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 <<EOF
+CPPFLAGS = -I. -I\$(top_srcdir)
+CFLAGS=$CFLAGS
+LDFLAGS=$LDFLAGS
+LIBSUF=$LIBSUF
+EXESUF=$EXESUF
+EOF

if test "$cpu" = "x86" ; then
 echo "ARCH=i386" >> 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 <<EOF
+SRC_PATH = $source_path
+top_builddir = \$(TOP)
+EOF
+case $source_path in
+  /*) echo 'top_srcdir = $(SRC_PATH)';;
+   *) echo 'top_srcdir = $(TOP)/$(SRC_PATH)';;
+esac >>config.mak

diff $TMPH config.h >/dev/null 2>&1
if test $? -ne 0 ; then
diff --git a/lib/Makefile b/lib/Makefile
index 6813052..a3e2cd1 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 116178f..c183342 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 b6833bd..d328ce7 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 \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]