Ignore the SVN perl module which is installed since 1fd8f97
[msysgit.git] / mingw / bin / a2dll
blobeb7be60f75ac5300a2ce1fd22cb646a6e2e6a0d3
1 #!/bin/sh
3 # This is a2dll 1.0
4 # (c)1999-2000 Paul Sokolovsky
5 # a2dll is distrubuted under GNU General Public License, see http://www.gnu.org
8 usage() {
9 echo 'a2dll 1.0: convert static library into win32 dll'
10 echo ' by <Paul.Sokolovsky@technologist.com>'
11 echo 'Usage: a2dll <staticlib> [-o <dllname>] [linker commands:-L,-l,-s] [--relink]'
12 exit 0
16 cmdline=$@
18 while test $# -ge 1
20 case "$1" in
21 -\? | -h* | --h*) usage;;
22 -o ) out="$2"; shift; shift;;
23 --relink) relink=1; shift;;
24 -* ) libs="$libs $1"; shift;;
25 *) in=$1; shift;;
26 esac
27 done
29 if [ "$in" = "" ]
30 then
31 usage
34 base=`basename $in .a`
36 if [ "$out" = "" ]
37 then
38 out=`awk -v n=$base 'BEGIN {print substr(n,4); exit;}'`.dll
41 if [ "$relink" != "1" ]
42 then
43 rm -f .dll/*
44 /usr/bin/mkdir -p .dll
45 cd .dll
46 ar x ../$in
47 else
48 cd .dll
51 echo Creating shared library \'$out\'
53 dllwrap --export-all -o ../$out `ls` $libs >../ld.err 2>&1
55 cd ..
56 if [ `wc ld.err|awk ' {print $1}' ` -gt 2 ]
57 then
58 echo Linking error, consult file \'ld.err\', correct errors, and run
59 echo \'$0 $cmdline --relink\'
60 exit 1
61 else
62 # cleanup
64 rm -f ld.err
65 rm -f .dll/*
66 /usr/bin/rmdir .dll
68 # create .def
69 # we use pexports on dll instead of dlltool on objects for this,
70 # because it's:
71 # 1. faster
72 # 2. I just saw that dlltool lies about assembly-sourced files, it
73 # lists their symbols as data
75 pexports $out >$base.def
77 # create import library
79 mv $in $in.static
80 dlltool --dllname $out --def $base.def --output-lib $in
82 # finally, we check whether dll exports data symbols
83 # if yes, we suggest user on steps to perform
85 pexports $out | awk '/DATA/ { print $1}' >$out.data
86 if test -s $out.data
87 then
88 echo
89 echo Shared library exports data symbols, they are listed \
90 in \'$out.data\'. For using them in client application, you should mark \
91 them as __declspec\(dllimport\) in library headers. You can quickly \
92 find places where these data symbols declared by issuing
93 echo
94 echo " grep -f $out.data *.h"
95 echo
96 echo in library header directory. Also note that this step is optional, you can postpone \
97 it until you\'ll get during linking unresolved symbol _imp__\<something\>, where \
98 \<something\> is one of the symbols listed in $out.data. Read documentation \
99 \(static2dll_howto.txt\) for more information.
100 else
101 rm $out.data
103 rm $base.def