#
# /emx/src/lib/sys/makefile
#
GCC=gcc -O -I/emx/include -I.. -Wall -mprobe $(MT_CCFLAGS)
AR=ar
I=/emx/include/
L=\emx\lib\ #
SYSCALLS=syscalls.h $(I)sys/signal.h
ERRNO=$(I)errno.h $(I)sys/errno.h
FMUTEX=$(I)sys/builtin.h $(I)sys/fmutex.h

PASSDOWN=CPU=$(CPU) DELOPT=$(DELOPT)

.SUFFIXES: .obj .s .asm

.SOURCE.c: ../$(CPU)
.SOURCE.s: ../$(CPU)
.SOURCE.asm: ../$(CPU)

.SOURCE.c: ..
.SOURCE.h: ..
.SOURCE.s: ..
.SOURCE.asm: ..

.PHONY: clean default dstlib sys sysmt sysst

DSTLIB=$(L)$(DIRNAME)\sys.lib

.c.obj:
	$(GCC) -c -s -Zomf $<

.s.obj:
	$(GCC) -c -s -Zomf -x assembler-with-cpp $<

#
# Requires MASM 6.0
#
# Without -Fo, MASM writes the output file to the directory of the source file
#
.asm.obj:
	ml -c -nologo -Cx -Fo$@ $<

default:    sys

sys .SEQUENTIAL: sysst sysmt

sysmt .SETDIR=mt_$(CPU):
	$(MAKE) -f ../makefile dstlib $(PASSDOWN) DIRNAME=mt MT_CCFLAGS=-Zmt

sysst .SETDIR=st_$(CPU):
	$(MAKE) -f ../makefile dstlib $(PASSDOWN) DIRNAME=st MT_CCFLAGS=

dstlib: $(DSTLIB)

clean:
	-del mt_$(CPU)\*.obj $(DELOPT)
	-del st_$(CPU)\*.obj $(DELOPT)

brk.obj: brk.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(FMUTEX) $(I)emx/syscalls.h
chdir.obj: chdir.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
chdrive.obj: chdrive.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
chmod.obj: chmod.c $(SYSCALLS) $(ERRNO) $(I)os2emx.h $(I)string.h \
		$(I)emx/syscalls.h
chsize.obj: chsize.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
clock.obj: clock.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
close.obj: close.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
dup.obj: dup.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
dup2.obj: dup2.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
emxinit.obj: emxinit.s
emx_ver.obj: emx_ver.s
endthrea.obj: endthrea.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
execname.obj: execname.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
exit.obj: exit.c $(I)os2emx.h
fcntl.obj: fcntl.c $(I)os2emx.h $(ERRNO) $(SYSCALLS) $(I)emx/syscalls.h \
		$(I)fcntl.h $(I)sys/fcntl.h
filefind.obj: filefind.c $(I)os2emx.h $(I)string.h $(ERRNO) $(SYSCALLS) \
		$(I)emx/syscalls.h
filesys.obj: filesys.c $(I)os2emx.h $(ERRNO) $(I)string.h $(SYSCALLS) \
		$(I)emx/syscalls.h
fstat.obj: fstat.c $(SYSCALLS) $(I)os2emx.h $(I)string.h $(I)sys/types.h \
		$(I)sys/stat.h $(I)emx/syscalls.h
fsync.obj: fsync.c $(I)os2emx.h $(SYSCALLS) $(I)emx/syscalls.h
ftime.obj: ftime.c $(I)os2emx.h $(SYSCALLS) $(I)sys/timeb.h $(I)time.h \
		$(I)emx/syscalls.h $(I)emx/time.h
ftruncat.obj: ftruncat.c $(I)os2emx.h $(SYSCALLS) $(I)emx/syscalls.h
getcwd.obj: getcwd.c $(I)os2emx.h $(SYSCALLS) $(I)emx/syscalls.h
getdrive.obj: getdrive.c $(I)os2emx.h $(SYSCALLS) $(I)emx/syscalls.h
getpid.obj: getpid.c $(I)os2emx.h $(SYSCALLS)
getppid.obj: getppid.c $(I)os2emx.h $(SYSCALLS)
heap.obj: heap.c $(SYSCALLS) $(I)os2emx.h $(I)sys/uflags.h $(I)emx/syscalls.h
heapdump.obj: heapdump.c $(SYSCALLS) $(I)os2emx.h $(I)sys/uflags.h \
		$(I)stdio.h $(I)emx/syscalls.h
imphandl.obj: imphandl.c $(I)emx/syscalls.h
init.obj: init.c $(I)os2emx.h $(SYSCALLS) $(I)string.h $(FMUTEX) \
		$(I)emx/syscalls.h $(I)emx/startup.h
initthre.obj: initthre.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
ioctl1.obj: ioctl1.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)emx/syscalls.h
ioctl2.obj: ioctl2.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)sys/ioctl.h \
		$(I)emx/syscalls.h
kill.obj: kill.c $(SYSCALLS) $(ERRNO) $(I)os2emx.h $(I)emx/syscalls.h
lseek.obj: lseek.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
memacces.obj: memacces.c $(SYSCALLS) $(I)emx/syscalls.h $(ERRNO)
memavail.obj: memavail.c $(I)emx/syscalls.h
mkdir.obj: mkdir.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
newthrea.obj: newthrea.c $(SYSCALLS) $(ERRNO) $(I)os2emx.h $(I)emx/syscalls.h
nls_memu.obj: nls_memu.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
nls_ctyp.obj: nls_ctyp.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h \
		$(I)sys/nls.h
open.obj: open.c $(SYSCALLS) $(I)os2emx.h $(I)string.h $(ERRNO) \
		$(I)emx/syscalls.h
os_ver.obj: os_ver.c $(I)emx/syscalls.h
p2t.obj: p2t.c $(SYSCALLS) $(I)os2emx.h $(I)time.h $(I)emx/syscalls.h \
		$(I)emx/time.h
pause.obj: pause.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
pipe.obj: pipe.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
portacce.obj: portacce.c $(SYSCALLS) $(I)emx/syscalls.h
raise.obj: raise.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)string.h \
		$(I)emx/syscalls.h
read.obj: read.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
read_kbd.obj: read_kbd.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
remove.obj: remove.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
rename.obj: rename.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
rmdir.obj: rmdir.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
sbrk.obj: sbrk.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(FMUTEX) \
		$(I)sys/uflags.h $(I)emx/syscalls.h
scrsize.obj: scrsize.c $(I)os2emx.h $(I)os2thunk.h $(I)emx/syscalls.h
sigactio.obj: sigactio.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)emx/syscalls.h
signal.obj: signal.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)emx/syscalls.h
sigpendi.obj: sigpendi.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)emx/syscalls.h
sigprocm.obj: sigprocm.c $(SYSCALLS) $(ERRNO) $(I)os2emx.h $(I)emx/syscalls.h
sigsuspe.obj: sigsuspe.c $(SYSCALLS) $(I)os2emx.h $(ERRNO) $(I)emx/syscalls.h
sleep.obj: sleep.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
sleep2.obj: sleep2.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
seterrno.obj: seterrno.c $(SYSCALLS) $(ERRNO)
spawnve.obj: spawnve.c $(SYSCALLS) $(I)stdlib.h $(PROCESS) $(I)string.h \
		$(ERRNO) $(I)os2emx.h $(I)emx/syscalls.h
stat.obj: stat.c $(SYSCALLS) $(I)os2emx.h $(I)string.h $(I)sys/types.h \
		$(I)sys/stat.h $(ERRNO) $(I)emx/syscalls.h
swchar.obj: swchar.c $(SYSCALLS)
systhrea.obj: systhrea.s
thunk0.obj: thunk0.asm
thunk1.obj: thunk1.asm
uflags.obj: uflags.c $(SYSCALLS)
ulimit.obj: ulimit.c $(I)sys/ulimit.h $(SYSCALLS) $(ERRNO) $(I)emx/syscalls.h
umask.obj: umask.c $(SYSCALLS) $(I)emx/syscalls.h
utimes.obj: utimes.c $(SYSCALLS) $(I)os2emx.h $(I)time.h $(I)sys/time.h \
		$(I)string.h $(ERRNO) $(I)emx/syscalls.h
unwind.obj: unwind.s
wait.obj: wait.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
waitpid.obj: waitpid.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h
write.obj: write.c $(SYSCALLS) $(I)os2emx.h $(I)emx/syscalls.h

heapsize.obj: ../heapsize.c $(SYSCALLS)
	$(GCC) -c -s -Zomf -DHEAPSIZE=0x2000000 ../heapsize.c

$(DSTLIB):  brk.obj chdir.obj chdrive.obj chmod.obj chsize.obj \
    clock.obj close.obj dup.obj dup2.obj emxinit.obj emx_ver.obj \
    endthrea.obj execname.obj exit.obj fcntl.obj filefind.obj filesys.obj \
    fstat.obj fsync.obj ftime.obj ftruncat.obj getcwd.obj \
    getdrive.obj getpid.obj getppid.obj heap.obj heapdump.obj heapsize.obj \
    imphandl.obj init.obj initthre.obj ioctl1.obj \
    ioctl2.obj kill.obj lseek.obj memacces.obj memavail.obj mkdir.obj \
    newthrea.obj nls_ctyp.obj nls_memu.obj open.obj os_ver.obj p2t.obj \
    pause.obj pipe.obj portacce.obj raise.obj read.obj read_kbd.obj \
    remove.obj rename.obj rmdir.obj sbrk.obj scrsize.obj seterrno.obj \
    sigactio.obj signal.obj sigpendi.obj sigprocm.obj sigsuspe.obj \
    sleep.obj sleep2.obj spawnve.obj stat.obj swchar.obj \
    systhrea.obj thunk0.obj thunk1.obj uflags.obj ulimit.obj umask.obj \
    unwind.obj utimes.obj wait.obj waitpid.obj write.obj
	-del $(DSTLIB)
	emxomfar rc $(DSTLIB) *.obj
