2 # Functions used to build the Windows Installer Package
4 # This script uses several bash extensions that are convenient
5 # since we "know" it will always run under Cygwin: shell functions,
6 # 'return', declaration of 'local' variables, $(command) syntax,
7 # ${#X} (counting chars), ${X#regexp} (searching) $((expr)) (arithmetic)
9 # PRODUCT_SUB_BLDDIR - top of the subproduct build e.g. "dbxml-2.0.1/dbxml"
10 # PRODUCT_BLDDIR - top of the build tree e.g. "dbxml-2.0.1"
11 # ERRORLOG - error output file
13 group_runtime="group.runtime"
14 group_devo="group.devo"
15 group_ex="group.examples"
16 group_java="group.java"
18 group_csharp="group.csharp"
24 if [ "$1" = -minor ]; then
28 echo "============================" >> $ERRORLOG
30 echo "$@" >> $ERRORLOG
36 # Before we start to use ERRORLOG, we get a full pathname,
37 # since the caller may change directories at times.
40 *) ERRORLOG=`pwd`"/$ERRORLOG" ;;
45 # File descriptor tricks.
46 # Duplicate current stderr to 15, as we'll occasionally
47 # need to report progress to it. Then, redirect all
48 # stderr from now on to the ERRORLOG.
56 if [ -d $PRODUCT_BLDDIR/$dbver ]; then
57 PRODUCT_SUB_BLDDIR=${PRODUCT_BLDDIR}/$dbver
60 if [ -d $PRODUCT_BLDDIR/../$dbver ]; then
61 PRODUCT_SUB_BLDDIR=${PRODUCT_BLDDIR}/../$dbver
64 Error "Cannot find product dir ($dbver) in ${PRODUCT_BLDDIR}"
68 # Fail fast for certain missing files
74 local upath="$origpath"
75 if [ "$1" != PATH ]; then
76 upath=`cygpath -up "$origpath"`
83 if [ -f "$dir/$file" ]; then
89 Error "File $file not found in $type path: $origpath"
96 echo "****************** FAIL ******************" >> $ERRORLOG
97 echo "ERROR: $@" >> $ERRORLOG
99 echo "See $ERRORLOG for details" >&15
104 Progress -minor "checking for Cygwin..."
105 RequireFileInPath PATH "$PATH" bash
109 Progress -minor "checking for XQilla..."
110 RequireFileInPath PATH "$PATH" xqilla
114 # A java SDK (with include files) must be installed
117 Progress -minor "checking for Java..."
118 RequireFileInPath INCLUDE "$INCLUDE" jni.h
119 # RequireFileInPath INCLUDE "$INCLUDE" jni_md.h
120 RequireFileInPath PATH "$PATH" jar.exe
121 RequireFileInPath PATH "$PATH" javac.exe
125 # A Tcl SDK (with compatible .lib files) must be installed
128 Progress -minor "checking for Tcl..."
129 RequireFileInPath INCLUDE "$INCLUDE" tcl.h
130 RequireFileInPath LIB "$LIB" tcl85g.lib
131 RequireFileInPath LIB "$LIB" tcl85.lib
135 # WiX must be installed
138 Progress -minor "checking for WiX..."
139 RequireFileInPath PATH "$PATH" candle.exe
140 RequireFileInPath PATH "$PATH" light.exe
144 # Perl must be installed
147 Progress -minor "checking for Perl..."
148 RequireFileInPath PATH "$PATH" perl.exe
152 # Tcl must be installed
155 Progress -minor "checking for Tcl..."
156 RequireFileInPath INCLUDE "$INCLUDE" tcl.h
157 RequireFileInPath LIB "$LIB" tcl85.lib
161 # Python (and include files) must be installed
164 Progress -minor "checking for Python..."
165 RequireFileInPath PATH "$PATH" python.exe
169 # PHP (and include files) must be installed
172 Progress -minor "checking for PHP..."
173 RequireFileInPath INCLUDE "$INCLUDE" php.h
174 RequireFileInPath PATH "$PATH" php.exe
178 # Locate the Merge Modules for Visual Studio. This MUST
179 # change if/when the default compiler is changed to a
180 # newer version. What will change is the registry key
181 # being used as well as the file name (*.msm) to match
185 Progress "Adding redistributable Visual Studio files..."
188 rm -f $tscript $tscript.out $tsed
190 # this short script removes leading/trailing spaces and turns
191 # '\' into '\\' in the path so *nix scripting and sed work
192 echo "s/\\\\/\\\\\\\\/g;s/^[ \\t]*//;s/[ \\t]*$//" > $tsed
194 # Query for location of VS Merge Module for CRT
195 # and return it to replace @MERGE_MODULES_LOCATION@ in db.wxs
196 echo "@echo off" > $tscript
197 echo "set DBROOTDIR=" >> $tscript
198 echo "for /F \"tokens=2* skip=2\" %%a in ('reg query \"HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup\\VS\" /v MSMDir') do echo %%b >> $tscript.out" >> $tscript
200 TLOC=`sed -f $tsed < $tscript.out`
201 MERGE_MODULES_LOCATION=${TLOC}Microsoft_VC80_CRT_x86.msm
202 rm -f $tscript $tscript.out $tsed
207 Progress "Building $PRODUCT_NAME in ${PRODUCT_SUB_BLDDIR}"
208 cd ${PRODUCT_SUB_BLDDIR}/dist
209 # make files writeable if necessary
210 chmod +w ${PRODUCT_SUB_BLDDIR}/build_windows/VS8/*.vcproj
211 chmod +w ${PRODUCT_SUB_BLDDIR}/build_windows/VS10/*.vcxproj
212 chmod +w ${PRODUCT_SUB_BLDDIR}/build_windows/VS10/*.props
213 chmod +w ${PRODUCT_SUB_BLDDIR}/build_windows/*.sln
214 cmd.exe /x /c call $MSI_DIR/build.bat
219 local licensertf="$2"
221 if [ ! -f "$licensein" ]; then
222 Error "License file $licensein: does not exist"
225 Progress "creating ${licensertf}..."
227 # Build a list of references to components ids (i.e. directories)
228 # that are listed in the .wxs file. This is needed to refer to
229 # all of the source (sadly it appears there is no better way!)
231 if ! grep '^=-=-=-=' $licensein > /dev/null; then
232 Error "LICENSE has changed format, this script must be adapted"
236 sed -e '1,/^=-=-=-=-=/d' < $licensein | MakeRtf > $licensertf
240 # Standard input is plain text, standard output is RTF.
246 # Courier is a good font, but the lines with all caps
247 # overflows our current dialog size:
248 # {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
249 # \viewkind4\uc1\pard\lang1033\f0\fs16
251 # Using Small fonts works:
252 # {\rtf1\ansi\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Small Fonts;}}
253 # {\colortbl ;\red0\green0\blue0;}
254 # \viewkind4\uc1\pard\cf1\lang1033\f0\fs14
256 # Arial is the best compromise:
257 sed -e 's/^ *//' << 'EndOfRTFHeader'
258 {\rtf1\ansi\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}
259 {\colortbl ;\red0\green0\blue0;}
260 \viewkind4\uc1\pard\cf1\lang1033\f0\fs16
263 # Embedded '<' and '>' can cause problems for Wix
264 sed -e 's:$:\\par:' -e 's:<: \\lquote :' -e 's:>: \\rquote :' < $temp1
269 CreateRuntimeComponents() {
271 Progress "Building/updating .wxs files for runtime..."
272 cd "${PRODUCT_BLDDIR}"
273 bash ${DIST_DIR}/winmsi/generateWix.sh dist/winmsi xqilla.exe
280 echo '[Default]' > $outfile
281 echo "BASEURL=$url" >> $outfile
282 echo '[InternetShortcut]' >> $outfile
283 echo "URL=$url" >> $outfile
284 echo "Modified=0000000007DCC3101DE" >> $outfile
291 echo "@echo off" > $outfile
292 echo "set DBROOTDIR=" >> $outfile
293 echo "for /F \"tokens=2* skip=2\" %%A in ('REG QUERY \"HKLM\\SOFTWARE\\Oracle\\$PRODUCT_NAME\\$PRODUCT_VERSION\" /v RootDirectory') do set DBROOTDIR=%%B" >> $outfile
294 echo "if \"%DBROOTDIR%\"==\"\" for /F \"tokens=2* skip=2\" %%A in ('REG QUERY \"HKLM\\SOFTWARE\\Wow6432Node\\Oracle\\$PRODUCT_NAME\\$PRODUCT_VERSION\" /v RootDirectory') do set DBROOTDIR=%%B" >> $outfile
295 echo "if ERRORLEVEL 2 goto MISSING" >> $outfile
296 echo "if not defined DBROOTDIR goto MISSING" >> $outfile
297 echo "set FN=\"%DBROOTDIR%$command\"" >> $outfile
298 echo "if not exist %FN% goto NOTFOUND" >> $outfile
299 echo "cmd /k \"%DBROOTDIR%$command\"$CR" >> $outfile
300 echo "goto END" >> $outfile
301 echo ":NOTFOUND" >> $outfile
302 echo "echo" >> $outfile
303 echo "echo Error: The program does not appear to be installed." >> $outfile
304 echo "echo" >> $outfile
305 echo "cmd /k" >> $outfile
306 echo "goto END" >> $outfile
307 echo ":MISSING" >> $outfile
308 echo "echo" >> $outfile
309 echo "echo NOTE:" >> $outfile
310 echo "echo The $PRODUCT_NAME version could not be determined." >> $outfile
311 echo "echo If you are running on Windows 2000, make sure the" >> $outfile
312 echo "echo REG.EXE program is installed from the Tools disk" >> $outfile
313 echo "echo" >> $outfile
314 echo "cmd /k" >> $outfile
315 echo ":END" >> $outfile
320 # Create link files that are referenced from
321 # links_frag.wxs and installed
325 MakeLink oracletn.bdbsc http://forums.oracle.com/forums/forum.jspa?forumID=271
326 MakeLink oracleon.bdbsc http://www.oracle.com/technetwork/database/berkeleydb/documentation/index.html
327 MakeLink oraclefa.bdbsc http://www.oracle.com/technetwork/database/berkeleydb/db-faq-095848.html
328 MakeLink oraclewb.bdbsc http://www.oracle.com
329 cp ${DIST_DIR}/winmsi/webicon.ico .
333 # run C# example projects through XQilla to replace the project reference
334 # with a reference to the runtime that will be installed.
335 createCSharpExamples() {
338 for i in `ls ../../examples/csharp`; do
339 f=../../stage/examples/csharp/$i/$i.csproj
340 mkdir -p ../../stage/examples/csharp/$i
341 xqilla.exe -u -v "inFile" $f -v "libname" libdb_dotnet$DB_VERSION_MAJOR$DB_VERSION_MINOR -v "libversion" $DB_VERSION_MAJOR.$DB_VERSION_MINOR.$DB_VERSION_PATCH.0 fixupCsharp.xq
342 # Visual studio doesn't like XML version 1.1...
343 sed -e's!version="1.1"!version="1.0"!g' $f > $f.tmp
350 # VS2010 examples need to remove the dependencies on db*.vcxproj
351 # projects that do not get bundled with binaries
352 fixup2010examples () {
355 for i in `ls ../../stage/build_windows/*.vcxproj`; do
356 xqilla.exe -u -v "inFile" $i fixup2010.xq
357 # Visual studio doesn't like XML version 1.1...
358 sed -e's!version="1.1"!version="1.0"!g' $i > $i.tmp
366 # This function copies source files to the staging
367 # area for packaging. It also creates lists of
368 # files per component. The component groups are
369 # listed at the top of this file (see group_* variables)
370 # These lists are used by genWix.py to generate the
371 # proper WiX Components. These files need to contain
372 # valid paths into the staging area.
374 StageSourceComponents() {
376 Progress "Staging source files -- examples and projects..."
378 cd "${PRODUCT_BLDDIR}"
379 # start with a clean slate
382 mkdir stage/build_windows
383 mkdir stage/build_windows/VS8
384 mkdir stage/build_windows/VS10
395 # many examples rely on getopt.c
396 cp src/clib/getopt.c stage/src/clib
397 # example solution and project files
398 cp build_windows/Berkeley_DB_examples.sln stage/build_windows
399 cp build_windows/BDB_dotNet_examples.sln stage/build_windows
400 cp build_windows/Berkeley_DB_examples_vs2010.sln stage/build_windows
401 cp build_windows/BDB_dotNet_examples_vs2010.sln stage/build_windows
402 # NOTE: this assumes ALL example projects start with "ex"
403 cp build_windows/VS8/ex*.vcproj stage/build_windows/VS8
404 # VS2010 projects too
405 cp build_windows/VS10/ex*.vcxproj stage/build_windows/VS10
406 cp build_windows/VS10/*.props stage/build_windows/VS10
408 # note files in example group file, starting at stage
410 find examples src build_windows -type f > $group_ex
417 find docs -type f > stage/$group_doc
421 # Header files for examples and devo
424 # development headers
425 cp build_windows/{db,db_cxx,dbstl_common}.h stage/include
426 echo "include/db.h" > stage/$group_devo
427 # put C++ in core devo, it's included in libdbXX
428 echo "include/db_cxx.h" >> stage/$group_devo
430 # dbinc/queue.h is required by rep_net.c for the LIST* macros, put it
431 # under include. It has no external dependencies.
432 mkdir stage/include/dbinc
433 cp src/dbinc/queue.h stage/include/dbinc
434 echo "include/dbinc/queue.h" >> stage/$group_ex
436 # STL has a lot of header files that are external
437 cp lang/cxx/stl/*.h stage/include
439 find include -name "dbstl*.h" >> $group_cxx
445 StageRuntimeComponents() {
447 Progress "Staging runtime files/executables..."
448 cd "${PRODUCT_BLDDIR}"
449 # stage directory must exist, created above
455 rm -f stage/$group_runtime stage/$group_java stage/$group_csharp \
458 for file in `find . -name "*.exe"`; do
461 for file in `find . -name "*.dll"`; do
464 for file in `find . -name "*.lib"`; do
467 # remove static libraries
468 rm stage/lib/libdb*s.lib
469 for file in `find . -name "*.jar"`; do
473 # don't need .lib files for Java and C#, nobody
474 # links with them other than DB's DLLs.
475 rm -f stage/lib/libdb_java*
476 rm -f stage/lib/libdb_csharp*
477 rm -f stage/lib/sqlite_jni.lib
478 rm -f stage/lib/sqlite3odbc.lib
480 # copy library .pdb files by hand
481 cp build_windows/Win32/Release/libdb*.pdb stage/bin
482 # SQLite header, library .pdb files
483 cp lang/sql/generated/sqlite3.h stage/include
484 cp build_windows/Win32/Release/sqlite3odbc.pdb stage/bin
485 cp build_windows/Win32/Release/sqlite_jni.pdb stage/bin
487 # remove example artifacts -- they are not bundled
488 rm -f stage/bin/ex*.exe
489 rm -f stage/jar/dbexamples.jar
491 # copy some extra C# files
492 cp build_windows/AnyCPU/Release/libdb_dotnet$DB_VERSION_MAJOR$DB_VERSION_MINOR.XML stage/bin
493 cp build_windows/AnyCPU/Release/libdb_dotnet$DB_VERSION_MAJOR$DB_VERSION_MINOR.pdb stage/bin
495 # modify C# example project files
498 # modify VS2010 example project files
510 # temp rename of dbsql to put it in SQL
511 mv bin/dbsql.exe bin/dbsql.exe.sv
512 find bin -name "*.exe" >> $group_runtime
513 find bin -name "libdb??.dll" >> $group_runtime
514 mv bin/dbsql.exe.sv bin/dbsql.exe
517 find lib -name "libdb??.lib" >> $group_devo
518 find bin -name "libdb??.pdb" >> $group_devo
521 echo "jar/db.jar" >> $group_java
522 find bin -name "libdb_java*" >> $group_java
524 # C++/STL (libdb?? includes C++ runtime)
525 find bin -name "libdb_stl*" >> $group_cxx
526 find lib -name "libdb_stl*" >> $group_cxx
529 find bin -name "libdb_csharp*" >> $group_csharp
530 find bin -name "libdb_dotnet*" >> $group_csharp
532 # SQL (includes jdbc/odbc)
533 find bin -name "libdb_sql*" >> $group_sql
534 find bin -name "sqlite*" >> $group_sql
535 find lib -name "*sql*" >> $group_sql
536 echo "jar/jdbc.jar" >> $group_sql
537 echo "bin/dbsql.exe" >> $group_sql
538 echo "include/sqlite3.h" >> $group_sql
546 Progress "Building .msi file..."
547 cd "${PRODUCT_BLDDIR}"/stage
552 mkdir wix 2>/dev/null
556 echo "MERGE: $MERGE_MODULES_LOCATION"
558 # copy/edit .wxs files to here
559 # use pattern that is *NOT* in lib_paths.sed to keep it intact
560 for i in db.wxs links_frag.wxs required_frag.wxs; do
561 sed -e"s:@PRODUCT_NAME@:$PRODUCT_NAME:g" -e"s:@PROD_WIX_VERSION@:$PRODUCT_VERSION:g" -e"s:@PROD_DB_VERSION@:$DB_VERSION:g" -e"s:@REG_KEY_VERSION@:$REG_KEY_VERSION:g" -e"s:@REG_KEY_NAME@:$REG_KEY_NAME:g" -e"s:@PROD_WIX_VERSION_MIN@:$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR.0:g " -e"s:@PRODUCT_MAJOR@:$PRODUCT_VERSION_MAJOR:g" -e"s:@PRODUCT_MINOR@:$PRODUCT_VERSION_MINOR:g" -e"s/@MERGE_MODULES_LOCATION@/$MERGE_MODULES_LOCATION/g" ${DIST_DIR}/winmsi/$i > ./$i
563 for i in db_components.wxs; do
564 sed -e"s:@PRODUCT_NAME@:$PRODUCT_NAME:g" -e"s:@PROD_WIX_VERSION@:$PRODUCT_VERSION:g" -e"s:@PROD_WIX_VERSION_SHORT@:$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR.$PRODUCT_VERSION_PATCH:g" -e"s:@PROD_WIX_VERSION_MIN@:$PRODUCT_VERSION_MAJOR.$PRODUCT_VERSION_MINOR.0:g" -e"s:@PRODUCT_MAJOR@:$PRODUCT_VERSION_MAJOR:g" -e"s:@PRODUCT_MINOR@:$PRODUCT_VERSION_MINOR:g" ../scripts/$i > ./$i
567 # WiX will pick up License.rtf in the current (work) directory
568 cp ${DIST_DIR}/License.rtf .
570 # Create link files. These are referenced from links_frag.wxs,
571 # and "light" linking below will fail without them
574 # Run WiX tools (these commands work with WiX 3.x)
576 light -out $dbver.msi -ext WixUIExtension *.wixobj