
#! /bin/sh
#  Example Script to compile and link a relocatable DLL
#    Files that make up the DLL = $foo.c  init.cc fixup.c.
#        (init.cc and fixup.c are housekeeping routines needed for the DLL. The actual
#                      library routines are in $foo.c and )
# ***Fill in your path to libcygwin.a here (with no trailing slash)***
LIBPATH=/lib

echo "Compiling" `basename $1 .c`".dll"

foo="`basename $1 .c`"

echo $foo

# Compile source files:
gcc -c $foo.c
gcc -c init.cc
gcc -c fixup.c

# Make .def file:
echo EXPORTS > $foo.def
nm $foo.o  init.o fixup.o | grep '^........ [T] _' | sed 's/[^_]*_//' >> $foo.def

# Link DLL.
ld --base-file $foo.base --dll -o $foo.dll $foo.o  init.o fixup.o \
 $LIBPATH/libcygwin.a /lib/w32api/libkernel32.a -e _dll_entry@12
dlltool --as=as --dllname $foo.dll --def $foo.def --base-file $foo.base --output-exp $foo.exp
ld --base-file $foo.base $foo.exp --dll -o $foo.dll $foo.o  init.o fixup.o  \
  $LIBPATH/libcygwin.a /lib/w32api/libkernel32.a -e _dll_entry@12
dlltool --as=as --dllname $foo.dll --def $foo.def --base-file $foo.base --output-exp $foo.exp
ld $foo.exp --dll -o $foo.dll $foo.o  init.o fixup.o  \
 $LIBPATH/libcygwin.a /lib/w32api/libkernel32.a -e _dll_entry@12

# Build the $foo.a lib to link to:
dlltool --as=as --dllname $foo.dll --def $foo.def --output-lib $foo.a

# Linking with main
#gcc main.c $foo.a -o main.exe


