0
|
1 #!/bin/sh
|
|
2 C=Makefile.config
|
|
3
|
|
4 # get full path
|
|
5 case $0 in
|
|
6 /*)
|
|
7 FULL=$0
|
|
8 ;;
|
|
9 *)
|
|
10 FULL=$PWD/$0
|
|
11 ;;
|
|
12 esac
|
|
13
|
|
14 printf "# auto-generated by $0\n" >$C
|
|
15 while [ $# -gt 0 ]; do
|
|
16 X=$1
|
|
17 shift 1
|
|
18 # Shell common:
|
|
19 case $X in
|
|
20 --help|-h|-?)
|
|
21 cat <<EOF
|
|
22 usage: $0 --<option>=<value> <var>=<value> ..
|
|
23
|
|
24 --prefix=<dir>
|
|
25 --target=<platform> uname/special targets: MacOSX,iOS,iPhoneSimulator
|
|
26 --sdk=<version> Mac OS X/iOS SDK version (e.g. '6.1' or '10.9.3')
|
|
27 Tested iOS SDK versions: 4.3, 6.1, 8.1
|
|
28 --sdkroot=<dir>
|
|
29
|
|
30 Useful variables CC, CXX, CFLAGS, CXXFLAGS, etc..
|
|
31
|
|
32 EOF
|
|
33 exit 1
|
|
34 ;;
|
|
35 # GNU Compatibility:
|
|
36 --prefix=*)
|
|
37 PREFIX=`printf -- "${X}" | cut -c 10-`
|
|
38 ;;
|
|
39 --target=*)
|
|
40 TARGET=`printf -- "${X}" | cut -c 10-`
|
|
41 ;;
|
|
42 --sdk=*)
|
|
43 SDK=`printf -- "${X}" | cut -c 7-`
|
|
44 ;;
|
|
45 --sdkroot=*)
|
|
46 SDKROOT=`printf -- "${X}" | cut -c 11-`
|
|
47 ;;
|
|
48 # Environment variables:
|
|
49 [A-Za-z_]*=*)
|
|
50 printf "${X}\n" >>$C
|
|
51 k=`printf "${X}" | cut -d = -f 1`
|
|
52 v=`printf "${X}" | cut -d = -f 2`
|
|
53 export $k="$v"
|
|
54 ;;
|
|
55 # Others fail:
|
|
56 *)
|
|
57 printf "error: invalid option ${X}\n" >&2
|
|
58 exit 1
|
|
59 ;;
|
|
60 esac
|
|
61 done
|
|
62 printf "PREFIX=${PREFIX:=/usr/local}\n" >>$C
|
|
63 case ${TARGET:=`uname`} in
|
|
64 Linux)
|
|
65 if [ -z "${CFLAGS}" ]; then
|
|
66 printf "CFLAGS=-fPIC\n" >>$C
|
|
67 fi
|
|
68 printf "LDLIBS=-lm -ldl\n" >>$C
|
|
69 ;;
|
|
70 OpenBSD)
|
|
71 printf "LDLIBS=-lm\n" >>$C
|
|
72 ;;
|
|
73 DragonFly|NetBSD)
|
|
74 if [ -z "${CFLAGS}" ]; then
|
|
75 printf "CFLAGS=-fPIC\n" >>$C
|
|
76 fi
|
|
77 printf "LDLIBS=-lm\n" >>$C
|
|
78 ;;
|
|
79 FreeBSD)
|
|
80 if [ -z "${CFLAGS}" ]; then
|
|
81 printf "CFLAGS=-fPIC\n" >>$C
|
|
82 fi
|
|
83 printf "LDLIBS=-lm\n" >>$C
|
|
84 printf "RM=rm -f\n" >>$C
|
|
85 ;;
|
|
86 MacOSX|Darwin)
|
|
87 # if Apple's libtool (not to be confused with GNU's) is available, which is according to libtool(1) "with -static [...] intended
|
|
88 # to replace ar(5) and ranlib", use it - if it is shadowed by some install of GNU's libtool assume that a foreign environment is
|
|
89 # intentionally used, and fall back to using 'ar rs' (the equivalent to 'libtool -static'), for compatibility:
|
|
90 if libtool -V >/dev/null 2>/dev/null; then # Apple's libtool has -V for version, which GNU does not.
|
|
91 printf "AR=libtool\n" >>$C
|
|
92 printf "ARFLAGS=-static -o\n" >>$C
|
|
93 else
|
|
94 printf "AR=ar\n" >>$C
|
|
95 printf "ARFLAGS=rs\n" >>$C # 's' is crucial for universal binary archives
|
|
96 fi
|
|
97 if [ `uname -n` = 'iPhone' ]; then # building on iPhone itself, uname yields Darwin (gcc setup for current/correct arch)
|
|
98 printf "CC=gcc\n" >>$C
|
|
99 elif [ -z ${SDK} ]; then
|
|
100 case `sw_vers -productVersion` in
|
|
101 10.4.*)
|
|
102 ARCHS="-arch ppc -arch i386 -arch x86_64"
|
|
103 ;;
|
|
104 10.[56].*)
|
|
105 ARCHS="-arch i386 -arch x86_64 -arch ppc"
|
|
106 ;;
|
|
107 10.6.*)
|
|
108 ARCHS="-arch i386 -arch x86_64"
|
|
109 ;;
|
|
110 10.10.*)
|
|
111 ARCHS="-arch x86_64 -arch i386"
|
|
112 ;;
|
|
113 10.[789].*)
|
|
114 ARCHS="-arch x86_64 -arch i386"
|
|
115 ;;
|
|
116 esac
|
|
117 printf "ASFLAGS=${ARCHS}\n" >>$C
|
|
118 printf "CFLAGS=${ARCHS}\n" >>$C
|
|
119 printf "CXXFLAGS=${ARCHS}\n" >>$C
|
|
120 else
|
|
121 if [ -z ${SDKROOT} ]; then
|
|
122 SDKROOT="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${SDK}.sdk"
|
|
123 fi
|
|
124 printf "CFLAGS=-isysroot ${SDKROOT}\n" >>$C
|
|
125 printf "CXXFLAGS=-isysroot ${SDKROOT}\n" >>$C
|
|
126 fi
|
|
127 ;;
|
|
128 iPhoneOS|iOS)
|
|
129 if [ -z ${SDKROOT} ]; then
|
|
130 SDKROOT="`xcode-select -print-path`/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDK}.sdk"
|
|
131 fi
|
|
132 if [ -z "${ARCHS}" ]; then
|
|
133 case "${SDK}" in
|
|
134 [45].*)
|
|
135 ARCHS="-arch armv6"
|
|
136 ;;
|
|
137 [67].*)
|
|
138 ARCHS="-arch armv7"
|
|
139 ;;
|
|
140 8.*)
|
|
141 ARCHS="-arch armv7 -arch arm64"
|
|
142 ;;
|
|
143 esac
|
|
144 fi
|
|
145 printf "ARFLAGS=rs\n" >>$C # 's' is crucial for universal binary archives
|
|
146 printf "ASFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
147 printf "CFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
148 printf "CXXFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
149 printf "LDFLAGS=-Wl,-syslibroot ${SDKROOT}\n" >>$C
|
|
150 ;;
|
|
151 iPhoneSimulator)
|
|
152 if [ -z ${SDKROOT} ]; then
|
|
153 SDKROOT="`xcode-select -print-path`/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDK}.sdk"
|
|
154 fi
|
|
155 ARCHS="-arch i386"
|
|
156 printf "ASFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
157 printf "CFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
158 printf "CXXFLAGS=${ARCHS} -isysroot ${SDKROOT}\n" >>$C
|
|
159 printf "LDFLAGS=-Wl,-syslibroot ${SDKROOT}\n" >>$C
|
|
160 ;;
|
|
161 SunOS)
|
|
162 # open distributions often don't come with default cc and CC, check for common alternatives.
|
|
163 printf "CC=` (which cc || which gcc || which clang ) | grep -v '^no '`\n" >>$C
|
|
164 printf "CXX=`(which CC || which g++ || which clang++) | grep -v '^no '`\n" >>$C # C++ compiler traditionally named CC
|
|
165 printf "CCC=${CXX}\n" >>$C # Sun make's rules use CCC for c++ compiler
|
|
166 printf "LDLIBS=-lm\n" >>$C
|
|
167 ;;
|
|
168 Minix)
|
|
169 printf "CC=gcc\n" >>$C
|
|
170 printf "CXX=g++\n">>$C
|
|
171 printf "AR=ar\n" >>$C
|
|
172 ;;
|
|
173 PSP)
|
|
174 SDKROOT="`psp-config --pspsdk-path`"
|
|
175 printf "CC=psp-gcc\n" >>$C
|
|
176 printf "CXX=psp-gcc\n">>$C # don't use psp-g++, buggy
|
|
177 printf "AR=psp-ar\n" >>$C
|
|
178 printf "CFLAGS=-I${SDKROOT}/include/\n" >>$C
|
|
179 printf "CXXFLAGS=-I${SDKROOT}/include/\n" >>$C
|
|
180 # Pulling in dyncall libs below is a hack, for some reason psp-ld is super-picky about order.
|
|
181 # Use your C lib of choice, from the PSPSDK, or...
|
|
182 #printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
|
|
183 # ... newlib.
|
|
184 printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
|
|
185 ;;
|
|
186 esac
|
|
187
|
|
188 BLDTOP="$PWD"
|
|
189 SRCTOP=`dirname ${FULL}`
|
|
190
|
|
191 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )`
|
|
192 for FILE in $FILES ; do
|
|
193 SRCFILE="$SRCTOP/$FILE"
|
|
194 BLDFILE="$BLDTOP/$FILE"
|
|
195 SRCDIR=`dirname $SRCFILE`
|
|
196 BLDDIR=`dirname $BLDFILE`
|
|
197 mkdir -p "$BLDDIR"
|
|
198 cat <<EOF >$BLDDIR/Makefile
|
|
199 VPATH = $SRCDIR
|
|
200 include $BLDTOP/Makefile.config
|
|
201 include \${VPATH}/Makefile.generic
|
|
202 EOF
|
|
203 done
|