File: build-dll

package info (click to toggle)
gtkgl2 1.99.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,104 kB
  • ctags: 330
  • sloc: sh: 6,744; ansic: 3,173; makefile: 125
file content (114 lines) | stat: -rwxr-xr-x 3,629 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash

# Wrapper script to build a DLL with gcc.

# In addition to just build the DLL with gcc -shared, it also links in
# a resource file containing an autoincremented build number, if
# available. See the compile-resource script.

# If version info (in the sense as used by libtool) is passed to this
# script, the generated DLL's name is suffixed with the number of the
# earliest implemented interface. Note that this suffix only is used
# in forming the name of the DLL, it is not related (from Windows's
# point of view) with the version resource inside the DLL. Also, note
# that this suffix is *not* related to the release number of the
# software package the library belongs to. (The version resource
# inside the DLL usually *does* refer to the software package's
# release number.) The DLL name also starts with "lib" in this case.

# If no version info is passed, no "lib" prefix is used for the DLL name.

# In addition to the DLL, also an import library is generated. The
# import library name does not contain the interface number
# suffix. This is intended to be similar in spirit to symlinking
# libfoo.so to libfoo.so.2.0.1 on Unix, and then when building some
# app, just specifying -lfoo.

# In addition to the gcc import library, if a .def file is passed on
# the command line, and the Microsoft linker is available, also a
# Microsoft import library (foo.lib) is generated.

# This script is usable at least with Cygwin 1.3.2 (the Cygwin bash is
# used to interpret this script, plus it calls at least m4), and
# gcc-2.95.3 and binutils-2.11.90 for Mingw (see www.mingw.org). For
# other combinations, no idea.

# The command line arguments are:
# $1: library base name, for instance foo
# $2: version info, like libtool's -version-info parameter. Consists of
#	one to three numbers, separated by a colon. See libtool documentation
#	for info. (Summary: The numbers are "current", "revision" and "age".)
#	The DLL name is suffixed with the value of current - age (age is always
#	less that or equal to current).
#	If you don't want any version suffix, pass - for this argument.
# rest: def file (if used), object files, libraries and other switches

# If called as 
#	build-dll foo 5:4:3 foo.def foobar.o tem.o zap.o ...
# this script would then generate libfoo-2.dll, libfoo.a, and foo.lib.
# (The last one only if the Microsoft linker is available). The lib prefix 
# is used in order to be libtool compatible.

library=$1; shift
version=$1; shift;
ldargs="$*"

[ -z "$CC" ] && CC=gcc

case "$CC" in
    gcc*)
	;;
    *)
	echo build-dll only works with gcc
	exit 1
	;;
esac

deffile=
for F in $ldargs; do
    case $F in
	*.def)	deffile=$F
    esac
done

dllfile=$library
if [ $version != '-' ]; then
    saved_IFS="$IFS"
    IFS=": "
    set $version 0 0
    IFS="$saved_IFS"
    if [ $# -gt 6 ]; then
	echo version info should be one to three numbers separated by colon
	exit 1
    fi
    current=$1
    age=$2
    dllfile=lib$library-$[current-age]
fi
dllfile=$dllfile.dll

# Check if we have a resource file for this DLL.

# The Cygwin dirname fails on Windows-style path syntax, which $0
# might be in some cases.
uname |grep CYGWIN > /dev/null
if [ "$?" = 0 ]; then
    t=`cygpath -au $0`
    d=`dirname $t`
else
    d=`dirname $0`
fi
resfile=$library-win32res.o
$d/compile-resource $library.rc $resfile && ldargs="$ldargs $resfile"

# Build the DLL.

$CC -shared -o $dllfile $ldargs -Wl,--out-implib,lib$library.a

# Finally, also build import libraries for the Microsoft linker.

if type -p lib.exe && [ -n "$deffile" ]; then
    lib -name:$dllfile -def:$deffile -out:$library.lib
fi

exit 0