Mercurial > hg > tinycc
annotate make/make.sh @ 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 | 11d95002dfe1 |
children | ba7d2de6912b |
rev | line source |
---|---|
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/bash |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 # Usage: ./make [ARCH] |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 # |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 # With no arguments, builds all targets. Else build target(s) listed on |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 # command line. Special target "native" builds a native compiler. |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 TINYCC_VERSION=0.9.25 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 DOLOCAL="-B. -I./include -I." |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 |
547
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
12 # Invoke the compiler with all the appropriate arguments |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
13 |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
14 function compile_tinycc() |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
15 { |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
16 OUTFILE=$1 |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
17 shift |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
18 $DEBUG $CC $@ -o $OUTFILE $CFLAGS $LIBS \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
19 -DTINYCC_TARGET_$(echo $ARCH | tr a-z A-Z) \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
20 -DTINYCC_TARGET='"'$ARCH'"' \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
21 -DTINYCC_VERSION='"'$TINYCC_VERSION'"' \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
22 -DTINYCC_INSTALLDIR='"'$TINYCC_INSTALLDIR'"' \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
23 -DCC_CRTDIR='"'$CC_CRTDIR'"' \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
24 -DCC_LIBPATH='"'$CC_LIBPATH'"' \ |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
25 -DCC_HEADERPATH='"'$CC_HEADERPATH'"' |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
26 } |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
27 |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
28 |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 function build() |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 { |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 source ./configure -v |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 # Build tinycc with a specific architecture and search paths. |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 |
547
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
35 ARCH=$1 compile_tinycc $1-tinycc_unstripped tcc.c options.c && |
529
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
36 $DEBUG $STRIP $1-tinycc_unstripped -o $1-tinycc |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 [ $? -ne 0 ] && exit 1 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 # If this would be a native compiler for this host, create "tinycc" symlink |
539
d98d14707471
As long as there's only one target, make the "tinycc" symlink. (Need to
Rob Landley <rob@landley.net>
parents:
538
diff
changeset
|
40 #if [ "$1" == "$HOST" ] |
d98d14707471
As long as there's only one target, make the "tinycc" symlink. (Need to
Rob Landley <rob@landley.net>
parents:
538
diff
changeset
|
41 #then |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 $DEBUG rm -f tinycc |
529
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
43 $DEBUG ln -s $1-tinycc tinycc |
539
d98d14707471
As long as there's only one target, make the "tinycc" symlink. (Need to
Rob Landley <rob@landley.net>
parents:
538
diff
changeset
|
44 #fi |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 |
547
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
46 # Compile tinycc as a shared library. |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
47 |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
48 ARCH=$1 compile_tinycc libtinycc-$1.so -shared -fPIC -DLIBTCC tcc.c && |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
49 |
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
50 # Build libtinyccrt-$ARCH.a (which compiled programs link against) |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 |
529
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
52 if [ -f $1/alloca.S ] |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 then |
529
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
54 $DEBUG mkdir -p lib/$1 |
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
55 $DEBUG ./$1-tinycc $DOLOCAL -o libtinycc1-$1.o -c libtinycc1.c && |
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
56 $DEBUG ./$1-tinycc $DOLOCAL -o alloca-$1.o -c $1/alloca.S && |
df3c131bf2f6
Unfortunately gcc defines things like "i386" to 1 (and not just __i386__
Rob Landley <rob@landley.net>
parents:
528
diff
changeset
|
57 $DEBUG ./$1-tinycc $DOLOCAL -o bound-alloca-$1.o -c $1/bound-alloca.S && |
547
9778e985b450
Rename runtime library to libtinyccrt-$ARCH.a, build libtinycc-$ARCH.so to
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
58 $DEBUG $AR rcs libtinyccrt-$1.a {libtinycc1,alloca,bound-alloca}-$1.o |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 fi |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 } |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 # Figure out what target(s) to build for. |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 [ $# -ne 0 ] && TARGETS="$@" |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 [ "$TARGETS" == "native" ] && TARGETS="$HOST" |
538
0f561eea8d68
Neither are arm and c67. Since all I've tested is i386 (and after a quick
Rob Landley <rob@landley.net>
parents:
537
diff
changeset
|
66 [ -z "$TARGETS" ] && TARGETS="i386" # arm c67 win32 |
517
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 # Build each architecture |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 for TARGET in $TARGETS |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 do |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 build $TARGET || exit 1 |
c1746b069e44
Add make.sh back, along with clean.sh and install.sh.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 done |