#
# /emx/test/makefile
#
#
# NOTE: Some targets need additional tools, not shipped with emx:
#
# diff  (gnudiff.zip): strtol, printf, scanf, gcvt, math, mktime, strptime,
#                      inet
# sed   (gnused.zip):  dll7
# MASM 6.00A:          c16.dll emxaout1.exe
# Microsoft C 6.00A:   c16.dll
# Devoloper's Toolkit: msgtest
#
# -------------------- CUSTOMIZATION --------------------
#
# Hostname of a Unix host, for select2 test
#
UNIXHOST=fidelio
#
# ------------------------- END -------------------------

CFLAGS=-g -Wall
CC0=gcc
CC=$(CC0) $(CFLAGS)
B=/emx/bin/
I=/emx/include/
S=$(I)sys/
IP=/emx/include/cpp/
L=/emx/lib/
LL=\emx\lib\ #
SIGNAL=$(I)signal.h $(S)signal.h
FCNTL=$(I)fcntl.h $(S)fcntl.h
ERRNO=$(I)errno.h $(S)errno.h
PROCESS=$(I)process.h $(S)process.h
LIBS=$(L)crt0.o $(L)st/c.a $(L)gcc.a
LIBSMT=$(L)crt0.o $(L)mt/c.a $(L)gcc.a
LIBP=$(L)iostream.a
LIBOS2=$(L)os2.a
LIBBSD=$(L)bsd.a


.SUFFIXES: .o .c .cc .s .exe

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

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

.c.s:
	$(CC) -S $<

.o.exe:
	$(CC) -o $*.exe $<

default:        reg-all

reg-all:	reg-base reg-tcpip
reg-base:	reg-base-auto reg-base-look
reg-tcpip:	reg-tcpip-auto reg-tcpip-look
reg-auto:	reg-base-auto reg-tcpip-auto
reg-look:	reg-base-look reg-tcpip-look

#
# All programs but regression tests
#
all-tests:      common plusplus os2only dosonly

common:         access.exe alarm.exe args.exe bsdtest.exe conv.exe \
                coretest.exe coretst2.exe ctypetst.exe debug.exe divtest.exe \
                dttest.exe dupexec.exe errno.exe exec.exe explode.exe \
                float.exe ftwtest.exe \
                fullpath.exe hexdump.exe hw_io.exe longlong.exe \
                mdecho.exe memory.exe memtest.exe mftest.exe nls.exe \
                pid.exe printf0.exe retcode.exe rndheap.exe \
                sbrktest.exe scanf0.exe sig2.exe sig3.exe \
                sig4.exe sig6.exe sig8.exe \
                sigsegv.exe splitarg.exe stack.exe \
                stdiotst.exe strftime.exe system.exe swaptest.exe \
                telltext.exe termio.exe timetest.exe tmpnam.exe \
                trunc.exe uname.exe version.exe vftest.exe \
                video.exe wmftest.exe wm_test.exe

dosonly:        hw_mem.exe int10.exe

os2only:        dll-all c16 far16.exe eatest.exe emxaout1.exe \
                fork.exe idle.exe kbd.exe msgtest os2test.exe pm2.exe \
                pipe.exe popen.exe read_kbd.exe select.exe \
                showmem1.exe threads.exe thunk.exe tl1.exe \
                vio.exe write1.exe sockets

c16:            c16.dll c16test1.exe c16test2.exe

dll-all:        dll1 dll2 dll3 dll4 dll5 dll6

dll1:           dlltest1.exe testdll1.dll

dll2:           dlltest2.exe testdll2.dll

dll3:           dlltest3.exe testdll3.dll

dll4:           dlltest4.exe testdll4.dll

dll5:           dlltest5.exe testdll5.dll

dll6:           dlltest6.exe testdll6.dll

dll7:           dlltest7.exe testdll7.dll

sockets:        impsockh.exe poorteln.exe sockecho.exe

#
# Make dll3 last as it requires OS/2
#
plusplus:       hello.exe stdio.exe test1.exe test2.exe dll3

msgtest:        msgtest.exe msgtest.msg

clean:
	-del *.o $(DELOPT)
	-del *.exe $(DELOPT)
	-del *.dll $(DELOPT)
	-del *.obj $(DELOPT)
	-del *.map $(DELOPT)
	-del *.msg $(DELOPT)
	-del *.lib $(DELOPT)
	-del coretest $(DELOPT)
	-del coretest.cor $(DELOPT)
	-del gcvt.out $(DELOPT)
	-del inet.out $(DELOPT)
	-del math.out $(DELOPT)
	-del mktime.out $(DELOPT)
	-del scanf.out $(DELOPT)
	-del strptime.out $(DELOPT)
	-del pm2 $(DELOPT)
	-del pm2.res $(DELOPT)
	-del c16.a $(DELOPT)
	-del strtol.t1 $(DELOPT)
	-del strtol.t2 $(DELOPT)
	-del strtol.t3 $(DELOPT)
	-del strtol.t4 $(DELOPT)
	-del testdll3.def $(DELOPT)
	-del testdll7.def $(DELOPT)
	-del printf.out $(DELOPT)
	-del telltext.tmp $(DELOPT)

access.o:       access.c $(I)stdio.h $(I)io.h $(I)string.h $(I)stdlib.h
alarm.o:        alarm.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(SIGNAL)
args.o:         args.c $(I)stdio.h $(I)stdlib.h
bsdtest.o:      bsdtest.c $(I)stdio.h $(I)stdlib.h
conv.o:         conv.c $(I)stdio.h $(I)stdlib.h $(I)string.h
coretest.o:     coretest.c $(I)stdio.h $(I)stdlib.h $(I)io.h $(FCNTL) \
                $(S)types.h $(S)stat.h $(SIGNAL) $(I)string.h
ctypetst.o:     ctypetst.c $(I)stdio.h $(I)string.h $(I)ctype.h
debug.o:        debug.c $(I)stdio.h $(I)string.h $(I)process.h \
                $(S)ptrace.h $(S)reg.h $(S)user.h $(I)stdlib.h $(S)wait.h
divtest.o:      divtest.c $(I)stdio.h $(I)stdlib.h
dttest.o:       dttest.c $(I)stdio.h $(I)stdlib.h $(I)getopt.h $(I)time.h \
                $(S)dirtree.h $(S)param.h
exec.o:         exec.c $(I)stdio.h $(I)string.h $(I)process.h $(SIGNAL) \
                $(S)wait.h
explode.o:      explode.c $(I)stdio.h $(I)stdlib.h
far16.o:        far16.c $(I)stdio.h $(I)os2.h $(I)os2thunk.h
float.o:        float.c $(I)stdio.h $(I)float.h
fork.o:         fork.c $(I)process.h $(I)stdio.h $(I)string.h $(I)stdlib.h \
                $(I)getopt.h $(SIGNAL) $(I)time.h $(S)wait.h
ftwtest.o:      ftwtest.c $(I)stdio.h $(S)types.h $(S)stat.h \
                $(I)ftw.h
fullpath.o:     fullpath.c $(I)stdio.h $(I)stdlib.h $(S)param.h \
                $(I)getopt.h
hello.o:        hello.cc $(IP)iostream.h
hexdump.o:      hexdump.c $(I)stdio.h $(I)stdlib.h $(I)io.h $(FCNTL) \
                $(S)ioctl.h
hw_io.o:        hw_io.c $(I)stdio.h $(I)stdlib.h $(S)hw.h $(I)string.h
hw_mem.o:       hw_mem.c $(I)stdio.h $(I)stdlib.h $(S)hw.h $(I)memory.h \
                $(I)io.h
idle.o:         idle.c $(I)stdio.h $(I)process.h $(I)string.h $(I)os2emx.h \
                $(I)stdlib.h
eatest.o:       eatest.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)getopt.h \
                $(I)io.h $(S)ea.h
mdecho.o:       mdecho.c $(I)stdio.h $(S)moddef.h
memory.o:       memory.c $(I)stdio.h $(I)string.h
memtest.o:      memtest.c $(S)emx.h $(I)stdio.h $(I)stdlib.h \
                $(I)string.h $(I)io.h
mftest.o:       mftest.c $(I)stdio.h $(I)stdlib.h $(I)getopt.h $(ERRNO)
nls.o:          nls.c $(S)nls.h $(I)stdio.h $(I)string.h $(I)stdlib.h
os2test.o:      os2test.c $(I)stdio.h $(I)string.h $(I)os2emx.h
pid.o:          pid.c $(I)stdio.h $(I)process.h
pipe.o:         pipe.c $(I)stdio.h $(I)io.h $(I)process.h $(I)unistd.h \
                $(I)stdlib.h $(FCNTL) $(I)string.h $(SIGNAL) $(S)wait.h
pm2.o:          pm2.c pm2.h $(I)stdio.h $(I)os2emx.h
popen.o:        popen.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)getopt.h \
                $(S)wait.h
printf0.o:      printf0.c $(I)stdio.h
retcode.o:      retcode.c $(I)stdlib.h
rndheap.o:      rndheap.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)malloc.h \
                $(I)getopt.h $(SIGNAL) $(ERRNO)
sbrktest.o:     sbrktest.c $(I)stdio.h $(I)stdlib.h $(I)string.h
select.o:       select.c $(I)stdio.h $(I)io.h $(I)process.h $(I)unistd.h \
                $(I)stdlib.h $(FCNTL) $(I)string.h $(SIGNAL) $(S)ioctl.h \
                $(S)types.h $(S)time.h $(S)wait.h
showmem1.o:     showmem1.c $(I)stdio.h $(I)stdlib.h
sig2.o:         sig2.c $(I)stdio.h $(I)stdlib.h $(SIGNAL) $(I)setjmp.h \
                $(I)process.h
sig3.o:         sig3.c $(I)stdio.h $(I)stdlib.h $(SIGNAL) $(I)setjmp.h
sig4.o:         sig4.c $(I)stdio.h $(I)stdlib.h $(SIGNAL)
sig6.o:         sig6.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(SIGNAL) \
                $(I)setjmp.h $(I)float.h
sigsegv.o:      sigsegv.c $(I)stdio.h $(I)stdlib.h $(SIGNAL)
splitarg.o:     splitarg.c $(I)stdio.h $(I)stdlib.h $(I)string.h
stack.o:        stack.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(SIGNAL) \
                $(I)alloca.h
stdio.o:        stdio.cc $(I)stdio.h $(IP)iostream.h
stdiotst.o:     stdiotst.c $(I)stdio.h $(I)stdlib.h
strftime.o:     strftime.c $(I)stdio.h $(I)time.h $(I)locale.h $(I)string.h \
                $(I)stdlib.h
system.o:       system.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)process.h
swaptest.o:     swaptest.c $(I)stdio.h $(I)stdlib.h $(I)io.h
termio.o:       termio.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)io.h \
                $(ERRNO) $(SIGNAL) $(I)process.h $(I)setjmp.h $(I)ctype.h \
                $(S)types.h $(S)time.h $(S)termio.h $(I)fcntl.h \
                $(S)ioctl.h $(I)termios.h
test1.o:        test1.cc $(I)stdio.h $(IP)iostream.h
test2.o:        test2.cc $(IP)iostream.h
timetest.o:     timetest.c $(I)stdio.h $(I)time.h $(S)types.h \
                $(S)stat.h $(I)io.h $(I)stdlib.h $(I)ctype.h $(I)string.h \
                $(I)getopt.h
tmpnam.o:       tmpnam.c $(I)stdio.h
trunc.o:        trunc.c $(I)stdio.h $(I)stdlib.h $(I)io.h $(I)getopt.h \
                $(I)fcntl.h
uname.o:        uname.c $(I)stdio.h $(S)utsname.h
version.o:      version.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(S)emx.h
video.o:        video.c $(I)stdio.h $(I)stdlib.h $(S)video.h
int10.o:        int10.c $(I)stdio.h $(I)stdlib.h $(I)dos.h
wm_test.o:      wm_test.c $(I)stdio.h $(I)stdlib.h $(I)string.h \
                $(S)video.h $(S)winmgr.h $(S)kbdscan.h

errno.exe:      errno.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(ERRNO) $(LIBS)
	$(CC) errno.c

longlong.o:     longlong.c $(I)stdio.h $(I)stdlib.h
	$(CC) -c longlong.c

msgtest.obj:    msgtest.c
	gcc -c msgtest.c -Zomf

scanf0.o:       scanf0.c $(I)stdio.h
	$(CC) -c scanf0.c

dupexec.exe:    dupexec.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)unistd.h \
                $(FCNTL) $(PROCESS) $(LIBS)
	$(CC) dupexec.c
	emxbind -aq dupexec -p

tl1.exe:        tl1.c $(S)emx.h $(I)stdio.h $(I)stdlib.h $(I)process.h \
                $(I)io.h $(LIBSMT)
	$(CC) -Zmts tl1.c

write1.exe:     write1.c $(S)emx.h $(I)stdio.h $(I)stdlib.h $(I)string.h \
                $(FCNTL) $(S)types.h $(S)stat.h $(I)unistd.h $(I)io.h \
                $(ERRNO) $(I)getopt.h $(LIBS)
	$(CC) write1.c

#
# Sockets
#
impsockh.exe: impsockh.c $(I)stdio.h $(I)stdlib.h $(I)unistd.h \
              $(S)types.h $(S)socket.h $(LIBS) $(L)socket.a
	$(CC) impsockh.c -lsocket

poorteln.exe: poorteln.c $(I)stdio.h $(I)stdlib.h $(I)process.h $(I)string.h \
              $(I)io.h $(I)unistd.h $(ERRNO) $(FCNTL) \
              $(S)types.h $(S)socket.h $(S)ioctl.h $(I)netinet/in.h \
              $(I)arpa/inet.h $(I)netdb.h easysock.o $(LIBSMT) $(L)socket.a
	$(CC) -Zmt poorteln.c easysock.o -lsocket

sockecho.exe: sockecho.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)signal.h \
              $(FCNTL) $(I)unistd.h $(I)getopt.h $(I)io.h $(ERRNO) \
              $(S)types.h $(S)wait.h $(S)socket.h $(S)ioctl.h \
              $(I)netinet/in.h $(I)arpa/inet.h $(I)netdb.h \
              $(LIBS) $(L)socket.a
	$(CC) -DACCEPT_BROKEN_EINTR sockecho.c -lsocket

#
# Regression tests running automatically
#
# Note that some of the tests need a `diff' tool
#
# Make seektext and telltext last as those tests are slow
#
reg-base-auto:  ctrlz1 fnmatch gcvt math mktime pack printf rwv scanf \
		strptime strtol utf2 sig5 swab ungetc seektext telltext

#
# Regression test for tell(), lseek(), eof(), fseek(), and ftell()
# for text-mode files ending with Ctrl-Z
#
ctrlz1:	ctrlz1.exe ctrlz1.inp
	ctrlz1

ctrlz1.exe:	ctrlz1.c $(I)stdio.h $(I)stdlib.h $(I)io.h $(FCNTL) \
		$(S)types.h $(S)stat.h $(LIBS)
	$(CC) ctrlz1.c

#
# Regression test for strtol() and strtoul()
#
strtol:         strtol.exe strtol.in1 strtol.in2 strtol.in3 strtol.in4 \
		strtol.ok1 strtol.ok2 strtol.ok3 strtol.ok4
	strtol s 0 <strtol.in1 >strtol.t1
	strtol u 0 <strtol.in2 >strtol.t2
	strtol s 1 <strtol.in3 >strtol.t3
	strtol u 2 <strtol.in4 >strtol.t4
	diff strtol.ok1 strtol.t1
	diff strtol.ok2 strtol.t2
	diff strtol.ok3 strtol.t3
	diff strtol.ok4 strtol.t4

strtol.exe:     strtol.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)errno.h \
                $(LIBS)
	$(CC) strtol.c

#
# Regression test for printf()
#
printf: printf.exe
	printf >printf.out
	diff printf.out printf.ok

# Note: Don't use -Wall as this implies -Wformat
printf.exe:     printf.c $(I)stdio.h $(LIBS)
	$(CC0) -g printf.c

#
# Regression test for scanf()
#
scanf:  scanf.exe
	scanf >scanf.out
	diff scanf.out scanf.ok

# Note: Don't use -Wall as this implies -Wformat
scanf.exe:      scanf.c $(I)stdio.h $(I)string.h $(LIBS)
	$(CC0) -g scanf.c

#
# Regression test for fnmatch()
#
fnmatch: fnmtest.exe fnmtest.inp
	fnmtest -r <fnmtest.inp

fnmtest.exe: fnmtest.c $(I)stdio.h $(I)stdlib.h $(I)string.h \
                $(I)fnmatch.h $(LIBS)
	$(CC) fnmtest.c

#
# Regression test for gcvt()
#
gcvt: gcvt.exe gcvt.inp gcvt.ok
	gcvt <gcvt.inp >gcvt.out
	diff gcvt.ok gcvt.out

gcvt.exe: gcvt.c $(I)stdio.h $(I)stdlib.h $(I)math.h $(LIBS)
	$(CC) gcvt.c

#
# Regression test for math functions
#
math: math.exe math.inp math.ok
	math <math.inp >math.out
	diff math.ok math.out

math.exe:       math.c $(I)stdio.h $(I)stdlib.h $(I)math.h $(LIBS)
	$(CC) math.c

#
# Regression test for mktime()
#
mktime: mktime.exe mktime.inp mktime.ok
	mktime -u <mktime.inp >mktime.out
	diff mktime.out mktime.ok

mktime.exe: mktime.c $(I)stdio.h $(I)stdlib.h $(I)time.h $(LIBS)
	$(CC) mktime.c

#
# Regression test for #pragma pack()
#
pack:   pack.exe
	pack

pack.exe:       pack.c $(I)stdio.h $(LIBS)
	$(CC) pack.c

#
# Regression test for readv() and writev()
#
rwv:	rwv.exe
	rwv

rwv.exe:	rwv.c $(I)stdio.h $(I)string.h $(I)sys/types.h $(I)sys/stat.h \
		$(I)sys/uio.h $(I)unistd.h $(FCNTL) $(LIBS)
	$(CC) rwv.c

#
# Regression test for fseek() on text streams
#
seektext: seektext.exe testtext.cr testtext.lf
	@echo Don't panic! This test may take several minutes
	seektext testtext.cr
	seektext testtext.lf

seektext.exe:   seektext.c $(I)stdio.h $(I)stdlib.h $(LIBS) $(LIBBSD)
	$(CC) seektext.c -lbsd

#
# Regression test for the return value of signal()
#
sig5:   sig5.exe
	sig5

sig5.exe:       sig5.c $(I)stdio.h $(SIGNAL) $(LIBS)
	$(CC) sig5.c

#
# Regression test for swab()
#
swab: swab.exe
	swab

swab.exe:	swab.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(LIBS)
	$(CC) swab.c

#
# Regression test for strptime()
#
strptime: strptime.exe strptime.inp strptime.ok
	strptime <strptime.inp >strptime.out
	diff strptime.ok strptime.out

strptime.exe: strptime.c $(I)stdio.h $(I)string.h $(I)time.h $(LIBS)
	$(CC) strptime.c

#
# Regression test for ftell() on text streams
#
telltext: telltext.exe testtext.cr testtext.lf
	@echo Don't panic! This test may take several minutes
	telltext testtext.cr telltext.tmp
	telltext -u testtext.lf telltext.tmp
	-del telltext.tmp

telltext.exe:   telltext.c $(I)stdio.h $(I)stdlib.h $(LIBS)
	$(CC) telltext.c

#
# Regression test for ungetc()
#
ungetc: ungetc.exe ungetc.inp
	ungetc -sa
	ungetc -b255 -u1 -sa
	ungetc -b3 -u1 -sa -v3
	ungetc -b7 -u1 -sa -v7
	ungetc -b13 -u1 -sa -v13
	@echo Don't panic! The following tests may take several minutes
	ungetc -sa -r10000
	ungetc -b255 -u1 -sa -r10000
	ungetc -b7 -u1 -sa -r10000 -v7

ungetc.exe: ungetc.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(LIBS)
	$(CC) ungetc.c

#
# Regression test for mblen(), mbtowc(), wctomb(), mbstowcs(), and wcstombs()
#
utf2: utf2.exe
	utf2 -c
	utf2 -s

utf2.exe:       utf2.c $(S)emx.h $(I)stdio.h $(I)stdlib.h $(I)string.h \
                $(I)limits.h $(LIBS) $(LIBBSD)
	$(CC) utf2.c -lbsd

#
# Regression tests running automatically, TCP/IP required
#
# Note that some of the tests need a `diff' tool
#

reg-tcpip-auto: byteord hreloc inet select2

#
# Regression test for htonl(), htons(), ntohl(), and ntohs()
#
byteord: byteord.exe
	byteord

byteord.exe: byteord.c $(I)stdio.h $(S)types.h $(I)netinet/in.h \
             $(LIBS) $(L)socket.a
	$(CC) byteord.c -lsocket

#
# Regression test for handle relocation caused by socket()
#
hreloc: hreloc.exe
	hreloc

hreloc.exe: hreloc.c $(S)emx.h $(I)stdio.h $(I)string.h $(I)unistd.h \
            $(ERRNO) $(S)fcntl.h $(S)types.h $(S)stat.h $(S)socket.h \
            $(LIBS) $(L)socket.a
	$(CC) hreloc.c -lsocket

#
# Regression test for inet_addr(), inet_network(), and inet_ntoa()
#
inet: inet.exe inet.inp inet.ok
	inet <inet.inp >inet.out
	diff inet.out inet.ok

inet.exe: inet.c $(I)stdio.h $(I)string.h $(S)types.h $(I)netinet/in.h \
          $(I)arpa/inet.h $(LIBS) $(L)socket.a
	$(CC) inet.c -lsocket

#
# Regression test for writefds vs. readfds of select()
#
select2: select2.exe
	select2 -t $(UNIXHOST) daytime

# Note: compile with -Zmt as easysock.o is compiled with -Zmt
select2.exe:	select2.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)io.h \
		$(S)types.h $(S)socket.h $(I)netinet/in.h $(I)arpa/inet.h \
		easysock.h easysock.o $(LIBS) $(L)socket.a
	$(CC) -Zmt select2.c easysock.o -lsocket

#
# Regression tests where a human must check the output
#
reg-base-look: sig1 sig7 sig8 dup mtff

sig1:	sig1.exe
	-sig1 1
	-sig1 16

sig1.exe:	sig1.c $(I)stdio.h $(SIGNAL) $(LIBS)
	$(CC) sig1.c

sig7:	sig7.exe
	-sig7

sig7.exe:       sig7.c $(I)stdio.h $(I)stdlib.h $(SIGNAL) $(I)setjmp.h $(LIBS)
	$(CC) sig7.c

sig8:	sig8.exe
	-sig8

sig8.exe:       sig8.c $(I)stdio.h $(I)stdlib.h $(SIGNAL) $(LIBS)
	$(CC) sig8.c -Zsysv-signals

dup:	dup.exe
	dup

dup.exe:        dup.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)unistd.h \
                $(FCNTL) $(ERRNO) $(LIBS)
	$(CC) dup.c

mtff:	mtff.exe
	@echo This should list 7 files matching *.h
	mtff -p 2 *.h *.xyz

mtff.exe:	mtff.c $(I)stdio.h $(I)stdlib.h $(I)stddef.h $(I)os2emx.h \
		$(S)emx.h $(LIBSMT)
	$(CC) -Zmt mtff.c

#
# Regression tests where a human must check the output, TCP/IP required
#

reg-tcpip-look: mtsock sockioct

mtsock:	mtsock.exe
	mtsock >nul

mtsock.exe:	mtsock.c $(I)stdio.h $(I)stdlib.h $(I)stddef.h $(I)unistd.h \
		$(FCNTL) $(I)io.h $(S)types.h $(S)socket.h \
		$(LIBSMT) $(L)socket.a
	$(CC) -Zmt mtsock.c -lsocket

sockioct: sockioct.exe
	sockioct -c

sockioct.exe: sockioct.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)unistd.h \
              $(S)types.h $(S)socket.h $(S)ioctl.h $(I)net/if.h \
              $(I)netinet/in.h $(I)arpa/inet.h $(I)netdb.h easysock.h \
              easysock.o $(LIBS) $(L)socket.a
	$(CC) -Zmt sockioct.c easysock.o -lsocket

#
# _cdecl thunks
#
# Required tools: Microsoft C 6.00A and MASM 6.00A
#
c16test1.exe: c16test1.o c16.a
	$(CC) -o c16test1.exe c16test1.o c16.a

c16test2.exe: c16test2.o c16.a
	$(CC) -o c16test2.exe c16test2.o c16.a

c16test1.o: c16test1.c
	$(CC) -c c16test1.c

c16test2.o: c16test2.c
	$(CC) -c c16test2.c

c16.dll: c16init.obj c16.obj c16.def
	link c16init c16 /align:16 /nod,c16.dll,nul,,c16.def

c16init.obj: c16init.asm
	@echo MASM 6.00A required!
	ml -c -W3 c16init.asm

c16.obj: c16.c
	@echo Microsoft C 6.0 required!
	cl -c -Lp -Alfu -G2s -W4 c16.c

c16.a: c16.imp
	emximp -o c16.a c16.imp

#
# mkmsgf comes with the "IBM Developer's Toolkit for OS/2 2.0"
#
msgtest.msg:    msgtest.txt
	@echo mkmsgf required!
	mkmsgf msgtest.txt msgtest.msg

#
# dll1: DLL without runtime environment
#
testdll1.dll: testdll1.c testdll1.def $(LIBS) $(LIBOS2)
	$(CC) -Zdll -Zomf -Zno-rte -s testdll1.c testdll1.def

dlltest1.exe:   dlltest1.c imp1.o
	$(CC) dlltest1.c imp1.o

imp1.o:         testdll1.imp
	emximp -a testdll1.imp

#
# dll2: DLL without runtime environment; test shared/instance data
#
CFLAGS_TESTDLL2 = -Zdll -Zomf -Zno-rte

testdll2.obj: testdll2.c
	$(CC) $(CFLAGS_TESTDLL2) -c testdll2.c

private.obj: private.c
	$(CC) -c private.c
	emxomf -DPRIV private.o

testdll2.dll: testdll2.obj private.obj testdll2.def
	$(CC) $(CFLAGS_TESTDLL2) testdll2.obj private.obj testdll2.def

testdll2.lib: testdll2.def
	emximp -o testdll2.lib testdll2.def

dlltest2.exe: dlltest2.c testdll2.lib
	$(CC) -Zomf dlltest2.c testdll2.lib

#
# dll3: DLL using C runtime DLL; test constructors/destructors in DLL
#
CFLAGS_TESTDLL3 = -Zdll -Zomf -Zmt -Zcrtdll

testdll3.obj: testdll3.cc testdll3.h
	$(CC) -c $(CFLAGS_TESTDLL3) testdll3.cc

testdll3.def: testdll3.df testdll3.obj
	copy testdll3.df testdll3.def
	emxexp testdll3.obj >>testdll3.def

testdll3.dll: testdll3.obj testdll3.def
	$(CC) $(CFLAGS_TESTDLL3) testdll3.obj testdll3.def -lwrap

testdll3.lib: testdll3.def
	emximp -o testdll3.lib testdll3.def

dlltest3.exe: dlltest3.cc testdll3.h testdll3.lib
	$(CC) -Zomf -Zmt -Zcrtdll dlltest3.cc testdll3.lib

#
# dll4: partial custom C runtime DLL
#
IMPORT_OBJ = $(L)appinit.obj $(L)dllinit.obj $(L)ctor.obj $(L)dtor.obj

testdll4.dll: testdll4.c testdll4.h testdll4.def
	$(CC) -Zomf -Zdll -Zmt testdll4.c testdll4.def

testdll4.lib: testdll4.def $(IMPORT_OBJ)
	emximp -o testdll4.lib testdll4.def
	emxomfar r testdll4.lib $(IMPORT_OBJ)

dlltest4.obj: dlltest4.c testdll4.h
	$(CC) -Zomf -Zmt -Zcrtdll -c dlltest4.c

dlltest4.exe: dlltest4.obj testdll4.lib
	$(CC) -Zomf -Zmt -Zcrtdll=testdll4 -L. dlltest4.c

#
# dll5: Stand-alone DLL; test RTE initialization
#
testdll5.dll: testdll5.c testdll5.h testdll5.def
	$(CC) -Zdll -Zomf -Zso -Zsys testdll5.c testdll5.def

dlltest5.exe: dlltest5.c testdll5.h testdll5.lib
	$(CC) dlltest5.c testdll5.lib -Zomf

testdll5.lib: testdll5.def
	emximp -o testdll5.lib testdll5.def

#
# dll6: single-thread custom C runtime DLL, with _DLL_InitTerm()
#
testdll6.dll: testdll6.c testdll6.h testdll6.def
	$(CC) -Zomf -Zdll testdll6.c testdll6.def

testdll6.lib: testdll6.def $(IMPORT_OBJ)
	emximp -o testdll6.lib testdll6.def
	emxomfar r testdll6.lib $(IMPORT_OBJ)

dlltest6.exe: dlltest6.c testdll6.h testdll6.lib
	$(CC) -Zomf dlltest6.c -Zcrtdll=testdll6

#
# dll7: complete custom C runtime DLL which does not use emx.dll (-Zsys)
#
# Required tools: sed
#
testdll7.dll: testdll7.c testdll7.h testdll7.def
	$(CC) -Zomf -Zmt -Zsys -Zdll testdll7.c testdll7.def

testdll7.def: testdll7.df $(LL)cdll.def
	copy testdll7.df testdll7.def
	sed -e "1,/EXPORTS/d" -e "/{EMX}/d" -e "/{ST}/d" <$(LL)cdll.def >>testdll7.def

testdll7.lib: testdll7.def $(IMPORT_OBJ)
	emximp -o testdll7.lib testdll7.def
	emxomfar r testdll7.lib $(IMPORT_OBJ)

dlltest7.obj: dlltest7.c testdll7.h
	$(CC) -Zomf -Zmt -Zcrtdll -c dlltest7.c

dlltest7.exe: dlltest7.obj testdll7.lib
	$(CC) -Zomf -Zmt -Zcrtdll=testdll7 -L. dlltest7.c

#
# Test emxaout
#
# Required tools: MASM 6.00A
#
emxaout1.exe: emxaout1.asm
	@echo MASM 6.00A required!
	ml -c emxaout1.asm
	emxaout emxaout1.obj
	gcc -Zomf -o emxaout1.exe emxaout1.obj

#
# Modules used by multiple programs
#
showmem.o:      showmem.c $(I)stdio.h $(I)stdlib.h $(I)os2emx.h

easysock.o:	easysock.c $(I)stdio.h $(I)stdlib.h $(I)string.h $(I)ctype.h \
		$(S)types.h $(S)socket.h $(I)netinet/in.h $(I)arpa/inet.h \
		$(I)netdb.h easysock.h
	$(CC) -Zmt -c easysock.c

#
#
#

access.exe:     access.o $(LIBS)
	$(CC) -o access.exe access.o

alarm.exe:      alarm.o $(LIBS)
	$(CC) -o alarm.exe alarm.o

args.exe:       args.o $(LIBS)
	$(CC) -o args.exe args.o

bsdtest.exe:    bsdtest.o $(LIBS) $(LIBBSD)
	$(CC) -o bsdtest.exe bsdtest.o -lbsd

conv.exe:       conv.o $(LIBS)
	$(CC) -o conv.exe conv.o

coretest:       coretest.o $(LIBS)
	$(CC) -o coretest coretest.o

coretest.exe:   coretest
	emxbind $(B)emxl coretest

coretest.cor:   coretest.exe
	coretest

coretst2.exe:   coretest coretest.cor
	emxbind -ccoretest.cor $(B)emxl coretest coretst2

ctypetst.exe:   ctypetst.o $(LIBS)
	$(CC) -o ctypetst.exe ctypetst.o

debug.exe:      debug.o $(LIBS)
	$(CC) -o debug.exe debug.o

divtest.exe:    divtest.o $(LIBS)
	$(CC) -o divtest.exe divtest.o

dttest.exe:     dttest.o $(LIBS)
	$(CC) -o dttest.exe dttest.o

exec.exe:       exec.o $(LIBS)
	$(CC) -o exec.exe exec.o
	emxbind -aq exec -p

explode.exe:    explode.o $(LIBS)
	$(CC) -o explode.exe explode.o

far16.exe:      far16.o $(LIBS) $(LIBOS2)
	$(CC) -o far16.exe far16.o

float.exe:      float.o $(LIBS)
	$(CC) -o float.exe float.o

fork.exe:       fork.o $(LIBS)
	$(CC) -o fork.exe fork.o

ftwtest.exe:    ftwtest.o $(LIBS)
	$(CC) -o ftwtest.exe ftwtest.o

fullpath.exe:   fullpath.o $(LIBS)
	$(CC) -o fullpath.exe fullpath.o

hello.exe:      hello.o $(LIBS) $(LIBP)
	$(CC) -o hello.exe hello.o -liostream

hexdump.exe:    hexdump.o $(LIBS)
	$(CC) -o hexdump.exe hexdump.o

hw_io.exe:      hw_io.o $(LIBS)
	$(CC) -o hw_io.exe hw_io.o
	emxbind -aq hw_io -ai

hw_mem.exe:     hw_mem.o $(LIBS)
	$(CC) -o hw_mem.exe hw_mem.o
	emxbind -aq hw_mem -am -p

idle.exe:       idle.o $(LIBS) $(LIBOS2)
	$(CC) -o idle.exe idle.o

kbd.exe:        kbd.c $(LIBS) $(LIBOS2)
	$(CC) -o kbd.exe kbd.c -Zomf -Zsys

eatest.exe:     eatest.o $(LIBS) $(LIBOS2)
	$(CC) -o eatest.exe eatest.o

longlong.exe:   longlong.o $(LIBS)
	$(CC) -o longlong.exe longlong.o

mdecho.exe:     mdecho.o $(LIBS) $(L)moddef.a
	$(CC) -o mdecho.exe mdecho.o -lmoddef

memory.exe:     memory.o $(LIBS)
	$(CC) -o memory.exe memory.o

memtest.exe:    memtest.o $(LIBS)
	$(CC) -o memtest.exe memtest.o

mftest.exe:      mftest.o $(LIBS)
	$(CC) -o mftest.exe mftest.o

msgtest.exe:    msgtest.obj
	$(CC) -o msgtest.exe msgtest.obj -Zomf

nls.exe:        nls.o $(LIBS)
	$(CC) -o nls.exe nls.o

os2test.exe:    os2test.o $(LIBS) $(LIBOS2)
	$(CC) -o os2test.exe os2test.o

pid.exe:        pid.o $(LIBS)
	$(CC) -o pid.exe pid.o

pipe.exe:       pipe.o $(LIBS)
	$(CC) -o pipe.exe pipe.o

pm2.res:        pm2.rc pm2.h
	rc -r -i \emx\include pm2.rc

pm2:            pm2.o $(LIBS) $(LIBOS2)
	$(CC) -o pm2 pm2.o

pm2.exe:        pm2 pm2.res
	emxbind -bpq -rpm2.res /emx/bin/emxl pm2

popen.exe:      popen.o $(LIBS)
	$(CC) -o popen.exe popen.o

printf0.exe:    printf0.o $(LIBS)
	$(CC) -o printf0.exe printf0.o

read_kbd.exe:   read_kbd.c
	$(CC) -O -o read_kbd.exe read_kbd.c -Zomf -Zsys

retcode.exe:    retcode.o $(LIBS)
	$(CC) -o retcode.exe retcode.o

rndheap.exe:    rndheap.o $(LIBS)
	$(CC) -o rndheap.exe rndheap.o

sbrktest.exe:   sbrktest.o showmem.o $(LIBS)
	$(CC) -o sbrktest.exe sbrktest.o showmem.o

scanf0.exe:     scanf0.o $(LIBS)
	$(CC) -o scanf0.exe scanf0.o

select.exe:     select.o $(LIBS)
	$(CC) -o select.exe select.o

showmem1.exe:    showmem1.o showmem.o $(LIBS) $(LIBOS2)
	$(CC) -o showmem1.exe showmem1.o showmem.o

sig2.exe:       sig2.o $(LIBS)
	$(CC) -o sig2.exe sig2.o

sig3.exe:       sig3.o $(LIBS)
	$(CC) -o sig3.exe sig3.o

sig4.exe:       sig4.o $(LIBS)
	$(CC) -o sig4.exe sig4.o

sig6.exe:       sig6.o $(LIBS)
	$(CC) -o sig6.exe sig6.o

sigsegv.exe:    sigsegv.o $(LIBS)
	$(CC) -o sigsegv.exe sigsegv.o

splitarg.exe:   splitarg.o $(LIBS)
	$(CC) -o splitarg.exe splitarg.o

stack.exe:      stack.o $(LIBS)
	$(CC) -o stack.exe stack.o

stdio.exe:      stdio.o $(LIBS) $(LIBP)
	$(CC) -o stdio.exe stdio.o -liostream

stdiotst.exe:   stdiotst.o $(LIBS)
	$(CC) -o stdiotst.exe stdiotst.o

strftime.exe:   strftime.o $(LIBS)
	$(CC) -o strftime.exe strftime.o

system.exe:     system.o $(LIBS)
	$(CC) -o system.exe system.o
	emxbind -aq system -p

swaptest.exe:   swaptest.o $(LIBS)
	$(CC) -o swaptest.exe swaptest.o

termio.exe:     termio.o $(LIBS)
	$(CC) -o termio.exe termio.o

test1.exe:      test1.o $(LIBS) $(LIBP)
	$(CC) -o test1.exe test1.o -liostream

test2.exe:      test2.o $(LIBS) $(LIBP)
	$(CC) -o test2.exe test2.o -liostream

threads.exe:    threads.c $(I)stdio.h $(I)stdlib.h $(I)string.h \
                $(I)ctype.h $(I)getopt.h $(I)os2emx.h
	$(CC) -o threads.exe threads.c -Zomf -Zmts

thunk.exe:      thunk.c $(I)os2thunk.h
	$(CC) -o thunk.exe thunk.c

timetest.exe:   timetest.o $(LIBS)
	$(CC) -o timetest.exe timetest.o

tmpnam.exe:     tmpnam.o $(LIBS)
	$(CC) -o tmpnam.exe tmpnam.o

trunc.exe:      trunc.o $(LIBS)
	$(CC) -o trunc.exe trunc.o

uname.exe:      uname.o $(LIBS)
	$(CC) -o uname.exe uname.o

version.exe:    version.o $(LIBS)
	$(CC) -o version.exe version.o

vftest.exe:     vftest.o $(LIBS) $(L)video.a
	$(CC) -o vftest.exe vftest.o -lvideo
	emxbind -aq vftest -acm

video.exe:      video.o $(LIBS) $(L)video.a
	$(CC) -o video.exe video.o -lvideo
	emxbind -aq video -acm

vio.exe:        vio.c
	$(CC) -O -o vio.exe vio.c -Zomf -Zmtd

int10.exe:      int10.o $(LIBS)
	$(CC) -o int10.exe int10.o
	emxbind -aq int10 -ac

wmftest.exe:    wmftest.o $(LIBS) $(L)video.a
	$(CC) -o wmftest.exe wmftest.o -lvideo
	emxbind -aq wmftest -acm

wm_test.exe:    wm_test.o $(LIBS) $(L)video.a
	$(CC) -o wm_test.exe wm_test.o -lvideo
	emxbind -aq wm_test -acm
