1 #-----------------------------------------------------------------------------#
3 # Makefile.DLLs, version 0.4.
5 # Contributed by Fergus Henderson.
7 # This Makefile contains rules for creating DLLs on Windows using gnu-win32.
9 #-----------------------------------------------------------------------------#
11 # This rule creates a `.def' file, which lists the symbols that are exported
12 # from the DLL. We use `nm' to get a list of all the exported text (`T')
13 # symbols and data symbols -- including uninitialized data (`B'),
14 # initialized data (`D'), read-only data (`R'), and common blocks (`C').
17 nm $< | grep '^........ [BCDRT] _' | sed 's/[^_]*_//' >> $@
19 # We need to use macros to access global data:
20 # the user of the DLL must refer to `foo' as `(*__imp_foo)'.
21 # This rule creates a `_globals.h' file, which contains macros
24 SYM_PREFIX = $(firstword $(SYM_PREFIX-$*) $*)
25 DLL_MACRO = $(SYM_PREFIX)_USE_DLL
26 IMP_MACRO = $(SYM_PREFIX)_IMP
27 GLOBAL_MACRO = $(SYM_PREFIX)_GLOBAL
30 echo "/* automatically generated by Makefile.DLLs */" > $@
31 echo "#if defined(__GNUC__) && defined(_WIN32) \\" >> $@
32 echo " && defined($(DLL_MACRO))" >> $@
33 echo "# define $(IMP_MACRO)(name) __imp_##name" >> $@
34 echo "# define $(GLOBAL_MACRO)(name) (*$(IMP_MACRO)(name))" >> $@
36 echo "# define $(GLOBAL_MACRO)(name) name" >> $@
39 for sym in `nm $< | grep '^........ [BCDR] _' | sed 's/[^_]*_//'`; do \
40 echo "#define $$sym $(GLOBAL_MACRO)($$sym)" >> $@; \
43 # This rule creates the export object file (`foo.exp') which contains the
44 # jump table array; this export object file becomes part of the DLL.
45 # This rule also creates the import library (`foo_dll.a') which contains small
46 # stubs for all the functions exported by the DLL which jump to them via the
47 # jump table. Executables that will use the DLL must be linked against this
50 dlltool $(DLLTOOLFLAGS) $(DLLTOOLFLAGS-$*) \
56 # The `sed' commands below are to convert DOS-style `C:\foo\bar'
57 # pathnames into Unix-style `//c/foo/bar' pathnames.
58 CYGWIN32_LIBS = $(shell echo \
59 -L`dirname \`gcc -print-file-name=libgcc.a | \
60 sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
61 -L`dirname \`gcc -print-file-name=libcygwin.a | \
62 sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
63 -L`dirname \`gcc -print-file-name=libkernel32.a | \
64 sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
65 -lgcc -lcygwin -lkernel32 -lgcc)
69 ifeq "$(strip $(RELOCATABLE))" "yes"
71 # to create relocatable DLLs, we need to do two passes
72 %.dll: %.exp %.a dll_fixup.o dll_init.o
73 $(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll -o $*.base \
74 -e _dll_entry@12 dll_init.o \
75 dll_fixup.o $*.exp $*.a \
76 $(LDLIBS) $(LDLIBS-$*) \
78 $(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll --base-file $*.base -o $@ \
79 -e _dll_entry@12 dll_init.o \
80 dll_fixup.o $*.exp $*.a \
81 $(LDLIBS) $(LDLIBS-$*) \
86 %.dll: %.exp %.a dll_fixup.o dll_init.o
87 $(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll -o $@ \
88 -e _dll_entry@12 dll_init.o \
89 dll_fixup.o $*.exp $*.a \
90 $(LDLIBS) $(LDLIBS-$*) \
95 # This black magic piece of assembler needs to be linked in in order to
96 # properly terminate the list of imported DLLs.
98 echo '.section .idata$$3' > dll_fixup.s
99 echo '.long 0,0,0,0, 0,0,0,0' >> dll_fixup.s
101 # This bit is necessary to provide an initialization function for the DLL.
103 echo '__attribute__((stdcall))' > dll_init.c
104 echo 'int dll_entry(int handle, int reason, void *ptr)' >> dll_init.c
105 echo '{return 1; }' >> dll_init.c
107 dont_throw_away: dll_fixup.o dll_init.o