github.com -> github.io
[build-cgdb.git] / build
blob69eb0d353c7da616036a55a5953ea68cc3c57317
1 #!/bin/bash
3 # build cgdb script
4 # Copyright (C) 2011,2012,2013 Kyle J. McKay. All rights reserved.
6 # Version 1.1.3
8 set -e
9 PATH="`getconf PATH`"
10 export PATH
11 myname="$0"
12 while [ -L "$myname" ]; do
13 oldname="$myname"
14 myname="$(readlink "$myname")"
15 case "$myname" in /*) :;; *)
16 myname="$(dirname "$oldname")/$myname"
17 esac
18 done
19 unset oldname
20 mydir="$(cd "$(dirname "$myname")" && pwd -P)"
21 myname="$(basename "$myname")"
23 # Version 5.2 is the last GPLv2 version of readline
24 # cgdb requires readline version 5.1 or later
25 READLINE='http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz'
26 READLINE_MD5=e39331f32ad14009b9ff49cc10c5e751
28 CGDB=cgdb-0.6.7.tar.bz2
29 CGDB_MD5=256f1dd960dbf2d5fdfdb1e720124361
31 DMG_NAME=cgdb-0.6.7.dmg
33 # clean if requested
34 if [ "$#" -eq 1 -a "$1" = "clean" ]; then
35 rm -rf "$mydir/installer" "$mydir/local"
36 rm -rf "$mydir/sources/readline" "$mydir/sources/readline-build"
37 rm -rf "$mydir/sources/cgdb" "$mydir/sources/cgdb-build"
38 exit 0
41 echo ""
43 strip1=
44 if ! (tar --strip-path=1 || : ) 2>&1 | grep -Eqi 'unrecognized option|not supported'; then
45 strip1=--strip-path=1
46 elif ! (tar --strip-components=1 || : ) 2>&1 | grep -Eqi 'unrecognized option|not supported'; then
47 strip1=--strip-components=1
49 if [ -z "$strip1" ]; then
50 echo "error: Cannot figure out tar option to strip top level path" >&2
51 exit 1
54 if xs="`type -P xcode-select`"; then
55 SDKROOT="`xcode-select -print-path`"
57 if [ -z "$SDKROOT" ]; then
58 SDKROOT=/Developer
60 SDK104="$SDKROOT/SDKs/MacOSX10.4u.sdk"
61 if [ ! -d "$SDK104" -o ! -r "$SDK104/usr/include/AvailabilityMacros.h" ]; then
62 echo "error: No Mac OS X 10.4u SDK found at $SDK104" >&2
63 exit 1
66 if ! pm="`PATH="$SDKROOT/usr/bin:$SDKROOT/Tools" type -P packagemaker`"; then
67 echo "error: Cannot locate packagemaker executable" >&2
69 if ! sf="`PATH="$SDKROOT/usr/bin:$SDKROOT/Tools" type -P SetFile`"; then
70 echo "error: Cannot locate SetFile executable" >&2
73 if ! fr="`PATH="$PATH:/usr/local/bin:/opt/local/bin:/sw/bin" type -P fakeroot`"; then
74 echo "*** ERROR: missing fakeroot"
75 echo ""
76 echo "error: unable to find fakeroot installation" >&2
77 echo "warning: build proceeding, but no installer will be created" >&2
78 echo "info: see http://mackyle.github.io/fakeroot to install fakeroot" >&2
79 echo ""
80 sleep 2
81 else
82 # try to trigger the fakeroot bug now if it's an old version
83 "$fr" find "$mydir" -print > /dev/null
86 rlgz="$(basename -- "$READLINE")"
87 if [ ! -r "$mydir/sources/$rlgz" ] || [ `md5 -q "$mydir/sources/$rlgz"` != $READLINE_MD5 ]; then
88 echo "*** fetching readline sources from $READLINE"
89 echo ""
90 rm -f "$mydir/sources/$rlgz"
91 curl -f -H "User-Agent:" -L -o "$mydir/sources/$rlgz" "$READLINE"
92 echo ""
93 if [ `md5 -q "$mydir/sources/$rlgz"` != $READLINE_MD5 ]; then
94 echo "error: readline sources md5 mismatch (expected $READLINE_MD5)" >&2
95 exit 1
99 cgbz="$(basename -- "$CGDB")"
100 if [ ! -r "$mydir/sources/$cgbz" ]; then
101 echo "error: missing cgdb source files sources/$cgbz" >&2
102 exit 1
104 if [ `md5 -q "$mydir/sources/$cgbz"` != $CGDB_MD5 ]; then
105 echo "error: cgdb sources md5 mismatch (expected $CGDB_MD5)" >&2
106 exit 1
109 echo "*** expanding sources"
110 rm -rf "$mydir/sources/cgdb" "$mydir/sources/readline"
111 mkdir "$mydir/sources/cgdb" "$mydir/sources/readline"
112 tar -xzf "$mydir/sources/$rlgz" $strip1 --directory="$mydir/sources/readline"
113 tar -xjf "$mydir/sources/$cgbz" $strip1 --directory="$mydir/sources/cgdb"
114 echo ""
116 echo "*** applying patches"
117 echo "tokenizer extensions: adding .cp, .m, .M and .mm"
118 patch -p1 -d "$mydir/sources/cgdb" < "$mydir/patches/tokenizer-exts.patch"
119 echo "line listings: only list 1 line (fixes clang problem)"
120 patch -p1 -d "$mydir/sources/cgdb" < "$mydir/patches/cgdb-0.6.7_clang_fix.patch"
121 echo ""
123 echo "*** preparing local install area"
124 rm -rf "$mydir/local"
125 mkdir "$mydir/local" "$mydir/local/include" "$mydir/local/lib" "$mydir/local/bin" "$mydir/local/share"
126 mkdir "$mydir/local/share/man" "$mydir/local/share/man/man1"
127 (umask 0; ln -s share/man "$mydir/local/man")
128 echo ""
130 CC=gcc-4.0
131 COPT="-Os"
132 ARCH="-arch i386 -arch ppc"
133 OSXDK="-isysroot$SDK104"
134 OSXMN="-mmacosx-version-min=10.4"
135 CFLAGS="$ARCH $OSXDK $OSXMN $COPT"
136 LDFLAGS="-Wl,-search_paths_first,-headerpad_max_install_names,-dead_strip_dylibs"
137 CPATH="$mydir/local/usr/local/include"
138 LIBRARY_PATH="$mydir/local/usr/local/lib"
140 export CC
141 export CFLAGS
142 export LDFLAGS
143 export CPATH
144 export LIBRARY_PATH
146 echo "*** configuring readline"
147 rm -rf "$mydir/sources/readline-build"
148 mkdir "$mydir/sources/readline-build"
149 (cd "$mydir/sources/readline-build" && ../readline/configure --enable-static --disable-shared --prefix="/usr/local")
150 echo ""
152 echo "*** building readline"
153 make -w -C "$mydir/sources/readline-build"
154 echo ""
156 echo "*** installing readline to local area"
157 make -w -C "$mydir/sources/readline-build" DESTDIR="$mydir/local" install
158 echo ""
160 echo "*** configuring cgdb"
161 rm -rf "$mydir/sources/cgdb-build"
162 mkdir "$mydir/sources/cgdb-build"
163 (cd "$mydir/sources/cgdb-build" && ../cgdb/configure --disable-dependency-tracking --with-readline="$mydir/local" --prefix="/usr/local")
164 echo ""
166 echo "*** building cgdb"
167 make -w -C "$mydir/sources/cgdb-build"
168 echo ""
170 echo "*** installing cgdb to local area"
171 make -w -C "$mydir/sources/cgdb-build" DESTDIR="$mydir/local" install
172 echo ""
174 if [ -z "$fr" ]; then
175 echo "*** ERROR: missing fakeroot"
176 echo ""
177 echo "error: unable to find fakeroot installation" >&2
178 echo "warning: no installer will be created" >&2
179 echo "warning: the completed build is in $mydir/local" >&2
180 echo "info: see http://mackyle.github.io/fakeroot to install fakeroot" >&2
181 exit 1
184 echo "*** creating installer image area"
185 if [ -d "$mydir/installer" ]; then
186 chmod -R u+w "$mydir/installer"
188 rm -rf "$mydir/installer"
189 mkdir "$mydir/installer" "$mydir/installer/usrlocal" "$mydir/installer/cgdb"
190 mkdir "$mydir/installer/usrlocal/bin" "$mydir/installer/usrlocal/share"
191 mkdir "$mydir/installer/usrlocal/share/man"
192 mkdir "$mydir/installer/usrlocal/share/man/man1"
193 mkdir "$mydir/installer/usrlocal/share/info"
194 mkdir "$mydir/installer/usrlocal/share/cgdb"
195 cat "$mydir/local/usr/local/bin/cgdb" > "$mydir/installer/usrlocal/bin/cgdb"
196 strip "$mydir/installer/usrlocal/bin/cgdb"
197 cat "$mydir/local/usr/local/share/man/man1/cgdb.1" > "$mydir/installer/usrlocal/share/man/man1/cgdb.1"
198 cat "$mydir/local/usr/local/share/info/cgdb.info" > "$mydir/installer/usrlocal/share/info/cgdb.info"
199 cat "$mydir/local/usr/local/share/cgdb/cgdb.txt" > "$mydir/installer/usrlocal/share/cgdb/cgdb.txt"
200 find "$mydir/installer/usrlocal" ! -type d -print0 | xargs -0 chmod 444
201 chmod 555 "$mydir/installer/usrlocal/bin/cgdb"
202 find "$mydir/installer/usrlocal" -type d -print0 | xargs -0 chmod 755
203 timenow="`date +%s`"
204 stamp="`perl -e '@x=localtime(43200*int($ARGV[0]/43200));printf("%04d%02d%02d%02d%02d.%02d",$x[5]+1900,$x[4]+1,$x[3],$x[2],$x[1],$x[0])' "$timenow"`"
205 stampsf="`perl -e '@x=localtime(43200*int($ARGV[0]/43200));printf("%02d/%02d/%04d %02d:%02d:%02d",$x[4]+1,$x[3],$x[5]+1900,$x[2],$x[1],$x[0])' "$timenow"`"
206 find "$mydir/installer/usrlocal" -print0 | xargs -0n1 "$sf" -d "$stampsf"
207 find "$mydir/installer/usrlocal" -print0 | xargs -0 touch -t "$stamp"
208 echo ""
210 echo "*** preparing installer description files"
211 cat > "$mydir/installer/Description.plist" <<DESCRIPTION
212 <?xml version="1.0" encoding="UTF-8"?>
213 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
214 <plist version="1.0">
215 <dict>
216 <key>IFPkgDescriptionDescription</key>
217 <string>cgdb: the curses debugger</string>
218 <key>IFPkgDescriptionTitle</key>
219 <string>cgdb</string>
220 </dict>
221 </plist>
222 DESCRIPTION
223 cat > "$mydir/installer/Info.plist" <<INFOPLIST
224 <?xml version="1.0" encoding="UTF-8"?>
225 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
226 <plist version="1.0">
227 <dict>
228 <key>CFBundleIdentifier</key>
229 <string>net.sourceforge.cgdb</string>
230 <key>CFBundleGetInfoString</key>
231 <string>cgdb 0.6.7_0</string>
232 <key>CFBundleShortVersionString</key>
233 <string>0.6.7_0</string>
234 <key>CFBundleVersion</key>
235 <string>06.7.0</string>
236 <key>IFMajorVersion</key>
237 <integer>6</integer>
238 <key>IFMinorVersion</key>
239 <integer>7</integer>
240 <key>IFPkgFlagAllowBackRev</key>
241 <true/>
242 <key>IFPkgFlagAuthorizationAction</key>
243 <string>RootAuthorization</string>
244 <key>IFPkgFlagDefaultLocation</key>
245 <string>/usr/local</string>
246 <key>IFPkgFlagFollowLinks</key>
247 <true/>
248 <key>IFPkgFlagInstallFat</key>
249 <true/>
250 <key>IFPkgFlagIsRequired</key>
251 <false/>
252 <key>IFPkgFlagOverwritePermissions</key>
253 <false/>
254 <key>IFPkgFlagRelocatable</key>
255 <false/>
256 <key>IFPkgFlagRestartAction</key>
257 <string>None</string>
258 <key>IFPkgFlagRootVolumeOnly</key>
259 <false/>
260 <key>IFPkgFlagUpdateInstalledLanguages</key>
261 <false/>
262 <key>IFPkgFormatVersion</key>
263 <real>0.10000000149011612</real>
264 </dict>
265 </plist>
266 INFOPLIST
267 echo ""
269 echo "*** creating installer"
270 "$fr" bash -s <<FAKEROOT
271 chown -R root:wheel "$mydir/installer/usrlocal"
272 cat "$mydir/dmg/README_INSTALL.txt" > "$mydir/installer/cgdb/README_INSTALL.txt"
273 "$pm" -build -v -u -p "$mydir/installer/cgdb/cgdb.mpkg" -ds -f "$mydir/installer/usrlocal" -i "$mydir/installer/Info.plist" -d "$mydir/installer/Description.plist" -r "$mydir/resources"
274 find "$mydir/installer/cgdb/cgdb.mpkg/Contents/Resources" -type d -mindepth 1 -print0 | xargs -0 rm -rf
275 cat "$mydir/installer/Description.plist" > "$mydir/installer/cgdb/cgdb.mpkg/Contents/Resources/Description.plist"
276 find "$mydir/installer/cgdb" ! -type d -print0 | xargs -0 chmod 444
277 find "$mydir/installer/cgdb" -type d -print0 | xargs -0 chmod 555
278 find "$mydir/installer/cgdb" -print0 | xargs -0n1 "$sf" -d "$stampsf"
279 find "$mydir/installer/cgdb" -print0 | xargs -0 touch -t "$stamp"
280 hdiutil create -scrub -srcfolder "$mydir/installer/cgdb" "$mydir/installer/cgdb.dmg" -format UDBZ -anyowners -skipunreadable
281 rm -f "$mydir/$DMG_NAME"
282 cat "$mydir/installer/cgdb.dmg" > "$mydir/$DMG_NAME"
283 "$sf" -d "$stampsf" "$mydir/$DMG_NAME"
284 touch -t "$stamp" "$mydir/$DMG_NAME"
285 FAKEROOT
286 echo ""
288 echo "*** cleaning up"
289 rm -rf "$mydir/installer" "$mydir/local"
290 rm -rf "$mydir/sources/readline" "$mydir/sources/readline-build"
291 rm -rf "$mydir/sources/cgdb" "$mydir/sources/cgdb-build"
292 echo ""
294 echo "*** success"
295 echo "Installer located at $mydir/$DMG_NAME"
296 exit 0