gerbv_open_image() can now take a zip archive as an argument.
[geda-gerbv/spe.git] / win32 / build_gerbv
blobc9443b584f14b6d7759af55e5a8143a2d43e165d
1 #!/bin/sh
3 # $Id$
6 # error out on failed commands whose return code wasn't explicitly
7 # checked
8 set -e
10 usage() {
11 cat << EOF
13 $0 [options]
15 Builds a non-cygwin version of gerbv and create a standalone
16 windows installer.
18 Supported options:
20 --build-only - Only run the 'make' part of the process. This is
21 shorthand for all of the --skip-* options except
22 for --skip-build.
24 --debug - Omits the compiler flag which prevents
25 a command window from being opened. This
26 is useful when trying to use debug printf's.
27 If listed twice then --enable-debug is passed
28 down to the configure script which enables
29 a good bit of debug output.
31 --help - Show this message and exit.
33 --force-autogen - Force running ./autogen.sh. Normally this is
34 only done if the configure script is not present.
36 --nsis-only - Only run NSIS to create the installer. This is
37 shorthand for all of the following --skip-* options.
39 --skip-build - Skip the "make" step of the process.
41 --skip-clean - Skip the "make clean" step of the process.
43 --skip-config - Skip the "./configure" step of the process.
45 --skip-install - Skip the "make install" step of the process.
47 --skip-nsis - Skip the NSIS step of the process.
49 For the $0 script to work, you must have the gtk_win32 files
50 as well as gdlib installed on your system in very specific
51 locations. Edit $0 to change these. While you are at it, feel
52 free to provide a patch to improve the documentation about
53 those libraries.
55 EOF
58 debug=no
59 do_autogen=no
60 do_config=yes
61 do_build=yes
62 do_clean=yes
63 do_install=yes
64 do_nsis=yes
65 config_args=""
66 while test $# -ne 0 ; do
67 case $1 in
68 --build-only)
69 do_clean=no
70 do_config=no
71 do_install=no
72 do_nsis=no
73 shift
76 --debug)
77 if test "X${debug}" = "Xyes" ; then
78 config_args="${config_args} --enable-debug"
80 debug=yes
81 shift
84 --help)
85 usage
86 exit 0
89 --force-autogen)
90 do_autogen=yes
91 shift
94 --nsis-only)
95 do_build=no
96 do_clean=no
97 do_config=no
98 do_install=no
99 shift
102 --skip-build)
103 do_build=no
104 shift
107 --skip-clean)
108 do_clean=no
109 shift
112 --skip-config)
113 do_config=no
114 shift
117 --skip-install)
118 do_install=no
119 shift
122 --skip-nsis)
123 do_nsis=no
124 shift
128 echo "ERROR: Unknown option $1"
129 usage
130 exit 1
134 break
136 esac
137 done
139 if test ! -f win32/build_gerbv ; then
140 echo "$0: ERROR. This script must be run from the top level of the gerbv source tree."
141 exit 1
144 # Run this under cygwin to build gerbv and create a windows installer for
145 # it. Thanks to Bob Paddock for pointing me to NSIS and answering some
146 # beginner windows questions.
148 # where gtk_win32 is installed
149 gtk_win32=c:\\cygwin\\home\\${USER}\\gtk_win32
151 # where only the runtime components are installed
152 gtk_win32_runtime=c:\\\\cygwin\\\\home\\\\${USER}\\\\gtk_win32_runtime
154 # gerbv version
156 gerbv_version=`awk '/AC_INIT/ {gsub(/.*,[ \t]*\[/, ""); gsub(/\]\).*/, ""); print}' configure.ac`
157 echo "gerbv_version=${gerbv_version}"
159 # location of the NSIS makensis executible (see http://nsis.sourceforge.net)
160 makensis="/cygdrive/c/Program Files/NSIS/makensis.exe"
163 # ########################################################################
165 # The rest should be ok without editing
167 # ########################################################################
170 if test ! -f configure -o $do_autogen = yes ; then
171 echo "Bootstrapping autotools"
172 ACLOCAL_FLAGS="-I ${gtk_win32}\\share\\aclocal" ./autogen.sh
175 # source directory
176 srcdir=`pwd.exe`/win32
177 top_srcdir=${srcdir}/..
179 src_dir=c:\\\\cygwin`echo ${srcdir} | sed 's;/;\\\\\\\\;g'`
180 top_src_dir=c:\\\\cygwin`echo ${top_srcdir} | sed 's;/;\\\\\\\\;g'`
183 # where to install gerbv
184 gerbv_inst=`pwd`/gerbv_inst
186 # DOS version
187 gerbv_inst_dir=c:\\\\cygwin`echo ${gerbv_inst} | sed 's;/;\\\\\\\\;g'`
189 PKG_CONFIG_PATH=${gtk_win32}\\lib\\pkgconfig
190 export PKG_CONFIG_PATH
192 PATH=${gtk_win32}\\bin:${gd_win32}:${PATH}
193 export PATH
195 echo "Showing packages known to pkg-config:"
196 pkg-config --list-all
199 # do not try to use libpng-config, it seems broken on win32
200 LIBPNG_CONFIG=/usr/bin/true
201 export LIBPNG_CONFIG
202 LIBPNG_CFLAGS="-I${HOME}/gtk_win32/include"
203 LIBPNG_LDFLAGS="-L${HOME}/gtk_win32/lib"
204 LIBPNG_LIBS="-lpng12"
206 # add the gcc options to produce a native windows binary that
207 # does not need cygwin to run
208 if test "x${debug}" = "xno" ; then
209 EXTRA_FLAGS="-mwindows"
212 CYGWIN_CFLAGS="-mms-bitfields -mno-cygwin ${EXTRA_FLAGS}"
213 export CYGWIN_CFLAGS
215 CYGWIN_CPPFLAGS="-mms-bitfields -mno-cygwin ${EXTRA_FLAGS}"
216 export CYGWIN_CPPFLAGS
218 # setting WIN32=yes will make sure that the desktop icon
219 # gets compiled in
220 if test "$do_config" = "yes" ; then
221 rm -fr src/.deps
222 echo "Configuring for cygwin"
223 ( ( ( env WIN32=yes \
224 ./configure \
225 --prefix=${gerbv_inst} \
226 --disable-dependency-tracking \
227 --disable-maintainer-mode \
228 --disable-nls \
229 --disable-update-desktop-database \
230 --disable-update-mime-database \
231 ${config_args} \
232 CFLAGS="${LIBPNG_CFLAGS}" \
233 LDFLAGS="${LIBPNG_LDFLAGS}" \
234 LIBS="${LIBPNG_LIBS}" \
235 WIN32=yes \
236 2>&1 ; echo $? >&4 ) | tee c.log 1>&3) 4>&1 | (read a ; exit $a)) 3>&1
238 if test $? -ne 0 ; then
239 echo "**** ERROR **** Configure failed. See log in c.log"
240 exit 1
243 # If the win32 pkg-config is used, then you end up with spurious CR's
244 # in the generated Makefile's and we need to get rid of them.
246 remove_rc() {
247 f="$1"
248 mv $f $f.bak
249 cat $f.bak | tr '\r' ' ' > $f
250 rm $f.bak
252 echo "Removing spurious carriage returns in the Makefiles..."
253 for f in `find . -name Makefile -print` ; do
254 remove_rc "$f"
255 done
257 echo "Removing spurious carriage returns in libtool..."
258 remove_rc libtool
260 fi # do_config
262 if test "$do_clean" = "yes" ; then
263 echo "Cleaning"
264 ( ( ( make clean 2>&1 ; echo $? >&4) | tee clean.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
265 if test $? -ne 0 ; then
266 echo "**** ERROR **** Clean failed. See log in clean.log"
267 exit 1
271 if test "$do_build" = "yes" ; then
272 echo "Building for cygwin"
273 ( ( ( make 2>&1 ; echo $? >&4) | tee m.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
274 if test $? -ne 0 ; then
275 echo "**** ERROR **** Build failed. See log in m.log"
276 exit 1
280 if test "$do_install" = "yes" ; then
281 echo "Installing for cygwin"
282 # first clean out the installation directory to make sure
283 # we don't have old junk lying around.
284 if test -d ${gerbv_inst} ; then
285 rm -fr ${gerbv_inst}
287 ( ( ( make install 2>&1 ; echo $? >&4) | tee -a m.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
288 if test $? -ne 0 ; then
289 echo "**** ERROR **** Build failed. See log in m.log"
290 exit 1
294 if test "$do_nsis" = "yes" ; then
295 echo "Creating NSIS script"
296 echo "srcdir = ${srcdir}"
297 echo "src_dir = ${src_dir}"
298 echo "top_srcdir = ${top_srcdir}"
299 echo "top_src_dir = ${top_src_dir}"
301 sed \
302 -e "s;@gerbv_version@;${gerbv_version};g" \
303 -e "s;@gerbv_prefix@;${gerbv_inst_dir};g" \
304 -e "s;@gerbv_srcdir@;${top_src_dir};g" \
305 -e "s;@gtk_win32_runtime@;${gtk_win32_runtime};g" \
306 ${srcdir}/gerbv.nsi.in > ${srcdir}/gerbv.nsi
308 echo "Creating windows installer"
309 "${makensis}" ${src_dir}/gerbv.nsi
312 echo "Windows installer left in ${srcdir}:"
313 ls -l ${srcdir}/*.exe
316 bat=run_install.bat
318 cat << EOF
320 Creating DOS batch file wrapper for the installer.
321 If you have just built this under cygwin on Vista,
322 you will need to either run the installer from
323 the Vista start menu, Windows explorer or directly from
324 the cygwin shell with
326 ./${bat}
330 cat > ${bat} << EOF
332 .\win32\gerbvinst-${gerbv_version}.exe
335 chmod 755 ${bat}
336 else
337 echo "Skipping NSIS step per user request"