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