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