changeset 547:9778e985b450

Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to use the compiler itself as a dynamic code generation library.
author Rob Landley <rob@landley.net>
date Thu, 03 Jan 2008 15:04:21 -0600
parents 3f683703c8db
children e0e9974a231b
files make/install.sh make/make.sh tccelf.c tests/libtcc_test.c
diffstat 4 files changed, 28 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/make/install.sh	Fri Dec 28 17:33:06 2007 -0600
+++ b/make/install.sh	Thu Jan 03 15:04:21 2008 -0600
@@ -11,7 +11,7 @@
 # Install libraries and headers
 
 $DEBUG mkdir -p "$TINYCC_INSTALLDIR"/{lib,include} &&
-$DEBUG cp libtinycc-*.a "$TINYCC_INSTALLDIR"/lib &&
+$DEBUG cp libtinyccrt-*.a libtinycc-*.so "$TINYCC_INSTALLDIR"/lib &&
 $DEBUG cp include/* "$TINYCC_INSTALLDIR"/include &&
 
 # Install binaries
--- a/make/make.sh	Fri Dec 28 17:33:06 2007 -0600
+++ b/make/make.sh	Thu Jan 03 15:04:21 2008 -0600
@@ -9,20 +9,30 @@
 
 DOLOCAL="-B. -I./include -I."
 
+# Invoke the compiler with all the appropriate arguments
+
+function compile_tinycc()
+{
+  OUTFILE=$1
+  shift
+  $DEBUG $CC $@ -o $OUTFILE $CFLAGS $LIBS \
+    -DTINYCC_TARGET_$(echo $ARCH | tr a-z A-Z) \
+    -DTINYCC_TARGET='"'$ARCH'"' \
+    -DTINYCC_VERSION='"'$TINYCC_VERSION'"' \
+    -DTINYCC_INSTALLDIR='"'$TINYCC_INSTALLDIR'"' \
+    -DCC_CRTDIR='"'$CC_CRTDIR'"' \
+    -DCC_LIBPATH='"'$CC_LIBPATH'"' \
+    -DCC_HEADERPATH='"'$CC_HEADERPATH'"'
+}
+
+
 function build()
 {
   source ./configure -v
 
   # Build tinycc with a specific architecture and search paths.
 
-  $DEBUG $CC tcc.c options.c -o $1-tinycc_unstripped $CFLAGS $LIBS \
-    -DTINYCC_TARGET_$(echo $1 | tr a-z A-Z) \
-    -DTINYCC_TARGET='"'$1'"' \
-    -DTINYCC_VERSION='"'$TINYCC_VERSION'"' \
-    -DTINYCC_INSTALLDIR='"'$TINYCC_INSTALLDIR'"' \
-    -DCC_CRTDIR='"'$CC_CRTDIR'"' \
-    -DCC_LIBPATH='"'$CC_LIBPATH'"' \
-    -DCC_HEADERPATH='"'$CC_HEADERPATH'"' &&
+  ARCH=$1 compile_tinycc $1-tinycc_unstripped tcc.c options.c &&
   $DEBUG $STRIP $1-tinycc_unstripped -o $1-tinycc
   [ $? -ne 0 ] && exit 1
 
@@ -33,7 +43,11 @@
     $DEBUG ln -s $1-tinycc tinycc
   #fi
 
-  # Build libtinycc1.a
+  # Compile tinycc as a shared library.
+
+  ARCH=$1 compile_tinycc libtinycc-$1.so -shared -fPIC -DLIBTCC tcc.c &&
+
+  # Build libtinyccrt-$ARCH.a (which compiled programs link against)
 
   if [ -f $1/alloca.S ]
   then
@@ -41,7 +55,7 @@
     $DEBUG ./$1-tinycc $DOLOCAL -o libtinycc1-$1.o -c libtinycc1.c &&
     $DEBUG ./$1-tinycc $DOLOCAL -o alloca-$1.o -c $1/alloca.S &&
     $DEBUG ./$1-tinycc $DOLOCAL -o bound-alloca-$1.o -c $1/bound-alloca.S &&
-    $DEBUG $AR rcs libtinycc-$1.a {libtinycc1,alloca,bound-alloca}-$1.o
+    $DEBUG $AR rcs libtinyccrt-$1.a {libtinycc1,alloca,bound-alloca}-$1.o
   fi
 }
 
--- a/tccelf.c	Fri Dec 28 17:33:06 2007 -0600
+++ b/tccelf.c	Thu Jan 03 15:04:21 2008 -0600
@@ -1011,7 +1011,7 @@
     // add libc
     if (!s1->nostdlib) {
         tcc_add_library(s1, "c");
-        tcc_add_library(s1, "tinycc-" TINYCC_TARGET);
+        tcc_add_library(s1, "tinyccrt-" TINYCC_TARGET);
       // add crt end if not memory output
       if (s1->output_type != TCC_OUTPUT_MEMORY)
           tcc_add_file(s1, CC_CRTDIR "/crtn.o");
--- a/tests/libtcc_test.c	Fri Dec 28 17:33:06 2007 -0600
+++ b/tests/libtcc_test.c	Thu Jan 03 15:04:21 2008 -0600
@@ -6,7 +6,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "../libtcc.h"
+#include "../libtinycc.h"
 
 /* this function is called by the generated code */
 int add(int a, int b)
@@ -44,7 +44,7 @@
     }
 
     /* MUST BE CALLED before any compilation or file loading */
-    tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
+    init_output_type(s, TCC_OUTPUT_MEMORY);
 
     tcc_compile_string(s, my_program);