#
#	Makefile for RSX 32bit (compiled with EMX+GCC)
#	Rainer Schnitker
#

# This Makefile was written for gnu make
# Change VPATH statements for others

# vpath: your make uses ';' or ':' between directories
VPATH = $(BLD);$(SOURCEASM);.
#VPATH = $(BLD):$(SOURCEASM):.

# not supported by borland make
#.SUFFIXES : .exe .emx .o .c .s

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

CC = gcc.exe
AS = gcc.exe -x assembler-with-cpp
LINK = ld.exe
CFLAGS = -Wall -I. -g $(DEB) -O2
AFLAGS = -Wall -I$(SOURCEASM)  -g
DEB =

BLD=build
SOURCEASM=asm32

.c.o:
	$(CC) -c $(CFLAGS) -o $(BLD)\$*.o $<

.s.o:
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $<

OBJS =	rsx.o \
	start32.o \
	process.o \
	signals.o \
	ptrace.o \
	termio.o \
	doserrno.o \
	sysemx.o \
	sysdj.o \
	cdosx32.o \
	loadprg.o \
	timedos.o \
	rmlib.o \
	statemx.o \
	djio.o \
	sysdep2.o \
	fs.o

KDEB  = kdeb.o

CRT0  = crt0.o

AOBJS = dpmi.o \
	dpmi10.o \
	excep32.o \
	adosx32.o \
	copy32.o \
	fpu.o

LIBOBJS = printf.o libc.o

FPU_EMU = fpu-emu\build\crt0fpu.o fpu-emu\build\fpu-emu.o

ALL: rsx.emx \rsx\bin\rsx.exe
	@echo rsx ready!

rsx.emx : $(CRT0) $(AOBJS) $(OBJS) $(LIBOBJS) $(FPU_EMU)
	ld -o rsx.emx $(CRT0) @ofiles.rsp $(FPU_EMU)
	strip rsx.emx

rsxd.emx : $(CRT0) $(AOBJS) $(OBJS) $(LIBOBJS) $(FPU_EMU) $(KDEB)
	ld -o rsxd.emx $(CRT0) @ofiles.rsp build\$(KDEB) $(FPU_EMU)
	copy /B loader\loader.exe + rsxd.emx \rsx\bin\rsx.exe


\rsx\bin\rsx.exe: rsx.emx loader\loader.exe
	copy /B loader\loader.exe + rsx.emx \rsx\bin\rsx.exe



#
# ASM-files in asm32 directory
#
dpmi10.o:   $(SOURCEASM)\dpmi10.s
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $(SOURCEASM)\$*.s
excep32.o:  $(SOURCEASM)\excep32.s
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $(SOURCEASM)\$*.s
adosx32.o:  $(SOURCEASM)\adosx32.s
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $(SOURCEASM)\$*.s
copy32.o:   $(SOURCEASM)\copy32.s
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $(SOURCEASM)\$*.s
# startup file
crt0.o: $(SOURCEASM)\crt0.s
	$(AS) -c $(AFLAGS) -o $(BLD)\$*.o $(SOURCEASM)\$*.s

#
# C-files in asm32 directory
#
dpmi.o: $(SOURCEASM)\dpmi.c
	$(CC) -c $(CFLAGS) $(SOURCEASM)\dpmi.c -o $(BLD)\dpmi.o -I$(SOURCEASM)
fpu.o: $(SOURCEASM)\fpu.c
	$(CC) -c $(CFLAGS) $(SOURCEASM)\fpu.c -o $(BLD)\fpu.o -I$(SOURCEASM)

