#
# Compile the MCI-to-DirectMusic wrapper by Norman Rasmussen
#
# You must have the DirectX SDK header files in the include directories
# or specify them at the -I option.
# You must also patch the DirectX dmdls.h file using dmdls.h.diff
# which you can find here.
#
# Then just say "make".
#

# path to the DirectX include files (patched using dmdls.h.diff)
DXINCLUDE = dxinc

# path to the MingW libraries
MINGWLIB = /usr/lib/mingw

# The rest should be fine as it is, but change CFLAGS for gcc 3.x
DLLNAME = dxmci
DEF_FILE = $(DLLNAME).def
DLL_OFILES = $(DLLNAME).o
DLL_ENTRY = _DllMain@12
DLL_IMPORTS = -lcrtdll -luser32 -lole32 -ldxguid -lkernel32


CC = gcc
CXX = g++

# if you're using gcc 3.x or higher, remove the -fvtable-thunks option
CFLAGS = -c -Os -fvtable-thunks -mno-cygwin -I $(DXINCLUDE) -march=i386 -mcpu=pentium
CXXFLAGS = $(CFLAGS)

LDPATH = -L$(MINGWLIB)
LDOPTS =  -Wl,--enable-auto-image-base
LDOPTS += -Wl,-Map,$(@:%.dll=%.map)		# uncomment to make map files


all:    $(DLLNAME).dll

# compile the C++ files
%.o : %.c
	$(CC) -o $@ $(CFLAGS) $<

%.o : %.cpp
	$(CXX) -o $@ $(CXXFLAGS) $<

%.o : %.c
	$(CC) -o $@ $(CFLAGS) $<

# make assembly file for testing the compile output
%.s : %.cpp
	$(CXX) -S -o $@ $(CXXFLAGS) $<

%.lst : %.s
	as -a -o /dev/null $< > $@

# generate the export definition file
$(DLLNAME).def: $(DLL_OFILES)
	dlltool -z $@ $^

# compile the DLL
$(DLLNAME).dll: $(DEF_FILE) $(DLL_OFILES)
	$(CXX) -o $@ -nostdlib -shared -e $(DLL_ENTRY) -Wl,--subsystem,windows,-s \
		$^ $(LDOPTS) \
		$(LDPATH) $(DLL_IMPORTS)

distclean:
	rm -f *.o *.map *.s *.dmp 

clean:	distclean
	rm -f *.dll *.def
