struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / scripts / repack_release.sh
blob43ec8684b73d16128e440fc90a55c00205ba5010
1 #! /bin/bash
3 # repack_release.sh - repack sdcc Linux, Mac OS X and Windows
4 # snapshot build source, binary and doc packages into a sdcc
5 # release package.
7 # Copyright (c) 2009-2012 Borut Razem
9 # This file is part of SDCC.
11 # This software is provided 'as-is', without any express or implied
12 # warranty. In no event will the authors be held liable for any damages
13 # arising from the use of this software.
15 # Permission is granted to anyone to use this software for any purpose,
16 # including commercial applications, and to alter it and redistribute it
17 # freely, subject to the following restrictions:
19 # 1. The origin of this software must not be misrepresented; you must not
20 # claim that you wrote the original software. If you use this software
21 # in a product, an acknowledgment in the product documentation would be
22 # appreciated but is not required.
23 # 2. Altered source versions must be plainly marked as such, and must not be
24 # misrepresented as being the original software.
25 # 3. This notice may not be removed or altered from any source distribution.
27 # Borut Razem
28 # borut.razem@gmail.com
30 # Example:
31 # ./repack_release.sh -dl -pr -ul 20090314 5413 2.9.0-rc1
34 # Uncomment next line to debug this script
35 #set -vx
37 function fatal_error()
39 echo "repack_release: $1" 1>&2
40 exit 1;
44 function usage()
46 echo "Usage: repack_release.sh [-h] [--help] [-dl] [-pr] [-ul] <date> <revision> <version>" 1>&2
47 echo "Repack sdcc Linux, Mac OS X and Windows snapshot build source," 1>&2
48 echo "binary and doc packages into a sdcc release package." 1>&2
49 echo "Options:" 1>&2
50 echo " -dl download before processing" 1>&2
51 echo " -pr process packages" 1>&2
52 echo " -ul upload after processing" 1>&2
53 echo " <none> download, process and upload" 1>&2
54 echo " -h --help print this usage and exit" 1>&2
55 echo "Arguments:" 1>&2
56 echo " <date> package date in YYYMMDD format, for example 20090314" 1>&2
57 echo " <revision> svn revision number, for example 5413" 1>&2
58 echo " <version> package version number, for example 2.9.0-rc1" 1>&2
59 exit 1;
63 function download()
65 local date=$1 revision=$2
67 mkdir -p dl
69 if ! pushd dl
70 then
71 fatal_error "Cannot cd to dl!"
72 else
73 ( \
74 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/sdcc-src/sdcc-src-${date}-${revision}.tar.bz2 && \
75 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/docs/sdcc-doc-${date}-${revision}.tar.bz2 && \
76 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/docs/sdcc-doc-${date}-${revision}.zip && \
77 # wget http://sourceforge.net/projects/sdcc/files/snapshot_builds/i386-unknown-linux2.5/sdcc-snapshot-i386-unknown-linux2.5-${date}-${revision}.tar.bz2 && \
78 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/amd64-unknown-linux2.5/sdcc-snapshot-amd64-unknown-linux2.5-${date}-${revision}.tar.bz2 && \
79 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/i586-mingw32msvc/sdcc-snapshot-i586-mingw32msvc-${date}-${revision}.zip && \
80 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/x86_64-w64-mingw32/sdcc-snapshot-x86_64-w64-mingw32-${date}-${revision}.zip && \
81 wget https://sourceforge.net/projects/sdcc/files/snapshot_builds/x86_64-apple-macosx/sdcc-snapshot-x86_64-apple-macosx-${date}-${revision}.tar.bz2 \
82 ) || fatal_error "Cannot download snapshot build packages!"
84 # a rename is required when another snapshot is taken as the source for the release
85 # mv sdcc-snapshot-i386_universal-apple-macosx-${date}-${revision}.tar.bz2 sdcc-snapshot-universal-apple-macosx-${date}-${revision}.tar.bz2
87 popd
92 function unpack()
94 local bin_pkg=$1 doc_pkg=$2
96 if [ -z "$(expr $(basename $bin_pkg) : 'sdcc-snapshot-\([^-]*-[^-]*-[^-]*\)-.*\.tar\.bz2')" ]
97 then
98 fatal_error "$bin_pkg is not a sdcc binary package!"
101 if [ -d sdcc ]
102 then
103 fatal_error "Directory sdcc already exists!"
106 tar -xjvf ${bin_pkg} || fatal_error "Cannot unpack $bin_pkg!"
108 # remove unneeded directories produced by sdbinutils
109 rm -rf ./sdcc/include
110 rm -rf ./sdcc/lib
112 rm -rf ./sdcc/share/doc
113 rm -rf ./sdcc/share/sdcc/doc
115 tar -xjvf ${doc_pkg} -C ./sdcc/share/sdcc || fatal_error "Cannot unpack $doc_pkg!"
119 function pack()
121 local arch=$1 ver=$2
123 cp ./sdcc/share/sdcc/doc/INSTALL.txt ./sdcc
124 cp ./sdcc/share/sdcc/doc/README.txt ./sdcc
126 mkdir -p ul
128 mv sdcc sdcc-${ver}
129 tar -cjvf ul/sdcc-${ver}-${arch}.tar.bz2 sdcc-${ver} || fatal_error "Cannot pack ul/sdcc-${ver}-${arch}.tar.bz2!"
130 mv sdcc-${ver} ${arch}
134 function repack_src()
136 local date=$1 revision=$2 ver=$3
139 tar -xjvf dl/sdcc-src-${date}-${revision}.tar.bz2 && \
140 mv sdcc sdcc-${ver} && \
141 tar -cjvf ul/sdcc-src-${ver}.tar.bz2 sdcc-${ver} && \
142 mv sdcc-${ver} sdcc-src-${ver} \
143 ) || fatal_error "Cannot repack the source package!"
147 function repack_win()
149 local date=$1 revision=$2 ver=$3 arch=$4
151 snapshot=../sdcc-src-${ver}
152 ver_maj=$(expr $ver : '\([0-9]*\)\.')
153 ver_min=$(expr $ver : '[0-9]*\.\([0-9]*\)\.')
154 ver_rev=$(expr $ver : '[0-9]*\.[0-9]*\.\([0-9]*\)')
156 if [[ ${arch} == *64* ]]
157 then
158 win="-DWIN64"
159 setup="x64-setup"
160 else
161 win=
162 setup="setup"
165 # - unpack WIN32 mingw daily snapshot sdcc-snapshot-i586-mingw32msvc-yyyymmdd-rrrr.zip
166 # to a clean directory (the option to create directories should be enabled).
167 # A sub directory sdcc is created (referenced as PKGDIR in continuation).
168 unzip dl/sdcc-snapshot-${arch}-${date}-${revision}.zip
170 if ! pushd sdcc
171 then
172 fatal_error "Cannot cd to sdcc!"
173 else
174 # - remove the PKGDIR/doc/ directory
175 rm -rf doc/
177 # - unpack sdcc-doc-yyyymmdd-rrrr.zip to the PKGDIR/doc directory
178 unzip ../dl/sdcc-doc-${date}-${revision}.zip
180 # - copy files sdcc/support/scripts/sdcc.ico and sdcc/support/scripts/sdcc.nsi
181 # (this file) from the sdcc Subversion snapshot to the PKGDIR directory
182 cp ${snapshot}/support/scripts/sdcc.nsi ${snapshot}/support/scripts/sdcc.ico .
184 # - copy file COPYING and COPYING3 from the sdcc Subversion snapshot to the PKGDIR directory,
185 # rename it to COPYING.txt and COPYING3.txt and convert it to DOS format:
186 cp ${snapshot}/COPYING COPYING.txt
187 todos COPYING.txt
188 cp ${snapshot}/sdas/COPYING3 COPYING3.txt
189 todos COPYING3.txt
190 cp ${snapshot}/ChangeLog doc/ChangeLog.txt
191 todos doc/ChangeLog.txt
192 cp ${snapshot}/doc/README.txt doc/README.txt
193 todos doc/README.txt
195 # - run NSIS installer from PKGDIR directory:
196 # Define -DWIN64 if creating a 64bit package.
197 makensis -DFULL_DOC -DVER_MAJOR=${ver_maj} -DVER_MINOR=${ver_min} -DVER_REVISION=${ver_rev} -DVER_BUILD=${revision} ${win} sdcc.nsi
199 # - A setup file setup.exe is created in PKGDIR directory.
200 # Rename it to sdcc-x.x.x-setup.exe and upload it
201 # to sdcc download repository at sourceforge.net
202 cp setup.exe ../ul/sdcc-${ver}-${setup}.exe
204 popd
206 mv sdcc ${arch}
211 function upload()
213 local ver=$1 user=$2
215 raw_ver=$(expr $ver : '\([0-9]*\.[0-9]*\.[0-9]*\)')
217 echo uploading ul/sdcc-src-${ver}.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc/${raw_ver}/
218 rsync -v --progress -e ssh ul/sdcc-src-${ver}.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc/${raw_ver}/
220 echo uploading ul/sdcc-doc-${ver}.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-doc/${raw_ver}/
221 rsync -v --progress -e ssh ul/sdcc-doc-${ver}.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-doc/${raw_ver}/
223 echo uploading ul/sdcc-doc-${ver}.zip ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-doc/${raw_ver}/
224 rsync -v --progress -e ssh ul/sdcc-doc-${ver}.zip ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-doc/${raw_ver}/
226 echo uploading ul/sdcc-${ver}-setup.exe ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-win32/${raw_ver}/
227 rsync -v --progress -e ssh ul/sdcc-${ver}-setup.exe ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-win32/${raw_ver}/
229 echo uploading ul/sdcc-${ver}-x64-setup.exe ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-win64/${raw_ver}/
230 rsync -v --progress -e ssh ul/sdcc-${ver}-x64-setup.exe ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-win64/${raw_ver}/
232 # echo uploading ul/sdcc-${ver}-i386-unknown-linux2.5.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-linux-x86/${raw_ver}/
233 # rsync -v --progress -e ssh ul/sdcc-${ver}-i386-unknown-linux2.5.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-linux-x86/${raw_ver}/
235 echo uploading ul/sdcc-${ver}-amd64-unknown-linux2.5.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-linux-amd64/${raw_ver}/
236 rsync -v --progress -e ssh ul/sdcc-${ver}-amd64-unknown-linux2.5.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-linux-amd64/${raw_ver}/
238 echo uploading ul/sdcc-${ver}-x86_64-apple-macosx.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-macosx-amd64/${raw_ver}/
239 rsync -v --progress -e ssh ul/sdcc-${ver}-x86_64-apple-macosx.tar.bz2 ${user}@web.sourceforge.net:/home/pfs/project/sdcc/sdcc-macosx-amd64/${raw_ver}/
243 # main procedure
245 while [ -n "$1" ]
247 case "$1"
249 -dl) dl=1; has_opts=1; shift;;
250 -pr) pr=1; has_opts=1; shift;;
251 -ul) ul=1; has_opts=1; shift;;
252 -h|--help) usage; exit 0;;
253 -*) echo "Unknown option $arg!"; usage; exit 1;;
254 *) break;;
255 esac
256 done
258 if [ $# != 3 ]
259 then
260 usage
263 test -z "$has_opts" && dl=1 && pr=1 && ul=1
265 date=$1
266 revision=$2
267 ver=$3
269 mkdir -p ul
271 # download the snapshots
272 test -n "$dl" && download ${date} ${revision}
274 if [ -n "$pr" ]
275 then
276 # repack the sources
277 repack_src ${date} ${revision} ${ver}
279 # repack the documentation
280 cp dl/sdcc-doc-${date}-${revision}.tar.bz2 ul/sdcc-doc-${ver}.tar.bz2
281 cp dl/sdcc-doc-${date}-${revision}.zip ul/sdcc-doc-${ver}.zip
283 # repack the *nix-like binaries
284 for arch in amd64-unknown-linux2.5 x86_64-apple-macosx
286 unpack dl/sdcc-snapshot-${arch}-${date}-${revision}.tar.bz2 dl/sdcc-doc-${date}-${revision}.tar.bz2
287 pack ${arch} ${ver}
288 done
290 # repack the windows binaries
291 repack_win ${date} ${revision} ${ver} i586-mingw32msvc
292 repack_win ${date} ${revision} ${ver} x86_64-w64-mingw32
295 # upload the release packages
296 test -n "$ul" && upload ${ver} sdcc-builder
298 exit 0