don't update min/max bounding box when drawing with CLEAR polarity
[geda-gerbv.git] / win32 / build_gerbv
blob44c03587bf67cb3051c4a1dce7075848d6e9340f
1 #!/bin/sh
5 # error out on failed commands whose return code wasn't explicitly
6 # checked
7 set -e
9 usage() {
10 cat << EOF
12 $0 [options]
14 Builds a non-cygwin version of gerbv or pcb and create a standalone
15 windows installer.
17 Supported options:
19 --build-only - Only run the 'make' part of the process. This is
20 shorthand for all of the --skip-* options except
21 for --skip-build.
23 --debug - Omits the compiler flag which prevents
24 a command window from being opened. This
25 is useful when trying to use debug printf's.
26 If listed twice then --enable-debug is passed
27 down to the configure script which enables
28 a good bit of debug output.
30 -h|--help - Show this message and exit.
32 --force-autogen - Force running ./autogen.sh. Normally this is
33 only done if the configure script is not present.
35 --nsis-only - Only run NSIS to create the installer. This is
36 shorthand for all of the following --skip-* options.
38 --skip-build - Skip the "make" step of the process.
40 --skip-clean - Skip the "make clean" step of the process.
42 --skip-config - Skip the "./configure" step of the process.
44 --skip-install - Skip the "make install" step of the process.
46 --skip-nsis - Skip the NSIS step of the process.
48 For the $0 script to work, you must have the gtk_win32 files
49 as well as gdlib installed on your system in very specific
50 locations. Edit $0 to change these. While you are at it, feel
51 free to provide a patch to improve the documentation about
52 those libraries.
54 On older installs of cygwin, the available gcc will accept -mno-cygwin
55 to build an executible that does not link to the cygwin dll. On newer
56 gcc's this option has been removed and you must use either a
57 cross compiler that targets mingw or use the native MinGW compiler.
58 If you use the native MinGW compiler approach, then
59 the MinGW compilers to be installed in
60 c:\MinGW and also in your cygwin environment there needs to be
61 a symbolic link:
63 /mingw -> /cygdrive/c/MinGW
65 EOF
68 debug=no
69 do_autogen=no
70 do_config=yes
71 do_build=yes
72 do_clean=yes
73 do_install=yes
74 do_nsis=yes
75 config_args=""
76 while test $# -ne 0 ; do
77 case $1 in
78 --build-only)
79 do_clean=no
80 do_config=no
81 do_install=no
82 do_nsis=no
83 shift
86 --debug)
87 if test "X${debug}" = "Xyes" ; then
88 config_args="${config_args} --enable-debug"
90 debug=yes
91 shift
94 -h|--help)
95 usage
96 exit 0
99 --force-autogen)
100 do_autogen=yes
101 shift
104 --nsis-only)
105 do_build=no
106 do_clean=no
107 do_config=no
108 do_install=no
109 shift
112 --skip-build)
113 do_build=no
114 shift
117 --skip-clean)
118 do_clean=no
119 shift
122 --skip-config)
123 do_config=no
124 shift
127 --skip-install)
128 do_install=no
129 shift
132 --skip-nsis)
133 do_nsis=no
134 shift
138 echo "ERROR: Unknown option $1"
139 usage
140 exit 1
144 break
146 esac
147 done
149 do_fake_crossbuild=no
150 if test -f /mingw/bin/mingw32-gcc.exe ; then
151 do_fake_crossbuild=yes
154 echo "do_fake_crossbuild = ${do_fake_crossbuild}"
156 enable_doc=
157 prog_name=unknown
158 if test ! -d win32 ; then
159 echo "$0: ERROR. This script must be run from the top level of the source tree"
160 exit 1
163 if test -f src/gerbv.c ; then
164 prog_name=gerbv
167 if test -f src/pcb-menu.res ; then
168 prog_name=pcb
169 config_args="${config_args} --disable-dbus --disable-m4lib-png "
170 if test -f .gitignore -o -f CVS/Root ; then
171 echo "Building from git or CVS so the documentation"
172 echo "build will be disabled (since we are cross building"
173 config_args="${config_args} --disable-doc"
174 enable_doc=";"
178 if test -f libwcalc/microstrip.c ; then
179 prog_name=wcalc
180 config_args="${config_args} --disable-htdocs --disable-cgi --disable-stdio"
183 if test ${prog_name} = unknown ; then
184 cat << EOF
185 $0: ERROR. Unable to figure out what you are building.
186 This may happen if you are trying to execute $0 from a directory
187 other than the top of the source tree.
189 exit 1
192 echo "Building program: ${prog_name}"
194 # Run this under cygwin to build gerbv or pcb and create a windows installer for
195 # it. Thanks to Bob Paddock for pointing me to NSIS and answering some
196 # beginner windows questions.
198 # where gtk_win32 is installed
199 gtk_win32=c:\\cygwin\\home\\${USER}\\gtk_win32
200 gd_win32=c:\\cygwin\\home\\${USER}\\gd_win32
201 gd_win32_f=c:/cygwin/home/${USER}/gd_win32
203 # where only the runtime components are installed
204 gtk_win32_runtime=c:\\\\cygwin\\\\home\\\\${USER}\\\\gtk_win32_runtime
205 gd_win32_runtime=c:\\\\cygwin\\\\home\\\\${USER}\\\\gd_win32_runtime
207 # program version
209 prog_version=`awk '/AC_INIT/ {gsub(/.*,[ \t]*\[/, ""); gsub(/\]\).*/, ""); print}' configure.ac`
210 echo "prog_version=${prog_version}"
212 # location of the NSIS makensis executible (see http://nsis.sourceforge.net)
213 makensis="/cygdrive/c/Program Files/NSIS/makensis.exe"
216 # ########################################################################
218 # The rest should be ok without editing
220 # ########################################################################
223 ######################################################################
225 # AUTOGEN
227 ######################################################################
229 if test ! -f configure -o $do_autogen = yes ; then
230 echo "Bootstrapping autotools"
231 ACLOCAL_FLAGS="-I ${gtk_win32}\\share\\aclocal" ./autogen.sh
234 # source directory
235 srcdir=`pwd.exe`/win32
236 top_srcdir=${srcdir}/..
238 src_dir=c:\\\\cygwin`echo ${srcdir} | sed 's;/;\\\\\\\\;g'`
239 top_src_dir=c:\\\\cygwin`echo ${top_srcdir} | sed 's;/;\\\\\\\\;g'`
242 # where to install the program
243 prog_inst=`pwd`/${prog_name}_inst
245 # DOS version
246 prog_inst_dir=c:\\\\cygwin`echo ${prog_inst} | sed 's;/;\\\\\\\\;g'`
248 PKG_CONFIG_PATH=${gtk_win32}\\lib\\pkgconfig
249 export PKG_CONFIG_PATH
251 PATH=${gtk_win32}\\bin:${gd_win32}:${PATH}
252 export PATH
254 echo "Showing packages known to pkg-config:"
255 pkg-config --list-all
258 # do not try to use libpng-config, it seems broken on win32
259 if test $prog_name = pcb ; then
260 LIBPNG_CFLAGS="-I${gtk_win32}\\include"
261 LIBPNG_CPPFLAGS="-I${gtk_win32}\\include"
262 LIBPNG_LDFLAGS="-L${gtk_win32}\\lib"
263 LIBPNG_LIBS="-lpng14"
264 LIBGD_CFLAGS="-I${gd_win32}\\include -I${gd_win32_f}/include"
265 LIBGD_CPPFLAGS="-I${gd_win32}\\include"
266 LIBGD_LDFLAGS="-L${gd_win32}\\lib -L${gd_win32_f}/lib"
267 LIBGD_LIBS="-lbgd"
268 # this ugly hack is here because the AC_CHECK_FUNC autoconf
269 # test doesn't include gd.h. Inside of gd.h, gdImageGif and
270 # friends are declared with
271 # __declspec(dllimport) void _stdcall
272 # which causes a change in how the function is named in the DLL
273 # which in turn causes the autoconf test to fail. ugh! FIXME!
274 export ac_cv_func_gdImageGif=yes
275 export ac_cv_func_gdImageJpeg=yes
276 export ac_cv_func_gdImagePng=yes
277 else
278 LIBPNG_CFLAGS=""
279 LIBPNG_LDFLAGS=""
280 LIBPNG_LIBS=""
282 LIBPNG_CONFIG=/usr/bin/true
283 export LIBPNG_CONFIG
285 # add the gcc options to produce a native windows binary that
286 # does not need cygwin to run
287 if test "x${debug}" = "xno" ; then
288 EXTRA_FLAGS="-mwindows"
291 CYGWIN_CFLAGS="-mms-bitfields -mno-cygwin ${EXTRA_FLAGS}"
292 export CYGWIN_CFLAGS
294 CYGWIN_CPPFLAGS="-mms-bitfields -mno-cygwin ${EXTRA_FLAGS}"
295 export CYGWIN_CPPFLAGS
298 # older releases of cygwin had a gcc that accepted -mno-cygwin.
299 # in more recent releases this flag (which builds and links without
300 # the cygwin dll) has been removed. We either need a normal
301 # cross compiler or we can fake it by using the native mingw
302 # compiler.
303 # see http://www.gnu.org/software/libtool/manual/html_node/Cygwin-to-MinGW-Cross.html
304 # in particular, the lt_cv_to_tool_file_cmd bit is needed because
305 # libtool will call the mingw ranlib which will not understand
306 # any cygwin absolute paths.
307 if test ${do_fake_crossbuild} = yes ; then
308 config_args="${config_args} --build=i686-pc-cygwin --host=mingw32"
309 NM=/cygdrive/c/MinGW/bin/nm.exe
310 export NM
312 # the ranlib bit here is because putting the mingw tools first
313 # in PATH causes the mingw ranlib to be called. The problem
314 # with that is tht libtool is passing an absolute cygwin
315 # path at install time to ranlib which can't deal. The
316 # func_convert... stuff is supposed to help but it didn't.
317 # The libtool folks have a patch for this so at some point
318 # this can go away.
319 RANLIB=/usr/bin/ranlib
320 export RANLIB
321 PATH=/cygdrive/c/MinGW/bin:${PATH}
322 export lt_cv_to_tool_file_cmd=func_convert_file_cygwin_to_w32
325 ######################################################################
327 # CONFIGURE
329 ######################################################################
331 # setting WIN32=yes will make sure that the desktop icon
332 # gets compiled in
333 if test "$do_config" = "yes" ; then
334 rm -fr src/.deps
335 echo "Configuring for cygwin"
336 ( ( ( env WIN32=yes \
337 ./configure \
338 --prefix=${prog_inst} \
339 --disable-dependency-tracking \
340 --disable-maintainer-mode \
341 --disable-nls \
342 --disable-update-desktop-database \
343 --disable-update-mime-database \
344 ${config_args} \
345 CFLAGS="${LIBPNG_CFLAGS} ${LIBGD_CFLAGS}" \
346 CPPFLAGS="${LIBPNG_CPPFLAGS} ${LIBGD_CPPFLAGS}" \
347 LDFLAGS="${LIBPNG_LDFLAGS} ${LIBGD_LDFLAGS}" \
348 LIBS="${LIBPNG_LIBS} ${LIBGD_LIBS}" \
349 WIN32=yes \
350 2>&1 ; echo $? >&4 ) | tee c.log 1>&3) 4>&1 | (read a ; exit $a)) 3>&1
352 if test $? -ne 0 ; then
353 echo "**** ERROR **** Configure failed. See log in c.log"
354 exit 1
357 # If the win32 pkg-config is used, then you end up with spurious CR's
358 # in the generated Makefile's and we need to get rid of them.
360 remove_rc() {
361 f="$1"
362 mv $f $f.bak
363 cat $f.bak | tr '\r' ' ' > $f
364 rm $f.bak
366 echo "Removing spurious carriage returns in the Makefiles..."
367 for f in `find . -name Makefile -print` ; do
368 remove_rc "$f"
369 done
371 if test -f libtool ; then
372 echo "Removing spurious carriage returns in libtool..."
373 remove_rc libtool
376 fi # do_config
378 ######################################################################
380 # CLEAN
382 ######################################################################
384 if test "$do_clean" = "yes" ; then
385 echo "Cleaning"
386 ( ( ( make clean 2>&1 ; echo $? >&4) | tee clean.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
387 if test $? -ne 0 ; then
388 echo "**** ERROR **** Clean failed. See log in clean.log"
389 exit 1
393 ######################################################################
395 # BUILD
397 ######################################################################
399 if test "$do_build" = "yes" ; then
400 echo "Building for cygwin"
401 ( ( ( make 2>&1 ; echo $? >&4) | tee m.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
402 if test $? -ne 0 ; then
403 echo "**** ERROR **** Build failed. See log in m.log"
404 exit 1
408 ######################################################################
410 # INSTALL
412 ######################################################################
414 if test "$do_install" = "yes" ; then
415 echo "Installing for cygwin"
416 # first clean out the installation directory to make sure
417 # we don't have old junk lying around.
418 if test -d ${prog_inst} ; then
419 rm -fr ${prog_inst}
421 ( ( ( make install 2>&1 ; echo $? >&4) | tee -a m.log 1>&3) 4>&1 | (read a ; exit $a) ) 3>&1
422 if test $? -ne 0 ; then
423 echo "**** ERROR **** Build failed. See log in m.log"
424 exit 1
428 ######################################################################
430 # NSIS INSTALLER CREATION
432 ######################################################################
434 if test "$do_nsis" = "yes" ; then
435 echo "Creating NSIS script"
436 echo "srcdir = ${srcdir}"
437 echo "src_dir = ${src_dir}"
438 echo "top_srcdir = ${top_srcdir}"
439 echo "top_src_dir = ${top_src_dir}"
441 sed \
442 -e "s|@enable_doc@|${enable_doc}|g" \
443 -e "s;@prog_version@;${prog_version};g" \
444 -e "s;@prog_prefix@;${prog_inst_dir};g" \
445 -e "s;@prog_srcdir@;${top_src_dir};g" \
446 -e "s;@gd_win32_runtime@;${gd_win32_runtime};g" \
447 -e "s;@gtk_win32_runtime@;${gtk_win32_runtime};g" \
448 ${srcdir}/${prog_name}.nsi.in > ${srcdir}/${prog_name}.nsi
450 echo "Creating windows installer"
451 "${makensis}" ${src_dir}/${prog_name}.nsi
454 echo "Windows installer left in ${srcdir}:"
455 ls -l ${srcdir}/*.exe
458 bat=run_install.bat
460 cat << EOF
462 Creating DOS batch file wrapper for the installer.
463 If you have just built this under cygwin on Vista,
464 you will need to either run the installer from
465 the Vista start menu, Windows explorer or directly from
466 the cygwin shell with
468 ./${bat}
472 cat > ${bat} << EOF
474 .\win32\\${prog_name}inst-${prog_version}.exe
477 chmod 755 ${bat}
478 else
479 echo "Skipping NSIS step per user request"