/[svn]/liblscp/trunk/osx/autoconf_builder.sh
ViewVC logotype

Contents of /liblscp/trunk/osx/autoconf_builder.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1641 - (show annotations) (download) (as text)
Sun Jan 13 16:31:45 2008 UTC (10 years, 8 months ago) by nagata
File MIME type: application/x-sh
File size: 8649 byte(s)
* OSX Xcode project files are added (directory osx)

1 #!/bin/sh
2 # autoconf_builder.sh
3 # Created by Toshi Nagata on 07/04/18.
4 #
5 # Copyright 2007 Toshi Nagata.
6 #
7 # Redistribution and use in source and binary forms, with or without modification, are permitted
8 # provided that the following conditions are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright notice, this list of
11 # conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13 # conditions and the following disclaimer in the documentation and/or other materials provided
14 # with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 #
25 # Influential environmental variables:
26 # ACTION(*): autoconf - run "make -f Makefile.cvs"; configure - run "configure";
27 # make - run "make"; install - run "make install";
28 # build (or empty string) - autoconf && configure && make (&& install)
29 # "install" step is only done if WITH_INSTALL is non-empty
30 # BUILD_STYLE(*): The build style. If it ends with "ppc" or "i386", it also specifies the architecture.
31 # If it ends with "UB" or "Universal", it creates the Universal Binaries for the products
32 # specified by $UB_PRODUCTS (see below).
33 # If any of the products are missing, then this script is recursively called for
34 # $BUILD_STYLE's that have "ppc" and "i386" in place of "UB" or "Universal".
35 # WITH_INSTALL: When non-empty, "install" action is automatically done in "build" action.
36 # CFLAGS, CXXFLAGS: Compiler flags
37 # CONFIG_OPTIONS: Options for "configure"
38 # BUILD_BASE_DIR: Temporary building and install directory. By default "$PWD/build". The source
39 # tree is duplicated (by use of symbolic links) in $BUILD_BASE_DIR/$BUILD_STYLE/<basename>.build,
40 # where <basename> is the basename of the toplevel directory of the source tree (which also
41 # should be the current directory when this script is invoked). The product is "installed"
42 # into $BUILD_BASE_DIR/$BUILD_STYLE/local.
43 # SDKROOT: The root directory for SDK
44 # UB_PRODUCTS: The products for which Universal Binaries are to be created. The paths should be
45 # relative to $BUILD_BASE_DIR/$BUILD_STYLE/local. Eg. bin/some_executable, lib/some_library.a.
46 # UB_ARCHS: The target architectures for the "UB" build style. If not specified, "ppc i386" is assumed.
47 # UB_ONEPASS: When non-empty, building "UB" is done with the compiler flag like "-arch i386 -arch ppc".
48 # Otherwise, binaries for each architecture are separately built and combined later by lipo.
49 #
50 # The variables marked with (*) are automatically set by Xcode.
51
52 BASE_DIR=$PWD
53 BASE_NAME=`basename $PWD`
54 UB_ARCHS=${UB_ARCHS:-"ppc i386"}
55
56 function rel2abs () {
57 (cd "$1"; pwd)
58 }
59
60 function abs2rel () {
61 /usr/bin/perl -e 'use File::Spec; print File::Spec->abs2rel($ARGV[0], $ARGV[1]), "\n";' "$1" "$2"
62 }
63
64 function link_recursive () {
65 local arg base i
66 arg="$1"
67 base=`basename "$arg"`
68 if test -d "$arg"; then
69 if expr "$base" = "CVS" "|" `rel2abs "$arg"` = "$BUILD_BASE_DIR" >/dev/null; then
70 echo "Skipping directory $arg"
71 else
72 echo "Copying directory $arg"
73 mkdir -p "$base"
74 cd "$base"
75 if ! expr "$arg" : "^/" >/dev/null; then
76 arg="../$arg"
77 fi
78 for i in "$arg"/*; do
79 link_recursive "$i"
80 done
81 cd ..
82 fi
83 else
84 echo "Linking $arg"
85 ln -sf $arg
86 fi
87 }
88
89 # Sanity checks
90 if test "x$BUILD_STYLE" = "x"; then
91 BUILD_STYLE="Default"
92 fi
93 if test "x$ACTION" = "x"; then
94 ACTION="build"
95 fi
96 if test "x$BUILD_BASE_DIR" = "x"; then
97 BUILD_BASE_DIR=$PWD/../temp_build
98 fi
99 mkdir -p "$BUILD_BASE_DIR" || exit $?
100 export BUILD_BASE_DIR=`rel2abs "$BUILD_BASE_DIR"`
101
102 if test -e "$SDKROOT"; then
103 SYSROOT_CFLAGS="-isysroot $SDKROOT"
104 else
105 SYSROOT_CFLAGS=
106 fi
107 if ! expr "$arg" : ".*/usr/local/bin.*" >/dev/null; then
108 PATH=${PATH/\/usr\/bin/\/usr\/local\/bin:\/usr\/bin}
109 fi
110 ARCH_CFLAGS=""
111 ARCH_CONFIG_OPTIONS=""
112 case "$BUILD_STYLE" in
113 *ppc)
114 ARCH="ppc"
115 ARCH_CFLAGS="-arch ppc"
116 ;;
117 *ppc64)
118 ARCH="ppc64"
119 ARCH_CFLAGS="-arch ppc64"
120 ARCH_CONFIG_OPTIONS="--host=ppc64-apple-darwin8"
121 if expr "$BASE_NAME" : "libsndfile" >/dev/null; then
122 # For shortcut endianness detection in libsndfile 1.0.17
123 export ac_cv_c_byte_order=big
124 fi
125 ;;
126 *i386)
127 ARCH="i386"
128 ARCH_CFLAGS="-arch i386 -msse -msse2"
129 ARCH_CONFIG_OPTIONS="--host=i386-apple-darwin8"
130 ;;
131 *x86_64)
132 ARCH="x86_64"
133 ARCH_CFLAGS="-arch x86_64 -m64"
134 ARCH_CONFIG_OPTIONS="--host=x86_64-apple-darwin8"
135 ;;
136 *UB)
137 ARCH="UB"
138 BUILD_STYLE_BASE=${BUILD_STYLE/UB/}
139 ;;
140 *Universal)
141 ARCH="UB"
142 BUILD_STYLE_BASE=${BUILD_STYLE/Universal/}
143 ;;
144 *)
145 echo "Warning: architecture cannot be recognized from the build style"
146 ARCH="unknown"
147 ;;
148 esac
149
150 case "$BUILD_STYLE" in
151 Development|Default)
152 OPT_CFLAGS="-O2 -g"
153 ;;
154 Deployment*)
155 OPT_CFLAGS="-O3"
156 ;;
157 esac
158
159 if test "x$ARCH" = "xUB"; then
160 for arch in $UB_ARCHS; do
161 case $arch in
162 ppc)
163 ARCH_CFLAGS="$ARCH_CFLAGS -arch ppc"
164 ;;
165 *ppc64)
166 ARCH_CFLAGS="$ARCH_CFLAGS -arch ppc64"
167 ;;
168 *i386)
169 ARCH_CFLAGS="$ARCH_CFLAGS -arch i386 -msse -msse2"
170 ;;
171 *x86_64)
172 ARCH_CFLAGS="$ARCH_CFLAGS -arch x86_64 -m64"
173 ;;
174 esac
175 done
176 fi
177
178 if test "x$ARCH" = "xUB" -a "x$ACTION" != "xclean" -a "x$UB_ONEPASS" = "x"; then
179 # Test the existence of the products
180 for arch in $UB_ARCHS; do
181 style=${BUILD_STYLE_BASE}${arch}
182 # BUILD_STYLE_PPC=${BUILD_STYLE_BASE}ppc
183 # BUILD_STYLE_386=${BUILD_STYLE_BASE}i386
184 # for style in $BUILD_STYLE_PPC $BUILD_STYLE_386; do
185 missing=no
186 for i in $UB_PRODUCTS; do
187 if ! test -e "$BUILD_BASE_DIR/$style/local/$i"; then
188 missing=yes
189 fi
190 done
191 if test "$missing" = "yes"; then
192 BUILD_STYLE_SAVE=$BUILD_STYLE
193 export BUILD_STYLE=$style
194 echo "Building with BUILD_STYLE=$style"
195 /bin/sh $0 || exit $?
196 BUILD_STYLE=$BUILD_STYLE_SAVE
197 fi
198 done
199 mkdir -p "$BUILD_BASE_DIR/$BUILD_STYLE/local" || exit $?
200 cd "$BUILD_BASE_DIR"
201 for i in $UB_PRODUCTS; do
202 archbins=""
203 for arch in $UB_ARCHS; do
204 archbins="$archbins $BUILD_BASE_DIR/${BUILD_STYLE_BASE}${arch}/local/$i"
205 done
206 mkdir -p "$BUILD_STYLE/local/"`dirname $i` || exit $?
207 echo "Creating universal binary $BUILD_STYLE/local/$i"
208 lipo -create $archbins -output "$BUILD_STYLE/local/$i" || exit $?
209 done
210 exit $?
211 fi
212
213 export CFLAGS="$SYSROOT_CFLAGS $ARCH_CFLAGS $OPT_CFLAGS $CFLAGS"
214 export CXXFLAGS="$SYSROOT_CFLAGS $ARCH_CFLAGS $OPT_CFLAGS $CXXFLAGS"
215
216 # Move to the working directory
217 BUILD_DIR="$BUILD_BASE_DIR/$BUILD_STYLE/$BASE_NAME.build"
218 mkdir -p "$BUILD_DIR"
219 BUILD_DIR=`rel2abs "$BUILD_DIR"`
220 CONFIG_OPTIONS="--prefix=$BUILD_BASE_DIR/$BUILD_STYLE/local $CONFIG_OPTIONS"
221
222 # Display all environments
223 set
224
225 cd $BUILD_DIR
226
227 # Clean if specified
228 if test "x$ACTION" = "xclean"; then
229 # if test "x$WITH_INSTALL" != "x" -a -e "Makefile"; then
230 # echo "Doing make uninstall"
231 # make uninstall
232 # fi
233 echo "Removing files in $BUILD_DIR"
234 cd $BASE_DIR
235 rm -rf "$BUILD_DIR"
236 echo "Removing product files in $BUILD_BASE_DIR/$BUILD_STYLE/local"
237 (cd "$BUILD_BASE_DIR/$BUILD_STYLE/local"; rm -rf $UB_PRODUCTS)
238 exit $?
239 fi
240
241 if test "x$ACTION" = "xbuild" -o "x$ACTION" = "xconfigure"; then
242 # Copy the source files if necessary
243 if test ! -e Makefile -a ! -e configure -a ! -e Makefile.cvs; then
244 echo "Copying the source files to $BUILD_DIR"
245 for i in `abs2rel "$BASE_DIR" "$BUILD_DIR"`/*; do
246 link_recursive $i
247 done
248 fi
249 # Make ./configure if necessary
250 if test -e Makefile.cvs -a ! -e configure; then
251 echo "Running make -f Makefile.cvs"
252 make -f Makefile.cvs || exit $?
253 fi
254 # Run ./configure if necessary
255 if test -e configure -a ! -e Makefile; then
256 CONFIG_ARGS="$CONFIG_OPTIONS $ARCH_CONFIG_OPTIONS $CONFIG_ENVS"
257 echo "Running configure $CONFIG_ARGS"
258 ./configure $CONFIG_ARGS || exit $?
259 fi
260 fi
261
262 if test "x$ACTION" = "xbuild" -o "x$ACTION" = "xmake"; then
263 # make
264 echo "Running make"
265 make || exit $?
266 fi
267
268 # make install if specified
269 if test "x$ACTION" = "xinstall" -o "(" "x$ACTION" = "xbuild" -a "x$WITH_INSTALL" != "x" ")"; then
270 echo "Running make install"
271 make install || exit $?
272 fi

  ViewVC Help
Powered by ViewVC