| 1 |
#!/usr/bin/env bash |
|---|
| 2 |
|
|---|
| 3 |
# A simple script to build libtango.a/libgtango |
|---|
| 4 |
# Copyright (C) 2007 Lars Ivar Igesund |
|---|
| 5 |
# Permission is granted to do anything you please with this software. |
|---|
| 6 |
# This software is provided with no warranty, express or implied, within the |
|---|
| 7 |
# bounds of applicable law. |
|---|
| 8 |
|
|---|
| 9 |
die() { |
|---|
| 10 |
echo "$1" |
|---|
| 11 |
exit $2 |
|---|
| 12 |
} |
|---|
| 13 |
|
|---|
| 14 |
DC= |
|---|
| 15 |
LIB= |
|---|
| 16 |
|
|---|
| 17 |
usage() { |
|---|
| 18 |
echo 'Usage: build-tango.sh <options> identifier |
|---|
| 19 |
Options: |
|---|
| 20 |
--help: Will print this help text |
|---|
| 21 |
--noinline: Will turn off inlining |
|---|
| 22 |
--norelease: Drops optimzations |
|---|
| 23 |
--debug: Will enable debug info |
|---|
| 24 |
--warn: Will enable warnings |
|---|
| 25 |
--verbose: Increase verbosity |
|---|
| 26 |
<identifier> is one of {dmd, gdc, ldc, mac} and will build libtango.a, |
|---|
| 27 |
libgtango.a or universal Mac binaries respectively |
|---|
| 28 |
|
|---|
| 29 |
The script must be called from within lib/ and the resulting |
|---|
| 30 |
binaries will be found there. The build requires that libtango-base-dmd.a/ |
|---|
| 31 |
libgphobos.a already was built.' |
|---|
| 32 |
exit 0 |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
UNAME=`uname` |
|---|
| 36 |
ARCH="" |
|---|
| 37 |
INLINE="-inline" |
|---|
| 38 |
POSIXFLAG="" |
|---|
| 39 |
DEBUG="" |
|---|
| 40 |
RELEASE="-release -O" |
|---|
| 41 |
WARN="" |
|---|
| 42 |
VERBOSE=0 |
|---|
| 43 |
|
|---|
| 44 |
# Compiler specific includes |
|---|
| 45 |
. dmdinclude |
|---|
| 46 |
|
|---|
| 47 |
# Checks for known compiler bugs |
|---|
| 48 |
compilerbugs() { |
|---|
| 49 |
if [ "$DC" = "dmd" ] |
|---|
| 50 |
then |
|---|
| 51 |
dmdbugs |
|---|
| 52 |
fi |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
# Sets up settings for specific compiler versions |
|---|
| 56 |
compilersettings() { |
|---|
| 57 |
if [ "$DC" = "dmd" ] |
|---|
| 58 |
then |
|---|
| 59 |
dmdsettings |
|---|
| 60 |
fi |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
# This filter can probably be improved quite a bit, but should work |
|---|
| 64 |
# on the supported platforms as of April 2008 |
|---|
| 65 |
filter() { |
|---|
| 66 |
|
|---|
| 67 |
FILE=$1 |
|---|
| 68 |
if [ "`echo $FILE | grep group`" ] |
|---|
| 69 |
then |
|---|
| 70 |
return 1 |
|---|
| 71 |
fi |
|---|
| 72 |
|
|---|
| 73 |
if [ "`echo $FILE | grep win32`" -o "`echo $FILE | grep Win32`" ] |
|---|
| 74 |
then |
|---|
| 75 |
return 1 |
|---|
| 76 |
fi |
|---|
| 77 |
|
|---|
| 78 |
if [ "`echo $FILE | grep darwin`" ] |
|---|
| 79 |
then |
|---|
| 80 |
if [ ! "$UNAME" == "Darwin" ] |
|---|
| 81 |
then |
|---|
| 82 |
return 1 |
|---|
| 83 |
else |
|---|
| 84 |
return 0 |
|---|
| 85 |
fi |
|---|
| 86 |
fi |
|---|
| 87 |
|
|---|
| 88 |
if [ "`echo $FILE | grep freebsd`" ] |
|---|
| 89 |
then |
|---|
| 90 |
if [ ! "$UNAME" == "FreeBSD" ] |
|---|
| 91 |
then |
|---|
| 92 |
return 1 |
|---|
| 93 |
else |
|---|
| 94 |
return 0 |
|---|
| 95 |
fi |
|---|
| 96 |
fi |
|---|
| 97 |
|
|---|
| 98 |
if [ "`echo $FILE | grep linux`" ] |
|---|
| 99 |
then |
|---|
| 100 |
if [ ! "$UNAME" == "Linux" ] |
|---|
| 101 |
then |
|---|
| 102 |
return 1 |
|---|
| 103 |
fi |
|---|
| 104 |
fi |
|---|
| 105 |
|
|---|
| 106 |
return 0 |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
# Compile the object files |
|---|
| 110 |
compile() { |
|---|
| 111 |
FILENAME=$1 |
|---|
| 112 |
OBJNAME=`echo $1 | sed -e 's/\.d//' | sed -e 's/\//\./g'` |
|---|
| 113 |
OBJNAME=${OBJNAME}.o |
|---|
| 114 |
|
|---|
| 115 |
if filter $OBJNAME |
|---|
| 116 |
then |
|---|
| 117 |
if [ $VERBOSE == 1 ]; then echo "[$DC] $FILENAME"; fi |
|---|
| 118 |
$DC $ARCH $WARN -c $INLINE $DEBUG $RELEASE $POSIXFLAG -version=Tango -of$OBJNAME $FILENAME |
|---|
| 119 |
if [ "$?" != 0 ] |
|---|
| 120 |
then |
|---|
| 121 |
return 1; |
|---|
| 122 |
fi |
|---|
| 123 |
ar -r lib/$LIB $OBJNAME 2>&1 | grep -v "ranlib: .* has no symbols" |
|---|
| 124 |
rm $OBJNAME |
|---|
| 125 |
fi |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
# Build the libraries |
|---|
| 129 |
build() { |
|---|
| 130 |
|
|---|
| 131 |
DC=$1 |
|---|
| 132 |
LIB=$2 |
|---|
| 133 |
|
|---|
| 134 |
if ! which $DC >& /dev/null |
|---|
| 135 |
then |
|---|
| 136 |
echo "$DC not found on your \$PATH!" |
|---|
| 137 |
return |
|---|
| 138 |
fi |
|---|
| 139 |
|
|---|
| 140 |
# Check if the compiler used has known bugs |
|---|
| 141 |
compilerbugs |
|---|
| 142 |
# Setup compiler specific settings |
|---|
| 143 |
compilersettings |
|---|
| 144 |
|
|---|
| 145 |
if [ ! -e "$3" ] |
|---|
| 146 |
then |
|---|
| 147 |
die "Dependency $3 not present, run build-yourcompiler.sh first" 1 |
|---|
| 148 |
fi |
|---|
| 149 |
|
|---|
| 150 |
cd .. |
|---|
| 151 |
|
|---|
| 152 |
for file in `find tango -name '*.d'` |
|---|
| 153 |
do |
|---|
| 154 |
compile $file |
|---|
| 155 |
if [ "$?" = 1 ] |
|---|
| 156 |
then |
|---|
| 157 |
die "Compilation of $file failed" 1 |
|---|
| 158 |
fi |
|---|
| 159 |
done |
|---|
| 160 |
|
|---|
| 161 |
ranlib lib/$LIB 2>&1 | grep -v "ranlib: .* has no symbols" |
|---|
| 162 |
|
|---|
| 163 |
cd lib |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
ORIGDIR=`pwd` |
|---|
| 167 |
if [ ! "`basename $ORIGDIR`" = "lib" ] |
|---|
| 168 |
then |
|---|
| 169 |
die "You must run this script from the lib directory." 1 |
|---|
| 170 |
fi |
|---|
| 171 |
|
|---|
| 172 |
if [ "$#" == "0" ] |
|---|
| 173 |
then |
|---|
| 174 |
usage |
|---|
| 175 |
fi |
|---|
| 176 |
|
|---|
| 177 |
while [ "$#" != "0" ] |
|---|
| 178 |
do |
|---|
| 179 |
case "$1" in |
|---|
| 180 |
--help) |
|---|
| 181 |
usage |
|---|
| 182 |
;; |
|---|
| 183 |
--warn) |
|---|
| 184 |
WARN="-w" |
|---|
| 185 |
;; |
|---|
| 186 |
--debug) |
|---|
| 187 |
DEBUG="-g -debug" |
|---|
| 188 |
;; |
|---|
| 189 |
--norelease) |
|---|
| 190 |
RELEASE="" |
|---|
| 191 |
;; |
|---|
| 192 |
--noinline) |
|---|
| 193 |
INLINE="" |
|---|
| 194 |
;; |
|---|
| 195 |
--verbose) |
|---|
| 196 |
VERBOSE=1 |
|---|
| 197 |
;; |
|---|
| 198 |
dmd) |
|---|
| 199 |
build dmd libtango-user-dmd.a libtango-base-dmd.a |
|---|
| 200 |
;; |
|---|
| 201 |
gdc) |
|---|
| 202 |
POSIXFLAG="-version=Posix" |
|---|
| 203 |
build gdmd libgtango.a libgphobos.a |
|---|
| 204 |
;; |
|---|
| 205 |
ldc) |
|---|
| 206 |
build ldmd libtango-user-ldc.a build-tango.sh |
|---|
| 207 |
;; |
|---|
| 208 |
mac) |
|---|
| 209 |
POSIXFLAG="-version=Posix" |
|---|
| 210 |
# build Universal Binary version of the Tango library |
|---|
| 211 |
ARCH="-arch ppc" |
|---|
| 212 |
build gdmd libgtango.a.ppc libgphobos.a.ppc |
|---|
| 213 |
ARCH="-arch i386" |
|---|
| 214 |
build gdmd libgtango.a.i386 libgphobos.a.i386 |
|---|
| 215 |
ARCH="-arch ppc64" |
|---|
| 216 |
build gdmd libgtango.a.ppc64 libgphobos.a.ppc64 |
|---|
| 217 |
ARCH="-arch x86_64" |
|---|
| 218 |
build gdmd libgtango.a.x86_64 libgphobos.a.x86_64 |
|---|
| 219 |
lipo -create -output libgtango.a libgtango.a.ppc libgtango.a.i386 \ |
|---|
| 220 |
libgtango.a.ppc64 libgtango.a.x86_64 |
|---|
| 221 |
;; |
|---|
| 222 |
*) |
|---|
| 223 |
usage |
|---|
| 224 |
;; |
|---|
| 225 |
esac |
|---|
| 226 |
shift |
|---|
| 227 |
done |
|---|