Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / dist / winmsi / s_winmsi.fcn
1 #
2 # Functions used to build the Windows Installer Package
3 #
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)
8 #
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
12
13 group_runtime="group.runtime"
14 group_devo="group.devo"
15 group_ex="group.examples"
16 group_java="group.java"
17 group_doc="group.doc"
18 group_csharp="group.csharp"
19 group_cxx="group.cxx"
20 group_sql="group.sql"
21
22 Progress()
23 {
24     if [ "$1" = -minor ]; then
25        shift
26     else
27        echo "" >> $ERRORLOG
28        echo "============================" >> $ERRORLOG
29     fi
30     echo "$@" >> $ERRORLOG
31     echo "$@" >&15
32 }
33
34 SetupErrorLog() {
35
36     # Before we start to use ERRORLOG, we get a full pathname,
37     # since the caller may change directories at times.
38     case "$ERRORLOG" in
39     /* ) ;;
40     *)   ERRORLOG=`pwd`"/$ERRORLOG" ;;
41     esac
42
43     rm -f $ERRORLOG
44
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.
49     # 
50     exec 15>&2
51     exec 2>>$ERRORLOG
52 }
53
54 SetProductDir()
55 {
56     if [ -d $PRODUCT_BLDDIR/$dbver ]; then
57         PRODUCT_SUB_BLDDIR=${PRODUCT_BLDDIR}/$dbver
58         return
59     fi      
60     if [ -d $PRODUCT_BLDDIR/../$dbver ]; then
61         PRODUCT_SUB_BLDDIR=${PRODUCT_BLDDIR}/../$dbver
62         return
63     fi      
64     Error "Cannot find product dir ($dbver) in ${PRODUCT_BLDDIR}"
65     exit 1
66 }
67
68 # Fail fast for certain missing files
69 RequireFileInPath()
70 {
71     local type="$1"
72     local origpath="$2"
73     local file="$3"
74     local upath="$origpath"
75     if [ "$1" != PATH ]; then
76        upath=`cygpath -up "$origpath"`
77     fi
78
79     SAVEIFS="$IFS"
80     IFS=":"
81     found=no
82     for dir in $upath; do
83         if [ -f "$dir/$file" ]; then
84             IFS="$SAVEIFS"
85             return
86         fi
87     done
88     IFS="$SAVEIFS"
89     Error "File $file not found in $type path: $origpath"
90     exit 1
91 }
92
93 Error()
94 {
95     echo "" >> $ERRORLOG
96     echo "****************** FAIL ******************" >> $ERRORLOG
97     echo "ERROR: $@" >> $ERRORLOG
98     echo "ERROR: $@" >&15
99     echo "See $ERRORLOG for details" >&15
100     return 1
101 }
102
103 RequireCygwin() {
104     Progress -minor "checking for Cygwin..."
105     RequireFileInPath PATH "$PATH" bash
106 }
107
108 RequireXQilla() {
109     Progress -minor "checking for XQilla..."
110     RequireFileInPath PATH "$PATH" xqilla
111 }
112
113 # RequireJava()
114 # A java SDK (with include files) must be installed
115 #
116 RequireJava() {
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
122 }
123
124 # RequireTcl()
125 # A Tcl SDK (with compatible .lib files) must be installed
126 #
127 RequireTcl() {
128     Progress -minor "checking for Tcl..."
129     RequireFileInPath INCLUDE "$INCLUDE" tcl.h
130     RequireFileInPath LIB "$LIB" tcl85g.lib
131     RequireFileInPath LIB "$LIB" tcl85.lib
132 }
133
134 # RequireWix()
135 # WiX must be installed
136 #
137 RequireWix() {
138     Progress -minor "checking for WiX..."
139     RequireFileInPath PATH "$PATH" candle.exe
140     RequireFileInPath PATH "$PATH" light.exe
141 }
142
143 # RequirePerl()
144 # Perl must be installed
145 #
146 RequirePerl() {
147     Progress -minor "checking for Perl..."
148     RequireFileInPath PATH "$PATH" perl.exe
149 }
150
151 # RequireTcl()
152 # Tcl must be installed
153 #
154 RequireTcl() {
155     Progress -minor "checking for Tcl..."
156     RequireFileInPath INCLUDE "$INCLUDE" tcl.h
157     RequireFileInPath LIB "$LIB" tcl85.lib
158 }
159
160 # RequirePython()
161 # Python (and include files) must be installed
162 #
163 RequirePython() {
164     Progress -minor "checking for Python..."
165     RequireFileInPath PATH "$PATH" python.exe
166 }
167
168 # RequirePHP()
169 # PHP (and include files) must be installed
170 #
171 RequirePHP() {
172     Progress -minor "checking for PHP..."
173     RequireFileInPath INCLUDE "$INCLUDE" php.h
174     RequireFileInPath PATH "$PATH" php.exe
175 }
176
177 #
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
182 # the new version.
183 #
184 FindMergeModules() {
185     Progress "Adding redistributable Visual Studio files..."
186     tscript=cmd$$a.cmd
187     tsed=sed$$a.sed
188     rm -f $tscript $tscript.out $tsed
189
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
193
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
199     cmd /c $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
203 }
204
205 BuildProduct() {
206     local here=`pwd`
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
215 }
216
217 CreateLicenseRtf() {
218     local licensein="$1"
219     local licensertf="$2"
220
221     if [ ! -f "$licensein" ]; then
222         Error "License file $licensein: does not exist"
223         exit 1
224     fi
225     Progress "creating ${licensertf}..."
226     
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!)
230     #
231     if ! grep '^=-=-=-=' $licensein > /dev/null; then
232         Error "LICENSE has changed format, this script must be adapted"
233         exit 1
234     fi
235     
236     sed -e '1,/^=-=-=-=-=/d' < $licensein | MakeRtf > $licensertf
237 }
238
239 # MakeRtf()
240 # Standard input is plain text, standard output is RTF.
241 #
242 MakeRtf() {
243     temp1=/tmp/sbm$$a
244     cat > $temp1
245
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 
250 #
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 
255
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 
261 EndOfRTFHeader
262
263 # Embedded '<' and '>' can cause problems for Wix
264     sed -e 's:$:\\par:' -e 's:<: \\lquote :' -e 's:>: \\rquote :' < $temp1
265     echo -n '}'
266     rm -f $temp1
267 }
268
269 CreateRuntimeComponents() {
270     local here=`pwd`
271     Progress "Building/updating .wxs files for runtime..."
272     cd "${PRODUCT_BLDDIR}"
273     bash ${DIST_DIR}/winmsi/generateWix.sh  dist/winmsi xqilla.exe
274     cd $here
275 }
276
277 MakeLink() {
278     local outfile=$1
279     local url=$2
280     echo '[Default]' > $outfile
281     echo "BASEURL=$url" >> $outfile
282     echo '[InternetShortcut]' >> $outfile
283     echo "URL=$url" >> $outfile
284     echo "Modified=0000000007DCC3101DE" >> $outfile
285     unix2dos $outfile
286 }
287
288 MakeCommand() {
289     local outfile=$1
290     local command=$2
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
316     unix2dos $outfile
317 }
318
319 CreateLinks() {
320     # Create link files that are referenced from
321     # links_frag.wxs and installed
322     echo "Making links"
323     mkdir links
324     cd links
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 .
330     cd ..
331 }
332
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() {
336     local here=`pwd`
337     cd dist/winmsi
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
344         cp -f $f.tmp $f
345         rm -rf $f.tmp
346     done
347     cd $here
348 }
349
350 # VS2010 examples need to remove the dependencies on db*.vcxproj
351 # projects that do not get bundled with binaries
352 fixup2010examples () {
353     local here=`pwd`
354     cd dist/winmsi
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
359         cp -f $i.tmp $i
360         rm -rf $i.tmp
361     done
362     cd $here
363 }
364
365 #
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.
373 #
374 StageSourceComponents() {
375     local here=`pwd`
376     Progress "Staging source files -- examples and projects..."
377
378     cd "${PRODUCT_BLDDIR}"
379     # start with a clean slate
380     rm -rf stage
381     mkdir stage
382     mkdir stage/build_windows
383     mkdir stage/build_windows/VS8
384     mkdir stage/build_windows/VS10
385     mkdir stage/sql
386     mkdir stage/src
387     mkdir stage/src/clib
388     mkdir stage/include
389
390     #
391     # Examples
392     #
393     cp -r examples stage
394
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
407
408     # note files in example group file, starting at stage
409     cd stage
410     find examples src build_windows -type f > $group_ex
411     cd ..
412
413     #
414     # Documentation
415     #
416     cp -r docs stage
417     find docs -type f > stage/$group_doc
418
419
420     #
421     # Header files for examples and devo
422     #
423
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
429
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
435  
436     # STL has a lot of header files that are external
437     cp lang/cxx/stl/*.h stage/include
438     cd stage
439     find include -name "dbstl*.h" >> $group_cxx
440     cd ..
441
442     cd $here
443 }
444
445 StageRuntimeComponents() {
446     local here=`pwd`
447     Progress "Staging runtime files/executables..."
448     cd "${PRODUCT_BLDDIR}"
449     # stage directory must exist, created above
450     mkdir stage/bin
451     mkdir stage/lib
452     mkdir stage/jar
453
454     # start clean
455     rm -f stage/$group_runtime stage/$group_java stage/$group_csharp \
456         stage/$group_sql
457
458     for file in `find . -name "*.exe"`; do
459         cp $file stage/bin
460     done
461     for file in `find . -name "*.dll"`; do
462         cp $file stage/bin
463     done
464     for file in `find . -name "*.lib"`; do
465         cp $file stage/lib
466     done
467     # remove static libraries
468     rm stage/lib/libdb*s.lib
469     for file in `find . -name "*.jar"`; do
470         cp $file stage/jar
471     done
472
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
479
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
486
487     # remove example artifacts -- they are not bundled
488     rm -f stage/bin/ex*.exe
489     rm -f stage/jar/dbexamples.jar
490
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
494
495     # modify C# example project files
496     createCSharpExamples
497
498     # modify VS2010 example project files
499     fixup2010examples
500
501     cp README stage
502     cp LICENSE stage
503
504     #
505     # Update group files
506     #
507
508     cd stage
509     # runtime
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
515
516     # core devo
517     find lib -name "libdb??.lib" >> $group_devo
518     find bin -name "libdb??.pdb" >> $group_devo
519
520     # java
521     echo "jar/db.jar" >> $group_java
522     find bin -name "libdb_java*" >> $group_java
523
524     # C++/STL (libdb?? includes C++ runtime)
525     find bin -name "libdb_stl*" >> $group_cxx
526     find lib -name "libdb_stl*" >> $group_cxx
527     
528     # C#
529     find bin -name "libdb_csharp*" >> $group_csharp
530     find bin -name "libdb_dotnet*" >> $group_csharp
531
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
539     cd ..
540
541     cd $here
542 }
543
544 CreateMsi() {
545     local here=`pwd`
546     Progress "Building .msi file..."
547     cd "${PRODUCT_BLDDIR}"/stage
548     chmod +w README
549     unix2dos README
550     chmod 444 README
551     rm -rf wix
552     mkdir wix 2>/dev/null
553     cd wix
554
555     FindMergeModules
556     echo "MERGE: $MERGE_MODULES_LOCATION"
557
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
562     done
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
565     done
566
567     # WiX will pick up License.rtf in the current (work) directory
568     cp ${DIST_DIR}/License.rtf .
569
570     # Create link files.  These are referenced from links_frag.wxs,
571     # and "light" linking below will fail without them
572     CreateLinks
573
574     # Run WiX tools (these commands work with WiX 3.x)
575     candle *.wxs
576     light -out $dbver.msi -ext WixUIExtension *.wixobj
577     cd $here
578 }