1#!/bin/bash -
2#	$Id: s_windows_dsp,v 12.23 2008/01/30 18:39:13 bostic Exp $
3#
4# Build Windows/32 .dsp files.
5
6. RELEASE
7
8SRCFILES=srcfiles.in
9
10create_dsp()
11{
12    projname="$1"       # name of the .dsp file
13    match="$2"          # the string used to egrep the $sources file
14    sources="$3"        # a modified version of $SRCFILES to facilitate matches
15    dsptemplate="$4"    # overall template file for the .dsp
16    extra_cppflags="$5" # extra flags to send to compiler
17    release_libs="$6"   # libraries to link against in Release builds
18    debug_libs="$7"     # libraries to link against in Debug builds
19    lib_suffix="$8"     # the library name is libdb@lib_suffix@@VERSION@
20    proj_type="$9"	# the project type dsp or vcp
21    proj_guid="${10}"	# The project guid for VS2005 projects
22
23    # Set the default project type to be "dsp"
24    if [ ! "$proj_type" ] ; then
25	    proj_type=dsp
26    fi
27
28			# template file for the src file fragments
29    srctemplate="$BUILDDIR/srcfile_$proj_type.src"
30    rsrctemplate="$BUILDDIR/rsrcfile_$proj_type.src"
31    dspoutput=$BUILDDIR/$projname.$proj_type
32
33    postbuild=$dspoutput.postbuild
34    if [ ! -f $postbuild ] ; then
35	    postbuild=/dev/null
36    fi
37
38    rm -f $dspoutput.insert
39    for srcpath in `egrep "$match" $sources | sed -e 's/[ 	].*//'`
40    do
41        # take the path name and break it up, converting / to \\.
42        # so many backslashes needed because of shell quoting and
43        # sed quoting -- we'll end up with two backslashes for every
44        # forward slash, but we need that when feeding that to the
45        # later sed command.
46        set - `echo $srcpath | sed -e 's;\(.*\)/;../\\1 ;' \
47            -e "s;$BUILDDIR;.;" \
48            -e 's;/;\\\\\\\\;g'`
49	srcdir="$1"
50	srcfile="$2"
51	if [ "${srcfile##*.}" = "rc" -a "$proj_type" = "vcproj" ] ; then
52		inptemplate=$rsrctemplate
53	else
54		inptemplate=$srctemplate
55	fi
56
57        sed -e "s/@srcdir@/$srcdir/g" \
58            -e "s/@srcfile@/$srcfile/g" \
59            < $inptemplate >> $dspoutput.insert
60    done
61    sed -e "/@SOURCE_FILES@/r$dspoutput.insert" \
62        -e "/@SOURCE_FILES@/d" \
63        -e "/@POST_BUILD@/r$postbuild" \
64        -e "/@POST_BUILD@/d" \
65        -e "s/@project_name@/$projname/g" \
66        -e "s/@bin_rel_dest@/Release/g" \
67        -e "s/@lib_rel_dest@/Release/g" \
68        -e "s/@bin_debug_dest@/Debug/g" \
69        -e "s/@lib_debug_dest@/Debug/g" \
70        -e "s,@extra_cppflags@,$extra_cppflags,g" \
71        -e "s,@release_libs@,$release_libs,g" \
72        -e "s,@debug_libs@,$debug_libs,g" \
73        -e "s,@lib_suffix@,$lib_suffix,g" \
74        -e "s/@DB_VERSION_MAJOR@/$DB_VERSION_MAJOR/g" \
75        -e "s/@DB_VERSION_MINOR@/$DB_VERSION_MINOR/g" \
76        -e "s/@PROJ_GUID@/$proj_guid/g" \
77      < $dsptemplate > $dspoutput.new
78
79    # We run this script on Windows (under Cygwin).  Fix up the line-endings
80    # for the temporary files.  We don't test the platform, just run unix2dos
81    # if the command exists, ignoring any not-found error message.
82    (unix2dos.exe $dspoutput.new) >/dev/null 2>&1
83
84    # Set the file mode to 644 because the VC++ IDE needs a writeable file
85    # in our development environment.
86    cmp $dspoutput.new $dspoutput > /dev/null 2>&1 ||
87	(echo "Building $dspoutput" && rm -f $dspoutput &&
88	    cp $dspoutput.new $dspoutput && chmod 664 $dspoutput)
89    rm -f $dspoutput.insert $dspoutput.new
90}
91
92TMPA=/tmp/swindsp$$a
93trap "rm -f $TMPA; exit 1" 1 2 3 15
94
95# create a copy of the srcfiles with comments and empty lines removed.
96# add a space at the end of each list of modules so that each module
97# can be unambiguously matched e.g. ' dynamic '
98sed -e "s/#.*$//" \
99    -e "/^[ 	]*$/d" \
100    -e "s/[ 	][ 	]*/ /" \
101    -e "s/[ 	]*$//" \
102    -e "/[	 ]/!d" \
103    -e "s/$/ /" < $SRCFILES > $TMPA
104
105# get a list of all modules mentioned
106#
107MODULES="`sed -e 's/^[^	 ]* //' < $TMPA | tr ' ' '\012' | sort | uniq`"
108
109for module in $MODULES
110do
111    case "$module" in
112    dynamic )
113	BUILDDIR=../build_windows
114        create_dsp db_dll " $module " $TMPA $BUILDDIR/dynamic_dsp.src \
115            '' 'ws2_32.lib' 'ws2_32.lib'
116        ;;
117    small )
118	BUILDDIR=../build_windows
119        create_dsp db_small " $module " $TMPA $BUILDDIR/static_dsp.src \
120            '/D "HAVE_SMALLBUILD"' '' '' _small
121        ;;
122    static )
123	BUILDDIR=../build_windows
124        create_dsp db_static " $module " $TMPA $BUILDDIR/static_dsp.src
125        ;;
126    ce)
127	BUILDDIR=../build_wince
128        create_dsp db_static " $module " $TMPA \
129	    ../build_wince/static_vcp.src '' '' '' '' vcp
130	# Build VS2005 projects.
131	# The GUID passed in must match that in the .sln workspace.
132	# It would be ideal to grab the GUID from there if this
133	# project is already included there.
134        create_dsp db_static " $module " $TMPA \
135	    ../build_wince/static_vcproj.src '' '' '' '' vcproj \
136	    "4AB4958F-8DD0-49B5-8C02-014B5637C59A"
137        ;;
138    ce_small)
139	BUILDDIR=../build_wince
140        create_dsp db_small " $module " $TMPA  \
141            ../build_wince/static_vcp.src '/D "HAVE_SMALLBUILD"' \
142	    '' '' _small vcp
143	# Build VS2005 projects.
144	# The GUID passed in must match that in the .sln workspace.
145	# It would be ideal to grab the GUID from there if this
146	# project is already included there.
147        create_dsp db_small " $module " $TMPA  \
148            ../build_wince/static_vcproj.src 'HAVE_SMALLBUILD' \
149	    '' '' _small vcproj "6A2849DA-8F7C-4B50-BDAE-AE7752EF8213"
150        ;;
151    java )
152        BUILDDIR=../build_windows
153        create_dsp db_java " $module " $TMPA $BUILDDIR/dynamic_dsp.src '' \
154            'libdb@DB_VERSION_MAJOR@@DB_VERSION_MINOR@.lib' \
155            'libdb@DB_VERSION_MAJOR@@DB_VERSION_MINOR@d.lib' _java
156        ;;
157    tcl )
158        BUILDDIR=../build_windows
159        create_dsp db_tcl " $module " $TMPA $BUILDDIR/dynamic_dsp.src \
160            '/D "DB_TCL_SUPPORT"' \
161            'libdb@DB_VERSION_MAJOR@@DB_VERSION_MINOR@.lib tcl84.lib' \
162            'libdb@DB_VERSION_MAJOR@@DB_VERSION_MINOR@d.lib tcl84g.lib' _tcl
163        ;;
164    testutil )
165	BUILDDIR=../build_windows
166        create_dsp db_test " $module " $TMPA $BUILDDIR/app_dsp.src \
167	    '' '/out:"dbkill.exe"' '/out:"dbkill.exe"'
168        ;;
169    app=* )
170	BUILDDIR=../build_windows
171        appname=`echo $module | sed -e 's/^app=//'`
172        case "$appname" in
173        ex_rep_base )
174            libs='ws2_32.lib'
175            ;;
176        * )
177            libs=''
178            ;;
179        esac
180	# Split into Windows CE and Win32/64 project creation.
181	case "$appname" in
182	wce_tpcb )
183		BUILDDIR=../build_wince
184		create_dsp $appname " $module " $TMPA \
185		    ../build_wince/app_vcp.src '/D "__NO_SYSTEM_INCLUDES"' \
186		    '' '' '' vcp
187		# The GUID passed in must match that in the .sln workspace.
188		# It would be ideal to grab the GUID from there if this
189		# project is already included there.
190		create_dsp $appname " $module " $TMPA \
191		    ../build_wince/app_vcproj.src '__NO_SYSTEM_INCLUDES' \
192		    '' '' '' vcproj "F2CE670A-ABAE-414A-9A17-8079AB58613F"
193		BUILDDIR=../build_windows
194	        ;;
195	* )
196        	create_dsp $appname " $module " $TMPA $BUILDDIR/app_dsp.src \
197        	    '' $libs $libs
198		;;
199	esac
200	;;
201    brew|s60|vx|vxsmall|vx6 )
202        ;;
203    * )
204        echo \
205    "s_windows_dsp: module name $module in $SRCFILES is unknown type"
206        ;;
207    esac
208done
209
210rm -f $TMPA
211