%.def: %.a
echo EXPORTS > $@
nm $< | grep '^........ [BCDRT] _' | sed 's/[^_]*_//' >> $@
SYM_PREFIX = $(firstword $(SYM_PREFIX-$*) $*)
DLL_MACRO = $(SYM_PREFIX)_USE_DLL
IMP_MACRO = $(SYM_PREFIX)_IMP
GLOBAL_MACRO = $(SYM_PREFIX)_GLOBAL
%_globals.h: %.a
echo "/* automatically generated by Makefile.DLLs */" > $@
echo "#if defined(__GNUC__) && defined(_WIN32) \\" >> $@
echo " && defined($(DLL_MACRO))" >> $@
echo "# define $(IMP_MACRO)(name) __imp_##name" >> $@
echo "# define $(GLOBAL_MACRO)(name) (*$(IMP_MACRO)(name))" >> $@
echo "#else" >> $@
echo "# define $(GLOBAL_MACRO)(name) name" >> $@
echo "#endif" >> $@
echo "" >> $@
for sym in `nm $< | grep '^........ [BCDR] _' | sed 's/[^_]*_//'`; do \
echo "#define $$sym $(GLOBAL_MACRO)($$sym)" >> $@; \
done
%.exp %_dll.a : %.def
dlltool $(DLLTOOLFLAGS) $(DLLTOOLFLAGS-$*) \
--def $< \
--dllname $*.dll \
--output-exp $*.exp \
--output-lib $*_dll.a
CYGWIN32_LIBS = $(shell echo \
-L`dirname \`gcc -print-file-name=libgcc.a | \
sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
-L`dirname \`gcc -print-file-name=libcygwin.a | \
sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
-L`dirname \`gcc -print-file-name=libkernel32.a | \
sed -e 's@^\\\\([A-Za-z]\\\\):@//\\\\1@g' -e 's@\\\\\\\\@/@g' \` ` \
-lgcc -lcygwin -lkernel32 -lgcc)
RELOCATABLE=yes
ifeq "$(strip $(RELOCATABLE))" "yes"
%.dll: %.exp %.a dll_fixup.o dll_init.o
$(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll -o $*.base \
-e _dll_entry@12 dll_init.o \
dll_fixup.o $*.exp $*.a \
$(LDLIBS) $(LDLIBS-$*) \
$(CYGWIN32_LIBS)
$(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll --base-file $*.base -o $@ \
-e _dll_entry@12 dll_init.o \
dll_fixup.o $*.exp $*.a \
$(LDLIBS) $(LDLIBS-$*) \
$(CYGWIN32_LIBS)
rm -f $*.base
else
%.dll: %.exp %.a dll_fixup.o dll_init.o
$(LD) $(LDFLAGS) $(LDFLAGS-$*) --dll -o $@ \
-e _dll_entry@12 dll_init.o \
dll_fixup.o $*.exp $*.a \
$(LDLIBS) $(LDLIBS-$*) \
$(CYGWIN32_LIBS)
endif
dll_fixup.s:
echo '.section .idata$$3' > dll_fixup.s
echo '.long 0,0,0,0, 0,0,0,0' >> dll_fixup.s
dll_init.c:
echo '__attribute__((stdcall))' > dll_init.c
echo 'int dll_entry(int handle, int reason, void *ptr)' >> dll_init.c
echo '{return 1; }' >> dll_init.c
dont_throw_away: dll_fixup.o dll_init.o