]> git.tdb.fi Git - builder.git/blob - bootstrap.sh
Older versions of OS X don't have clang
[builder.git] / bootstrap.sh
1 #!/bin/sh
2 # $Id$
3
4 set -e
5
6 INCLUDEDIR=temp/bootstrap/include
7 REQUIRED="core datafile"
8 CFLAGS="-I$INCLUDEDIR `pkg-config --cflags sigc++-2.0`"
9 LIBS="`pkg-config --libs sigc++-2.0` -lpthread"
10 MACHINE="`uname -m`"
11 SYSTEM="`uname -s`"
12 if [ "$MACHINE" = "x86_64" ]; then
13         MULTIARCH="x86_64-linux-gnu"
14 else
15         MULTIARCH="i386-linux-gnu"
16 fi
17 if [ "$SYSTEM" = "Darwin" ]; then
18         if which clang++ >/dev/null; then
19                 COMPILER="clang++"
20         else
21                 COMPILER="g++"
22         fi
23 else
24         COMPILER="g++"
25 fi
26 if [ -e /usr/lib/libdl.so -o -e /usr/lib/$MULTIARCH/libdl.so ]; then
27         LIBS="$LIBS -ldl"
28 fi
29
30 while [ "$1" ]; do
31         case $1 in
32         --libpath)
33                 shift
34                 LIBPATH="$1"
35                 ;;
36         --libpath=*)
37                 LIBPATH="${1#--libpath=}"
38                 ;;
39         --prefix)
40                 shift
41                 PREFIX="$1"
42                 ;;
43         --prefix=*)
44                 PREFIX="${1#--prefix=}"
45                 ;;
46         --keep-temp)
47                 KEEP_TEMP=yes
48                 ;;
49         *)
50                 echo "Unknown option $1"
51                 exit 1
52                 ;;
53         esac
54         shift
55 done
56
57 if [ -z "$LIBPATH" -o "${LIBPATH%%/*}" ]; then
58         LIBPATH=`pwd`/${LIBPATH:-..}
59 fi
60
61 rm -rf "$INCLUDEDIR"
62 mkdir -p "$INCLUDEDIR/msp"
63
64 sources=source/*.cpp
65
66 missing=""
67 for i in $REQUIRED; do
68         path=`ls -1d $LIBPATH/*$i* 2>/dev/null | head -n1`
69         if [ -z "$path"  -o ! -d "$path/source" ]; then
70                 missing="$missing msp$i"
71         else
72                 headers=`find $path/source \( -name windows -prune \) -o \( -name '*.h' -print \)`
73                 for j in $headers; do
74                         rel=${j#$path/source/}
75                         comp=${rel%%/*}
76                         if [ "$comp" = "$rel" ]; then
77                                 comp=$i
78                         fi
79                         mkdir -p "$INCLUDEDIR/msp/$comp"
80                         ln -sf $j "$INCLUDEDIR/msp/$comp/"
81                 done
82                 sources="$sources `find $path/source \( -name windows -prune \) -o \( -name '*.cpp' -print \)`"
83         fi
84 done
85
86 if [ ! -z "$missing" ]; then
87         echo "The following libraries were not found:$missing"
88         echo "I looked for them in $LIBPATH"
89         echo "If they are somewhere else, please add --libpath=PATH to the command line."
90         exit 1
91 fi
92
93 echo "Compiling builder-stage1.  This may take several minutes."
94 objects=""
95 for i in $sources; do
96         obj=`mktemp temp/bootstrap/XXXXXX`
97         mv $obj $obj.o
98         obj=$obj.o
99         dir=${i%/*}
100         dir=${dir%/unix}
101         flags="$CFLAGS"
102         if [ -d "$dir/unix" ]; then
103                 flags="$flags -iquote $dir -iquote $dir/unix"
104         fi
105         $COMPILER -c $i -o $obj $flags
106         objects="$objects $obj"
107 done
108 $COMPILER $objects -o builder-stage1 $LIBS
109
110 if [ "$KEEP_TEMP" != "yes" ]; then
111         echo "Cleaning up"
112         rm -r temp/bootstrap
113 fi
114
115 echo "Using builder-stage1 to compile builder."
116 ARGS=
117 if [ "$PREFIX" ]; then
118         ARGS="$ARGS --prefix='$PREFIX'"
119 fi
120 eval "./builder-stage1 $ARGS"