Sun Sep 17 2000 Elliot Lee <sopwith@redhat.com> Define g_alloca() as an
[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 1.1.x and gcc-2.95.2 for mingw as
7 # distributed by 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     resfile=$library-win32res.o
35     objs="$objs $resfile"
36     ldargs="$ldargs $resfile"
37
38     # Check if we have a build number stamp file.
39     if [ -f $library-build.stamp ]; then
40         read number <$library-build.stamp
41         buildnumber=$[number+1]
42         echo Build number is $buildnumber
43         echo $buildnumber >$library-build.stamp
44     else
45         echo Using zero as build number
46         buildnumber=0
47     fi
48
49     m4 -DBUILDNUMBER=$buildnumber <$library.rc >$library-win32res.rc
50     windres $library-win32res.rc $library-win32res.o
51     rm $library-win32res.rc
52 fi
53
54 # Build the DLL.
55
56 $GCC -mdll -mno-cygwin -Wl,--base-file,$library.base -o $dllfile $ldargs &&
57 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --base-file $library.base --output-exp $library.exp $objs &&
58 $GCC -mdll -mno-cygwin -Wl,--base-file,$library.base,$library.exp -o $dllfile $ldargs &&
59 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --base-file $library.base --output-exp $library.exp $objs &&
60 $GCC -mdll -mno-cygwin -Wl,$library.exp -o $dllfile $ldargs &&
61 $DLLTOOL --as=$AS --dllname $dllfile $defswitch --output-lib lib$libname.a $objs
62
63 # Finally, also build import libraries for the Microsoft linker. You
64 # will either need to have some decent version of MSVC, or get lib.exe
65 # (and link.exe) from the (freely downloadable) Microsoft Platform SDK.
66
67 if type -p lib.exe && [ -n "$def" -a "$def" != '-' ]; then
68     lib -name:$libname.dll -def:$def -out:$libname.lib
69 fi
70
71 rm $library.base $library.exp 2>/dev/null