2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / wrapper / build-dll
blobac223d1fd42e27b6efcd8690b8f886130787f624
1 #!/bin/bash
3 # Temporary hack until building dlls is easier with gcc -mno-cygwin
4 # ("mingw32").
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.
9 GCC="gcc"
10 DLLTOOL="dlltool"
11 AS=as
13 library=$1; shift
14 version=$1; shift;
15 def=$1; shift
16 ldargs="$*"
18 defswitch=""
19 [ -n "$def" -a "$def" != '-' ] && defswitch="--def $def"
21 libname=$library
22 [ $version != '-' ] && libname=$library-$version
23 dllfile=$libname.dll
25 for F in $ldargs; do
26 case $F in
27 *.[ao]) objs="$objs $F";;
28 esac
29 done
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"
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
49 m4 -DBUILDNUMBER=$buildnumber <$library.rc >$library-win32res.rc
50 windres $library-win32res.rc $library-win32res.o
51 rm $library-win32res.rc
54 # Build the DLL.
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
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.
67 if type -p lib.exe && [ -n "$def" -a "$def" != '-' ]; then
68 lib -name:$libname.dll -def:$def -out:$libname.lib
71 rm $library.base $library.exp 2>/dev/null