Rename the GUTILS_C_VAR macro to GLIB_VAR.
[platform/upstream/glib.git] / build-dll
1 #!/bin/bash
2
3 # Temporary hack until building dlls is easier with gcc -mno-cygwin
4 # ("mingw32").
5
6 # This is usable with cygwin b20.1 and gcc-2.95.2 as distributed by
7 # Mumit Khan. For other combinations, no idea.
8
9 GCC="gcc"
10 DLLTOOL="dlltool"
11 AS=as
12
13 library=$1; shift
14 version=$1; shift;
15 def=$1; shift
16 ldargs="$*"
17
18 defswitch=""
19 [ -n "$def" -a "$def" != '-' ] && defswitch="--def $def"
20
21 libname=$library
22 [ $version != '-' ] && libname=$library-$version
23 dllfile=$libname.dll
24
25 for F in $ldargs; do
26     case $F in
27         *.[ao]) objs="$objs $F";;
28     esac
29 done
30
31 # Check if we have a resource file for this DLL.
32 resfile=""
33 if [ -f $library.rc ]; then
34     # Kludge to get the path to the win32 headers. Should work for both
35     # gcc running on cygwin, and bare mingw gcc, even if the make is
36     # running on cygwin (whew).
37     WIN32APIHEADERS=`echo "\#include <winver.h>" | $GCC -M -E - | tail -1 | sed -e 's![\\/]winver.h!!' | tr -d '\015'`
38
39     resfile=$library-win32res.o
40     objs="$objs $resfile"
41
42     # Check if we have a build number stamp file.
43     if [ -f $library-build.stamp ]; then
44         read number <$library-build.stamp
45         buildnumber=$[number+1]
46         echo Build number is $buildnumber
47         echo $buildnumber >$library-build.stamp
48     else
49         echo Using zero as build number
50         buildnumber=0
51     fi
52
53     m4 -DBUILDNUMBER=$buildnumber <$library.rc >$library-win32res.rc
54     windres --include-dir $WIN32APIHEADERS $library-win32res.rc $library-win32res.o
55     rm $library-win32res.rc
56 fi
57
58 # Build the DLL.
59
60 $GCC -mdll -mno-cygwin -Wl,--base-file,$library.base -o $dllfile $ldargs &&
61 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --base-file $library.base --output-exp $library.exp $objs &&
62 $GCC -mdll -mno-cygwin -Wl,--base-file,$library.base,$library.exp -o $dllfile $ldargs &&
63 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --base-file $library.base --output-exp $library.exp $objs &&
64 $GCC -mdll -mno-cygwin -Wl,$library.exp -o $dllfile $ldargs &&
65 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --output-lib lib$libname.a $objs
66
67 # Finally, also build import libraries for the Microsoft linker. You
68 # will either need to have some decent version of MSVC, or get lib.exe
69 # (and link.exe) from the (freely downloadable) Microsoft Platform SDK.
70
71 if type -p lib.exe && [ -n "$def" -a "$def" != '-' ]; then
72     lib -name:$libname.dll -def:$def -out:$libname.lib
73 fi
74
75 rm $library.base $library.exp 2>/dev/null