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

Annotation of /libgig/trunk/osx/autoconf_builder.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1640 - (hide annotations) (download) (as text)
Sun Jan 13 16:23:50 2008 UTC (16 years, 3 months ago) by nagata
File MIME type: application/x-sh
File size: 8649 byte(s)
- Modified to make consistent with other subprojects

1 schoenebeck 1172 #!/bin/sh
2     # autoconf_builder.sh
3     # Created by Toshi Nagata on 07/04/18.
4     #
5 schoenebeck 1190 # 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 schoenebeck 1172 # Influential environmental variables:
26     # ACTION(*): autoconf - run "make -f Makefile.cvs"; configure - run "configure";
27 schoenebeck 1190 # 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 schoenebeck 1172 # BUILD_STYLE(*): The build style. If it ends with "ppc" or "i386", it also specifies the architecture.
31 schoenebeck 1190 # 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 schoenebeck 1172 # 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 schoenebeck 1190 # 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 schoenebeck 1172 # SDKROOT: The root directory for SDK
44 schoenebeck 1190 # 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 nagata 1640 # 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 schoenebeck 1172 #
50     # The variables marked with (*) are automatically set by Xcode.
51    
52     BASE_DIR=$PWD
53     BASE_NAME=`basename $PWD`
54 nagata 1640 UB_ARCHS=${UB_ARCHS:-"ppc i386"}
55 schoenebeck 1172
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 nagata 1640 BUILD_BASE_DIR=$PWD/../temp_build
98 schoenebeck 1172 fi
99 schoenebeck 1190 mkdir -p "$BUILD_BASE_DIR" || exit $?
100 nagata 1640 export BUILD_BASE_DIR=`rel2abs "$BUILD_BASE_DIR"`
101 schoenebeck 1172
102     if test -e "$SDKROOT"; then
103     SYSROOT_CFLAGS="-isysroot $SDKROOT"
104     else
105     SYSROOT_CFLAGS=
106     fi
107 nagata 1640 if ! expr "$arg" : ".*/usr/local/bin.*" >/dev/null; then
108     PATH=${PATH/\/usr\/bin/\/usr\/local\/bin:\/usr\/bin}
109     fi
110 schoenebeck 1172 ARCH_CFLAGS=""
111     ARCH_CONFIG_OPTIONS=""
112     case "$BUILD_STYLE" in
113     *ppc)
114     ARCH="ppc"
115     ARCH_CFLAGS="-arch ppc"
116     ;;
117 nagata 1640 *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 schoenebeck 1172 *i386)
127     ARCH="i386"
128     ARCH_CFLAGS="-arch i386 -msse -msse2"
129     ARCH_CONFIG_OPTIONS="--host=i386-apple-darwin8"
130     ;;
131 nagata 1640 *x86_64)
132     ARCH="x86_64"
133     ARCH_CFLAGS="-arch x86_64 -m64"
134     ARCH_CONFIG_OPTIONS="--host=x86_64-apple-darwin8"
135     ;;
136 schoenebeck 1190 *UB)
137 schoenebeck 1172 ARCH="UB"
138 schoenebeck 1190 BUILD_STYLE_BASE=${BUILD_STYLE/UB/}
139 schoenebeck 1172 ;;
140 schoenebeck 1190 *Universal)
141     ARCH="UB"
142     BUILD_STYLE_BASE=${BUILD_STYLE/Universal/}
143     ;;
144 schoenebeck 1172 *)
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 nagata 1640 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 schoenebeck 1190 # Test the existence of the products
180 nagata 1640 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 schoenebeck 1190 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 nagata 1640 archbins=""
203     for arch in $UB_ARCHS; do
204     archbins="$archbins $BUILD_BASE_DIR/${BUILD_STYLE_BASE}${arch}/local/$i"
205     done
206 schoenebeck 1190 mkdir -p "$BUILD_STYLE/local/"`dirname $i` || exit $?
207     echo "Creating universal binary $BUILD_STYLE/local/$i"
208 nagata 1640 lipo -create $archbins -output "$BUILD_STYLE/local/$i" || exit $?
209 schoenebeck 1190 done
210     exit $?
211     fi
212    
213 nagata 1640 export CFLAGS="$SYSROOT_CFLAGS $ARCH_CFLAGS $OPT_CFLAGS $CFLAGS"
214     export CXXFLAGS="$SYSROOT_CFLAGS $ARCH_CFLAGS $OPT_CFLAGS $CXXFLAGS"
215    
216 schoenebeck 1190 # 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 schoenebeck 1172 # Display all environments
223     set
224    
225     cd $BUILD_DIR
226    
227     # Clean if specified
228     if test "x$ACTION" = "xclean"; then
229 schoenebeck 1190 # if test "x$WITH_INSTALL" != "x" -a -e "Makefile"; then
230     # echo "Doing make uninstall"
231     # make uninstall
232     # fi
233 schoenebeck 1172 echo "Removing files in $BUILD_DIR"
234     cd $BASE_DIR
235     rm -rf "$BUILD_DIR"
236 nagata 1640 echo "Removing product files in $BUILD_BASE_DIR/$BUILD_STYLE/local"
237     (cd "$BUILD_BASE_DIR/$BUILD_STYLE/local"; rm -rf $UB_PRODUCTS)
238 schoenebeck 1172 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