changeset 565:1dadc72cb41f

Add a Makefile with some make/* wrappers, for UI reasons. Remove CC_CRTDIR and move CC_LIBPATH to make/make.sh and explain why (it can still be overridden from configure). Only source ./configure once in make/make.sh so "make native" works (on a platform where you can make that target, anyway).
author Rob Landley <rob@landley.net>
date Tue, 11 Mar 2008 23:51:35 -0500
parents d89a6822b7e0
children 70d322018e75
files Makefile configure make/install.sh make/make.sh
diffstat 4 files changed, 47 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Tue Mar 11 23:51:35 2008 -0500
@@ -0,0 +1,10 @@
+# The build logic isn't really in this makefile, it's in bash scripts in
+# the make directory.  This just provides a familiar user interface.
+
+all native i386 arm c67 win32:
+	make/make.sh $@
+
+install clean test:
+	make/$@.sh
+
+.dummy: all i386 arm c67 win32 install clean test
--- a/configure	Tue Mar 11 23:45:07 2008 -0500
+++ b/configure	Tue Mar 11 23:51:35 2008 -0500
@@ -1,7 +1,10 @@
 #!/bin/bash
 
 # Set lots of environment variables to default values.  All of these are
-# overridden by existing local variables.
+# overridden by existing local variables, if any.
+
+# You don't have to run ./configure before running make, since make/make.sh
+# sources this file, but it shouldn't hurt anything if you do.
 
 [ -z "$CC" ] && CC=cc
 [ -z "$AR" ] && AR=ar
@@ -13,24 +16,23 @@
 [ -z "$HOST" ] && HOST=$(uname -m | sed 's/i.86/i686/')
 [ -z "$PREFIX" ] && PREFIX=/usr/local
 
-
-
 # Set the compiler's search/install paths.
 
-# i386 runs on an x86-64 host, but the library paths are abnormal.
-
-LIB="lib"
-[ "$HOST" == "x86_64" ] && [ TARGET="i386" ] && LIB="lib32"
-
-# Directory for tinycc libraries (such as libtinycc.a) and headers (stdarg.h)
+# Directory for tinycc's own libraries (such as libtinyccrt-$ARCH.a)
+# and headers (such as stdarg.h)
 [ -z "$TINYCC_INSTALLDIR" ] && TINYCC_INSTALLDIR="$PREFIX"/tinycc
-# Where should the linker look for C runtime files (crt1.o, crti.o, crtn.o)
-[ -z "$CC_CRTDIR" ] && CC_CRTDIR="/usr/$LIB"
-# Path to search for system libraries.
-[ -z "$CC_LIBPATH" ] && CC_LIBPATH="/usr/local/$LIB:/usr/$LIB:/$LIB"
 # Path to search for system #include files.
 [ -z "$CC_HEADERPATH" ] && CC_HEADERPATH="/usr/include:/usr/local/include"
 
+# CC_LIBPATH is set in make/make.sh because it varies by target (such as
+# building for i386 on an x86_64 host).  You can set CC_LIBPATH here if you
+# want to, but then it won't vary by target because we don't know what the
+# target _is_ yet.
+#
+# # Path to search for system libraries.
+#
+# [ -z "$CC_LIBPATH" ] && CC_LIBPATH="/usr/local/lib:/usr/lib:/lib"
+
 # For ./configure -v display all the variables we just set.
 
 if [ "$1" == "-v" ]
--- a/make/install.sh	Tue Mar 11 23:45:07 2008 -0500
+++ b/make/install.sh	Tue Mar 11 23:51:35 2008 -0500
@@ -4,7 +4,7 @@
 
 if [ -z "$TINYCC_INSTALLDIR" ]
 then
-  No TINYCC_INSTALLDIR
+  echo 'No $TINYCC_INSTALLDIR' >&2
   exit 1
 fi
 
--- a/make/make.sh	Tue Mar 11 23:45:07 2008 -0500
+++ b/make/make.sh	Tue Mar 11 23:51:35 2008 -0500
@@ -5,6 +5,10 @@
 # With no arguments, builds all targets.  Else build target(s) listed on
 # command line.  Special target "native" builds a native compiler.
 
+# Set "DEBUG=echo" to view the commands instead of running them.
+
+source ./configure
+
 TINYCC_VERSION=0.9.25
 
 DOLOCAL="-B. -I./include -I."
@@ -28,20 +32,31 @@
 
 function build()
 {
-  source ./configure -v
+  # The path at which the new compiler should search for system libraries is,
+  # alas, target dependent.
+
+  if [ -z "$CC_LIBPATH" ]
+  then
+    L="lib"
+    [ "$HOST" == "x86_64" ] && [ TARGET="i386" ] && L="lib32"
+    L="/usr/local/$L:/usr/$L:/$L"
+  else
+    L="$CC_LIBPATH"
+  fi
 
   # Build tinycc with a specific architecture and search paths.
 
-  ARCH=$1 compile_tinycc $1-tinycc_unstripped tcc.c options.c &&
+  ARCH=$1 CC_LIBPATH="$L" compile_tinycc $1-tinycc_unstripped tcc.c options.c &&
   $DEBUG $STRIP $1-tinycc_unstripped -o $1-tinycc
+
   [ $? -ne 0 ] && exit 1
 
   # If this would be a native compiler for this host, create "tinycc" symlink
-  #if [ "$1" == "$HOST" ]
-  #then
+  if [ "$1" == "$HOST" ]
+  then
     $DEBUG rm -f tinycc
     $DEBUG ln -s $1-tinycc tinycc
-  #fi
+  fi
 
   # Compile tinycc as a shared library.
 
@@ -75,5 +90,6 @@
 
 for TARGET in $TARGETS
 do
+  echo Building for target: "$TARGET"
   build $TARGET || exit 1
 done