summaryrefslogtreecommitdiffstats
path: root/buildall.sh
blob: 6d5cf09037122065633870759ccba7a43fa1c9ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/bash -xe

mirrorrobot=/home/nasmbuild/gitmirror/robot-wrapper.sh
here=/home/nasmbuild/work
patchdir=/home/nasmbuild/patches
pubdir=/pub/nasm
snapdir="$pubdir"/snapshots
reldir="$pubdir"/releasebuilds
excludedir=/home/nasmbuild/exclude
repo=/pub/git/nasm/nasm.git
tagrepo=/pub/git/nasm/nasm-daily.git
web=/home/www/nasm

DOS4GW=/usr/share/openwatcom/binw/dos4gw.exe
CWSDPMI=/home/nasmbuild/cwsdpmi
READMES=/home/nasmbuild/readmes

export PATH=/home/nasmbuild/bin:/bin:/usr/bin:/usr/local/bin:/opt/watcom/bin

if [ `whoami` != nasmbuild ]; then
    echo "$0: run me as nasmbuild, please" 1>&2
    exit 1
fi

declare -A args
for arg; do args["$arg"]=true; done

if [ -z "${args[locked]}" ]; then
    exec flock -x $here "$0" "$@" locked
fi

cd $here

build () {
    version="$1"
    outdir="$2"
    gitdir="$3"
    rev="$4"

    cpus=$(grep '^processor' < /proc/cpuinfo | wc -l)
    jobs=$((cpus+2))
    export makej="make -j$jobs"

    local -A jobn

    rm -rf nasm-* win32 win64 dos macosx os2 rpmbuild doc html log
    mkdir -p log

    # --- Generate tarballs ---
    (
      cd "$gitdir"
      if [ -d "$patchdir"/"$version" ]; then
	  for p in "$patchdir"/"$version"/*; do
	      git am "$p"
	  done
      fi
      if [ -f ./tools/release ]; then
	  ./tools/release $version $here
      else
	  ./misc/release $version $here
      fi
    )

    # --- Generate Linux RPMs ---
    (
	mkdir -p rpmbuild/i386/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
	do32 rpmbuild -D "%_topdir ${here}/rpmbuild/i386" --target i686 -tb nasm-$version.tar.xz
    ) > log/rpm32 2>&1 &
    jobn[rpm32]=$!
    (
	mkdir -p rpmbuild/x86_64/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
	rpmbuild -D "%_topdir ${here}/rpmbuild/x86_64" -ta nasm-$version.tar.xz
    ) > log/rpm64 2>&1 &
    jobn[rpm64]=$!

    # --- Expand tarballs (generate combined src+doc working tree) ---
    xz -cd nasm-$version-xdoc.tar.xz | tar xf -
    cp -a nasm-$version/doc .

    xz -cd nasm-$version.tar.xz | tar xf -

    # --- Generate Win32 binaries ---
    (
	mkdir -p win32
	cp -a nasm-$version win32
	cd win32/nasm-$version
	LDFLAGS='-s' ./configure --host=i686-w64-mingw32
	$makej LN_S='ln'
	cd ..
	zip -9Dl  ../nasm-$version-win32.zip nasm-$version/LICENSE
	zip -9Drg ../nasm-$version-win32.zip nasm-$version -i \*.exe
	cd nasm-$version
	if [ -f nsis/nasm.nsi ]; then
	    make nsis
	    mv nasm-$version-installer*.exe ../../
	elif [ -f nasm.nsi ]; then
	    makensis nasm.nsi
	    mv nasm-$version-installer.exe ../../nasm-$version-installer-x86.exe
	fi
    ) > log/win32 2>&1 &
    jobn[win32]=$!

    # --- Generate Win64 binaries ---
    (
	mkdir -p win64
	cp -a nasm-$version win64
	cd win64/nasm-$version
	LDFLAGS='-s' ./configure --host=x86_64-w64-mingw32
	$makej LN_S='ln'
	cd ..
	zip -9Dl  ../nasm-$version-win64.zip nasm-$version/LICENSE
	zip -9Drg ../nasm-$version-win64.zip nasm-$version -i \*.exe
	cd nasm-$version
	if [ -f nsis/nasm.nsi ]; then
	    make nsis
	    mv nasm-$version-installer*.exe ../../
	elif [ -f nasm.nsi ]; then
	    makensis nasm.nsi
	    mv nasm-$version-installer.exe ../../nasm-$version-installer-x64.exe
	fi
    ) > log/win64 2>&1 &
    jobn[win64]=$!

    # --- Generate DOS binaries ---
    (
	mkdir -p dos
	cp -a nasm-$version dos
	cd dos/nasm-$version
	LDFLAGS='-s' ./configure --host=i586-pc-msdosdjgpp
	$makej LN_S='ln'
	mv doc/nasmdoc.txt .
	cp $READMES/dos README
	cp $CWSDPMI/bin/cwsdpmi.{exe,doc} .
	cd ..
	zip -9Dl  ../nasm-$version-dos.zip nasm-$version/{LICENSE,README,nasmdoc.txt,cwsdpmi.doc}
	zip -9Drg ../nasm-$version-dos.zip nasm-$version -i \*.exe
	find nasm-$version -name \*.exe -a -not -name cwsdpmi.exe -type f -print0 | \
	    xargs -0r time upx -q --lzma --best --all-filters
	/usr/sbin/hardlink nasm-$version
	zip -9Dl  ../nasm-$version-dos-upx.zip nasm-$version/{LICENSE,README,nasmdoc.txt,cwsdpmi.doc}
	zip -9Drg ../nasm-$version-dos-upx.zip nasm-$version -i \*.exe
    ) > log/dos 2>&1 &
    jobn[dos]=$!

    # --- Generate MacOS X binaries ---
    (
	mkdir -p macosx/nasm-$version
	cp -a nasm-$version macosx/nasm-$version.work
	cd macosx/nasm-$version.work
	CC='darwinx-gcc -arch i386 -arch x86_64 -arch ppc' \
	  ./configure --host=i686-apple-darwin10
	$makej
	mv LICENSE README doc/nasmdoc.pdf ../nasm-$version/
	make install INSTALLROOT=`pwd`/../nasm-$version bindir= mandir=
	make install_rdf INSTALLROOT=`pwd`/../nasm-$version bindir= mandir=
	cd ..
	zip -9Dr ../nasm-$version-macosx.zip nasm-$version
    ) > log/macosx 2>&1 &
    jobn[macosx]=$!

    # --- Generate OS/2 binaries ---
    #mkdir -p os2
    #cp -a nasm-$version os2
    #cd os2/nasm-$version
    #make -f Mkfiles/owlinux.mak os2
    #cd ..
    #zip -9Dl  ../nasm-$version-os2.zip nasm-$version/LICENSE
    #zip -9Drg ../nasm-$version-os2.zip nasm-$version -i \*.exe
    #cd ..

    # --- Wait for job completion and dump logs ---
    ok=true
    set +xe
    for j in rpm32 rpm64 win32 win64 dos macosx; do
	wait ${jobn[$j]}; ws=$?
	err=''
	if [ $ws -ne 0 ]; then
	    ok=false; err=" *** ERROR: $w ***"
	fi

	echo ''
	echo "  === ${j}${err} ==="
	echo ''
	cat log/$j
    done
    set -xe

    # Fail if we stumbled
    $ok that we finished everything ok

    # --- Clean up ---
    rm -rf "$gitdir" nasm-$version log

    # --- Publish resulting output files ---
    mkdir -p "$outdir"
    echo "$rev" > "$outdir"/git.id
    for os in linux win32 win64 dos macosx; do
	mkdir -p "$outdir"/"$os"
    done

    # Sources
    mv -f nasm-${version}.tar.* nasm-${version}.zip "$outdir"
    mv -f nasm-${version}-xdoc.tar.* nasm-${version}-xdoc.zip "$outdir"
    # Win32
    mv -f nasm-${version}-win32.zip "$outdir"/win32/
    mv -f nasm-${version}-installer-x86.exe "$outdir"/win32/
    # Win64
    mv -f nasm-${version}-win64.zip "$outdir"/win64/
    mv -f nasm-${version}-installer-x64.exe "$outdir"/win64/
    # DOS
    mv -f nasm-${version}-dos.zip nasm-${version}-dos-upx.zip "$outdir"/dos/
    # MacOS X
    mv -f nasm-${version}-macosx.zip "$outdir"/macosx/
    # OS/2
    #mv -f nasm-${version}-os2.zip "$outdir"/os2/
    # Linux (RPMS)
    find rpmbuild/i386 -name '*.i?86.rpm' -exec mv -f '{}' "$outdir"/linux/ \;
    find rpmbuild/x86_64 -name '*.rpm' -exec mv -f '{}' "$outdir"/linux/ \;
    ( cd "$outdir"/linux && createrepo_c . )
    # Expanded docs
    cp -a doc "$outdir"/doc

    echo "$version" "$rev" >> build-ids
}

# This gets run for real (tagged) releases
process_release () {
    version="$1"
    outdir="$2"

    rm -rf $web/docs/"$version" $web/xdoc/"$version"
    cp -al "$outdir"/doc/html $web/docs/"$version"
    cp -al "$outdir"/doc $web/xdoc/"$version"
    case "$version" in
	*rc*)
	    # -rc release
	    update_version "$version" $web/version.inc "$pubdir"
	    ;;
	*)
	    if update_version "$version" $web/version.inc "$pubdir" ; then
		( cd $web && rm -f doc && ln -s docs/"$version" doc )
	    fi
	    ;;
    esac
}

rm -rf git git-rel

today=$(date +%Y%m%d)

# Make sure the git repo is up to date
$mirrorrobot force
git clone -s -l $repo git
(cd $tagrepo && git fetch -f) > /dev/null 2>&1
HEAD=$(cd git && git rev-parse HEAD)

#
# Test run?  Make sure to lock the working directory so the
# regular robot doesn't step on us...
#
if [ -n "${args[test]}" ]; then
    rm -rf /var/tmp/nasmtest
    build $(cat git/version)-test /var/tmp/nasmtest git "$HEAD"
    exit 0
fi

#
# Tagged releases...
#
(cd git && git tag) | while read tag; do
    : $tag
    tagref=$(cd git && git rev-parse "$tag")
    if [ x$(cat "$excludedir"/"$tag" 2>/dev/null) != x"$tagref" ]; then
	case "$tag" in
	    nasm-0.99.0[5-9]|nasm-0.99.[1-9]*|nasm-[1-9]*)
		rel_version=$(echo "$tag" | sed -e 's/^nasm-//')
		if [ ! -d "$reldir"/"$rel_version" ]; then
		    rm -rf git-rel
		    git clone -s -l -n git git-rel
		    ( cd git-rel && git checkout "$tag" )
		    tagref=$(cd git-rel && git rev-parse "$tag")
		    # Note: "if ( shellfunc ... ); then" breaks -e... thus this workaround.
		    set +e
		    ( set -e; build "$rel_version" "$reldir"/"$rel_version" git-rel "$tagref" )
		    err=$?
		    set -e
		    if [ $err -eq 0 ]; then
			process_release "$rel_version" "$reldir"/"$rel_version"
		    else
			# Build failed, we don't want to build this exact tag again
			echo "$tagref" > "$excludedir"/"$tag"
		    fi
		fi
		;;
	esac
    fi
done

#
# Daily snapshot...
#
if [ x$HEAD = x$(cat LAST_HEAD) ]; then
    exit 0
fi
if [ -d "$snapdir"/$today ]; then
    # We already did a build today...
    exit 0
fi

snap_version=$(cat git/version)-$today
set +e
( set -e; build "$snap_version" "$snapdir"/$today git "$HEAD" )
err=$?
set -e
if [ $err -eq 0 ]; then
    env GIT_DIR="$tagrepo" git tag -a -f -m "Daily snapshot $today" nasm-"$snap_version"
    env GIT_DIR="$tagrepo" git update-server-info
    ( cd $snapdir && rm -f latest && ln -s $today latest )
fi

echo "$HEAD" > LAST_HEAD