Annotation of OpenXM_contrib/pari-2.2/config/Makefile.DLLs, Revision 1.1.1.1
1.1 noro 1: # This makefile is freely available from the website of Cygnus Solutions
2: # at http://www.cygnus.com on the cygwin32 home page. The author is
3: # Fergus Henderson <fjh@cs.mu.oz.au> http://www.cs.mu.oz.au/~fjh
4: # Before using this file you should read and understand the documentation
5: # on the Cygnus website.
6: # This file comes with a suitable disclaimer; i.e.,
7: # This is provided AS IS, with absolutely NO WARRANTY EITHER EXPRESSED
8: # OR IMPLIED.
9:
10: #-----------------------------------------------------------------------------#
11:
12: # Makefile.DLLs, version 0.7.
13:
14: # This Makefile contains rules for creating DLLs on Windows using gnu-win32.
15:
16: #-----------------------------------------------------------------------------#
17:
18: # The SYM_PREFIX is used as a prefix for the symbols in the files
19: # that this makefiles automatically generates.
20: #
21: # The default SYM_PREFIX for libfoo.dll is `libfoo'.
22: # But you can override this by setting `SYM_PREFIX-libfoo = blah'.
23:
24: SYM_PREFIX = $(firstword $(SYM_PREFIX-$*) $*)
25:
26: GUARD_MACRO = $(SYM_PREFIX)_GLOBALS_H
27: DEFINE_DLL_MACRO = $(SYM_PREFIX)_DEFINE_DLL
28: USE_DLL_MACRO = $(SYM_PREFIX)_USE_DLL
29: IMP_MACRO = $(SYM_PREFIX)_IMP
30: GLOBAL_MACRO = $(SYM_PREFIX)_GLOBAL
31: IMPURE_PTR = $(SYM_PREFIX)_impure_ptr
32:
33: # This rule creates a `.def' file, which lists the symbols that are exported
34: # from the DLL. We use `nm' to get a list of all the exported text (`T')
35: # symbols and data symbols -- including uninitialized data (`B'),
36: # initialized data (`D'), read-only data (`R'), and common blocks (`C').
37: # We also export `_impure_ptr', suitably renamed, so that the
38: # main program can do the necessary initialization of the DLL's _impure_ptr.
39: # (Since there can be more than one DLL, we must rename _impure_ptr as
40: # $(SYM_PREFIX)_impure_ptr to prevent name collisions.)
41: %.def: %.a
42: echo EXPORTS > $@
43: echo $(IMPURE_PTR) = _impure_ptr >> $@
44: nm $< | sed -n '/^........ [BCDRT] _/s/[^_]*_//p' >> $@
45:
46: # We need to use macros to access global data:
47: # the user of the DLL must refer to `bar' as `(*__imp_bar)'.
48: # This rule creates a pair of files `foo_dll.h' and `foo_globals.h'
49: # which contains macros for doing this.
50: #
51: # The DLL may also contain some references to _impure_ptr
52: # (e.g. stdin is defined as a macro which expands to _impure_ptr.stdin).
53: # We need to provide a definition for this (otherwise it will link in
54: # the definition in libccrt.o, which causes lots of problems,
55: # eventually leading to undefined symbol `WinMain').
56: # The DLL's entry function (below) will initialize the _impure_ptr variable
57: # in the DLL so that they point to the main program's reent_data struct.
58:
59: %_dll.h:
60: echo "/* automatically generated by Makefile.DLLs */" > $@
61: echo "#ifndef $(GUARD_MACRO)" >> $@
62: echo "#define $(GUARD_MACRO)" >> $@
63: echo "" >> $@
64: echo "#if defined(__GNUC__) && defined(__CYGWIN32__)" >> $@
65: echo " #if defined($(USE_DLL_MACRO))" >> $@
66: echo " #define $(IMP_MACRO)(name) __imp_##name" >> $@
67: echo " #define $(GLOBAL_MACRO)(name) (*$(IMP_MACRO)(name))" >> $@
68: echo " #include \"$*_globals.h\"" >> $@
69: echo " #endif /* $(USE_DLL_MACRO) */" >> $@
70: echo "#endif /* __GNUC__ && __CYGWIN32__ */" >> $@
71: echo "" >> $@
72: echo "#endif /* $(GUARD_MACRO) */" >> $@
73:
74: %_globals.h: %.a
75: echo "/* automatically generated by Makefile.DLLs */" > $@
76: for sym in $(IMPURE_PTR) \
77: `nm $< | grep '^........ [BCDR] _' | sed 's/[^_]*_//'`; \
78: do \
79: echo "#define $$sym $(GLOBAL_MACRO)($$sym)" >> $@; \
80: done
81:
82: %_dll.c:
83: echo "/* automatically generated by Makefile.DLLs */" > $@
84: echo "void *_impure_ptr;" >> $@
85:
86: # This rule creates the export object file (`foo.exp') which contains the
87: # jump table array; this export object file becomes part of the DLL.
88: # This rule also creates the import library (`foo_dll.a') which contains small
89: # stubs for all the functions exported by the DLL which jump to them via the
90: # jump table. Executables that will use the DLL must be linked against this
91: # stub library.
92: %.exp %_dll.a : %.def
93: dlltool $(DLLTOOLFLAGS) $(DLLTOOLFLAGS-$*) \
94: --def $< \
95: --dllname $*.dll \
96: --output-exp $*.exp \
97: --output-lib $*_dll.a
98:
99: # The `sed' commands below are to convert DOS-style `C:\foo\bar'
100: # pathnames into Unix-style `//c/foo/bar' pathnames.
101: CYGWIN32_LIBS = $(shell echo \
102: -L`dirname \`gcc -print-file-name=libgcc.a | \
103: sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
104: -L`dirname \`gcc -print-file-name=libcygwin.a | \
105: sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
106: -L`dirname \`gcc -print-file-name=libkernel32.a | \
107: sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
108: -lgcc -lcygwin -lkernel32 -lgcc)
109:
110: # Making relocatable DLLs doesn't seem to work.
111: # Not quite sure why. The --image-base values below
112: # where chosen at random, they seem to work on my machine.
113: # DYNRELOC=no is the default
114: # DLLDFLAGS-libgc += --image-base=0x2345000
115: # DLLDFLAGS-libmer += --image-base=0x1234000
116: # DLLDFLAGS-libmercury += --image-base=0x3456000
117:
118: ifeq "$(strip $(DYNRELOC))" "yes"
119:
120: # to create relocatable DLLs, we need to do two passes
121: # (warning: this is untested)
122: %.dll: %.exp %.a %_dll.o dll_init.o dll_fixup.o
123: $(DLLD) $(DLLDFLAGS) $(DLLDFLAGS-$*) --dll -o $*.base \
124: -e _dll_entry@12 \
125: $*.exp $*.a $*_dll.o \
126: dll_init.o dll_fixup.o \
127: $(LDLIBS) $(LDLIBS-$*) \
128: $(CYGWIN32_LIBS)
129: # untested
130: dlltool $(DLLTOOLFLAGS) $(DLLTOOLFLAGS-$*) \
131: --def $*.def \
132: --dllname $*.dll \
133: --base-file $*.base \
134: --output-exp $*.exp
135: $(DLLD) $(DLLDFLAGS) $(DLLDFLAGS-$*) --dll -o $*.base \
136: -e _dll_entry@12 \
137: $*.exp $*.a $*_dll.o \
138: dll_init.o dll_fixup.o \
139: $(LDLIBS) $(LDLIBS-$*) \
140: $(CYGWIN32_LIBS)
141: dlltool $(DLLTOOLFLAGS) $(DLLTOOLFLAGS-$*) \
142: --def $*.def \
143: --dllname $*.dll \
144: --base-file $*.base \
145: --output-exp $*.exp
146: # end untested stuff
147: $(DLLD) $(DLLDFLAGS) $(DLLDFLAGS-$*) --dll --base-file $*.base -o $@ \
148: -e _dll_entry@12 \
149: $*.exp $*.a $*_dll.o \
150: dll_init.o dll_fixup.o \
151: $(LDLIBS) $(LDLIBS-$*) \
152: $(CYGWIN32_LIBS)
153: rm -f $*.base
154:
155: else
156:
157: %.dll: %.exp %.a %_dll.o dll_fixup.o dll_init.o
158: $(DLLD) $(DLLDFLAGS) $(DLLDFLAGS-$*) --dll -o $@ \
159: -e _dll_entry@12 \
160: $*.exp $*.a $*_dll.o \
161: dll_init.o dll_fixup.o \
162: $(LDLIBS) $(LDLIBS-$*) \
163: $(CYGWIN32_LIBS)
164:
165: endif
166:
167: # This black magic piece of assembler needs to be linked in in order to
168: # properly terminate the list of imported DLLs.
169: dll_fixup.s:
170: echo '.section .idata$$3' > dll_fixup.s
171: echo '.long 0,0,0,0,0' >> dll_fixup.s
172:
173: dll_fixup.o: dll_fixup.s
174: $(AS) $(ASFLAGS) -o dll_fixup.o dll_fixup.s
175:
176: # Windows requires each DLL to have an initialization function
177: # that is called at certain points (thread/process attach/detach).
178: # This one just initializes `_impure_ptr'.
179: dll_init.c:
180: echo '#include <stdio.h>' > dll_init.c
181: echo 'extern struct _reent *_impure_ptr;' >> dll_init.c
182: echo 'extern __declspec(dllimport) struct _reent reent_data;' >> dll_init.c
183: echo '__attribute__((stdcall))' >> dll_init.c
184: echo 'int dll_entry(int handle, int reason, void *ptr)' >> dll_init.c
185: echo '{ _impure_ptr = reent_data; return 1; }' >> dll_init.c
186:
187: # The following rule is just there to convince gcc
188: # to keep otherwise unused intermediate targets around.
189: dont_throw_away: dll_fixup.o dll_init.o
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>