# GNU Makefile for OS/2 -- using GCC/EMX-0.9d environment
#
# make dll    : builds mikmod.dll and its import lib mikmod.lib
# make static : builds the static library mikmod_static.lib

INCLUDES=-I../os2 -I../include
CC=gcc
AR=emxomfar
ARFLAGS=cr
IMPLIB=emximp

CFLAGS=-O2 -Wall -funroll-loops -ffast-math -fno-strength-reduce -Zomf -Zmt
CPPFLAGS=-DMIKMOD_BUILD -DHAVE_FCNTL_H -DHAVE_LIMITS_H -DHAVE_UNISTD_H -DHAVE_SYS_IOCTL_H -DHAVE_SYS_TIME_H

# To build a debug version:
#CPPFLAGS+= -DMIKMOD_DEBUG

# MMPM/2 driver (will work with any OS/2 version starting from 2.1.)
CPPFLAGS+= -DDRV_OS2
# DART (Direct Audio Real Time) driver (uses less CPU time than the
#                          standard MMPM/2 drivers, requires Warp4.)
CPPFLAGS+= -DDRV_DART
# support for aiff file output:
CPPFLAGS+= -DDRV_AIFF
# support for wav file output:
CPPFLAGS+= -DDRV_WAV
# support for output raw data to a file:
CPPFLAGS+= -DDRV_RAW
# support for output to stdout (not needed by everyone)
#CPPFLAGS+= -DDRV_STDOUT

# disable support for module depackers
#CPPFLAGS+= -DNO_DEPACKERS
# disable the high quality mixer (build only with the standart mixer)
#CPPFLAGS+= -DNO_HQMIXER

# drv_os2 and drv_dart require mmpm2
LIBS = -lmmpm2

COMPILE=$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES)

.SUFFIXES:
.SUFFIXES: .o .c

LIBNAME=mikmod3.lib
LIBSTATIC=mikmod_static.lib
DLLNAME=mikmod3.dll
DEFNAME=mikmod.def

OBJ=drv_os2.o drv_dart.o \
    drv_raw.o drv_aiff.o drv_wav.o \
    drv_nos.o drv_stdout.o \
    load_669.o load_amf.o load_asy.o load_dsm.o load_far.o load_gdm.o load_gt2.o \
    load_it.o load_imf.o load_m15.o load_med.o load_mod.o load_mtm.o load_okt.o \
    load_s3m.o load_stm.o load_stx.o load_ult.o load_umx.o load_uni.o load_xm.o \
    mmalloc.o mmerror.o mmio.o \
    mmcmp.o pp20.o s404.o xpk.o strcasecmp.o \
    mdriver.o mdreg.o mloader.o mlreg.o mlutil.o mplayer.o munitrk.o mwav.o \
    npertab.o sloader.o virtch.o virtch2.o virtch_common.o

help:
	@echo ""
	@echo "Valid targets:"
	@echo ""
	@echo "  $(MAKE) dll    : build dll and import library."
	@echo "  $(MAKE) static : build static library."
	@echo ""

clean: FORCE
	FOR %F IN ( $(LIBNAME) $(DLLNAME) $(OBJ) ) DO IF EXIST %F ERASE %F

dll: $(DLLNAME) $(LIBNAME)
static: $(LIBSTATIC)

$(DLLNAME): CFLAGS+=-Zdll
$(LIBNAME): $(DLLNAME)
$(DLLNAME): $(OBJ) $(DEFNAME)
	$(CC) $(CFLAGS) -Zso -Zsys -o $(DLLNAME) $(DEFNAME) $(OBJ) $(LIBS)
	$(IMPLIB) -o $(LIBNAME) $(DEFNAME)

$(LIBSTATIC): CPPFLAGS+=-DMIKMOD_STATIC
$(LIBSTATIC): $(OBJ)
	$(AR) $(ARFLAGS) $(LIBSTATIC) $(OBJ)

HEADER_DEPS=../include/mikmod.h ../include/mikmod_internals.h ../include/mikmod_ctype.h
drv_dart.o: ../drivers/drv_dart.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_dart.c
drv_nos.o: ../drivers/drv_nos.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_nos.c
drv_os2.o: ../drivers/drv_os2.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_os2.c
drv_raw.o: ../drivers/drv_raw.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_raw.c
drv_stdout.o: ../drivers/drv_stdout.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_stdout.c
drv_aiff.o: ../drivers/drv_aiff.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_aiff.c
drv_wav.o: ../drivers/drv_wav.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../drivers/drv_wav.c
load_669.o: ../loaders/load_669.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_669.c
load_amf.o: ../loaders/load_amf.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_amf.c
load_asy.o: ../loaders/load_asy.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_asy.c
load_dsm.o: ../loaders/load_dsm.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_dsm.c
load_far.o: ../loaders/load_far.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_far.c
load_gdm.o: ../loaders/load_gdm.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_gdm.c
load_gt2.o: ../loaders/load_gt2.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_gt2.c
load_it.o: ../loaders/load_it.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_it.c
load_imf.o: ../loaders/load_imf.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_imf.c
load_m15.o: ../loaders/load_m15.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_m15.c
load_med.o: ../loaders/load_med.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_med.c
load_mod.o: ../loaders/load_mod.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_mod.c
load_mtm.o: ../loaders/load_mtm.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_mtm.c
load_okt.o: ../loaders/load_okt.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_okt.c
load_s3m.o: ../loaders/load_s3m.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_s3m.c
load_stm.o: ../loaders/load_stm.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_stm.c
load_stx.o: ../loaders/load_stx.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_stx.c
load_ult.o: ../loaders/load_ult.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_ult.c
load_umx.o: ../loaders/load_umx.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_umx.c
load_uni.o: ../loaders/load_uni.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_uni.c
load_xm.o: ../loaders/load_xm.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../loaders/load_xm.c
mmalloc.o: ../mmio/mmalloc.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../mmio/mmalloc.c
mmerror.o: ../mmio/mmerror.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../mmio/mmerror.c
mmio.o: ../mmio/mmio.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../mmio/mmio.c
mmcmp.o: ../depackers/mmcmp.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../depackers/mmcmp.c
pp20.o: ../depackers/pp20.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../depackers/pp20.c
s404.o: ../depackers/s404.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../depackers/s404.c
xpk.o: ../depackers/xpk.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../depackers/xpk.c
mdriver.o: ../playercode/mdriver.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mdriver.c
mdreg.o: ../playercode/mdreg.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mdreg.c
mloader.o: ../playercode/mloader.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mloader.c
mlreg.o: ../playercode/mlreg.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mlreg.c
mlutil.o: ../playercode/mlutil.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mlutil.c
mplayer.o: ../playercode/mplayer.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mplayer.c
munitrk.o: ../playercode/munitrk.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/munitrk.c
mwav.o: ../playercode/mwav.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/mwav.c
npertab.o: ../playercode/npertab.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/npertab.c
sloader.o: ../playercode/sloader.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/sloader.c
virtch.o: ../playercode/virtch.c ../playercode/virtch_common.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/virtch.c
virtch2.o: ../playercode/virtch2.c ../playercode/virtch_common.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/virtch2.c
virtch_common.o: ../playercode/virtch_common.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../playercode/virtch_common.c
strcasecmp.o: ../posix/strcasecmp.c $(HEADER_DEPS)
	$(COMPILE) -o $@ -c ../posix/strcasecmp.c

FORCE:
