#               Makefile for wm-FPU-emu under DJGPP V2

#DEBUG	= -DDEBUGGING
DEBUG	=
PARANOID = -DPARANOID
REENTRANT	= -DREENTRANT_FPU
DJINC   = ../../../djgpp/wm-FPU-emu
CFLAGS	:= $(CFLAGS) $(PARANOID) $(DEBUG) -fno-builtin -I $(DJINC) -O2 -Wall

all:	libwmemu.a \
	wmemu387.dxe

emuentry.o: $(DJINC)/emuentry.c
	$(CC) $(CFLAGS) -c $< -o $@

# The $(wildcard) gork is because they might not have djlsr unzipped
npxsetup.c: $(wildcard $(DJDIR)/src/libc/emu387/npxsetup.c)
	update $(DJDIR)/src/libc/emu387/npxsetup.c ./npxsetup.c

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

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

%.o : %.S
	$(CC) -D__ASSEMBLER__ $(PARANOID) $(REENTRANT) -c $<

OBJS =	fpu_entry.o div_small.o errors.o \
	fpu_arith.o fpu_aux.o fpu_etc.o fpu_trig.o \
	load_store.o get_address.o \
	poly_atan.o poly_l2.o poly_2xm1.o poly_sin.o poly_tan.o \
	poly_div.o poly_mul64.o polynomial.o \
	reg_add_sub.o reg_compare.o reg_constant.o reg_ld_str.o \
	reg_div.o reg_mul.o reg_norm.o \
	reg_u_add.o reg_u_div.o reg_u_mul.o reg_u_sub.o \
	reg_round.o \
	wm_shrx.o wm_sqrt.o

libwmemu.a: $(OBJS) emuentry.o npxsetup.o
	command.com /c if exist libwmemu.a del libwmemu.a
	$(AR) rcs libwmemu.a $(OBJS) emuentry.o npxsetup.o

wmemu387.dxe: emuentry.o $(OBJS) 
	dxegen wmemu387.dxe __emu_entry emuentry.o libwmemu.a

dep:
	$(CPP) $(DJINC) -M *.c > dj.dep
	$(CPP) -D__ASSEMBLER__ -M *.S >> dj.dep

install:
	update wmemu387.dxe $(DJDIR)/bin/wmemu387.dxe
	update libwmemu.a $(DJDIR)/lib/libwmemu.a

clean:
	command.com .c for %f in (*.a *.o *.dep *.dxe npxsetup.c) do if exist %f del %f

dummy:

#
# include a dependency file if one exists
#
ifeq (dj.dep,$(wildcard dj.dep))
include dj.dep
endif
