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