# $Header: /cvsroot/posix2/posix2/libext/test/Makefile,v 1.3 2000/04/17 08:25:49 veit Exp $
# requires GNUmake    

# tools section
AR     = ar rc
AWK    = gawk
CC     = gcc
CP     = cp
DVIPS  = dvips
EMXEXP = emxexp
EMXIMP = emximp
EMXOMF = emxomf
IPFC   = ipfc
LATEX  = latex
LD     = gcc
LEX    = flex
LN     = cp
RANLIB = ar s
RC     = rc
RM     = rm -f
SED    = sed
TEX    = latex
YACC   = bison
CTAGS  = ctags

# flags section
DEBUG     = -g -O2 -mpentium -D_DEBUG -DDEBUG -DTHREAD_EXPERIMENTAL \
   -D_USE_HRTIMER_SYS -D_CPYFILE_FOR_SYMLINK -DDEBUG 

WFLAGS   = -Wall -W -Wmissing-prototypes -Wshadow -Wcast-align \
   -Wpointer-arith -Winline -Wmissing-declarations  \
   -Wstrict-prototypes -Wconversion
 
DEFINES  = -D__ST_MT_ERRNO__ -Zmt -DGNUFNS 
INCLUDE  = -I../include -I$(X11ROOT)/XFree86/include
CFLAGS  = $(DEFINES) $(DEBUG) $(WFLAGS) $(INCLUDE)

LIBRARY    = -L../libc -L$(X11ROOT)/XFree86/lib -lextensions
#-lsocket -lstdcpp
DEF          = EXE.DEF
DLLDEFFILE = 
DLLFLAGS   = -Zomf -Zmtd -Zdll $(DLLDEFFILE) 
LDFLAGS    =  $(CFLAGS) -Zmtd -Zbin-files -Zbsd-signals $(DEBUG) \
   $(DEF) $(LIBRARY) 

.SUFFIXES:
.SUFFIXES: .a .aux .c .cpp .cxx .C .def .dll .dvi .exe .hlp .inf .ipf \
           .lib .log .map .o .obj .rc .res .tex .toc
.PHONY: clean default distclean

default: all

all: test

run: test
	$(RM) core copy.dat *.tst dummy
	mmaptest
	itimertest 999
	-test_poll.exe 
	-dltest.exe
	testusleep
	testcpfile testcpfile.exe copy.dat
	cmp testcpfile.exe copy.dat
	cmp copy.dat symlnk.tst
	-testcpfile testcpfile.exe copy.dat
	statxtest
	popentst
	$(RM) copy.dat *.tst

test: itimertest.exe testusleep.exe testcpfile.exe dltest.exe \
 test_poll.exe dltest.exe mmaptest.exe statxtest.exe shmsts.exe \
 testshm2.exe popentst.exe 
# testshm.exe clntshm.exe forkshm.exe xtestshm.exe


itimertest.exe: itimertest.c ../extensions.a 
	$(CC) itimertest.c -o $@ $(LDFLAGS)

testusleep.exe: testusleep.c ../extensions.a 
	$(CC) testusleep.c -o $@ $(LDFLAGS)

testcpfile.exe: testcpfile.c ../extensions.a 
	$(CC) testcpfile.c -o $@ $(LDFLAGS)

test_poll.exe: test_poll.c ../extensions.a 
	$(CC) test_poll.c -o $@ $(LDFLAGS)  

dltest.exe: dt.c ../extensions.a sam.dll
	$(CC) dt.c -o $@ $(LDFLAGS)

mmaptest.exe: mmaptest.c ../extensions.a 
	$(CC) mmaptest.c -o $@ $(LDFLAGS)

statxtest.exe: statxtest.c ../extensions.a 
	$(CC) statxtest.c -o $@ $(LDFLAGS)

shmsts.exe: shmsts.c ../extensions.a 
	$(CC) shmsts.c -o $@ $(LDFLAGS)

testshm2.exe: testshm2.c ../extensions.a 
	$(CC) testshm2.c -o $@ $(LDFLAGS)

popentst.exe: popentst.c ../extensions.a 
	$(CC) popentst.c -o $@ $(LDFLAGS)

sam.dll: sam.obj sam.def
	$(CC) $^ -o $@ -s -Zdll -Zno-rte -Zomf
#	$(CC) $^ -o $@ -Zdll -Zomf # you may need this for more complex examples

#
# add dependencies here
#
# foo: bar
dt.o: ../include/dlfcn.h dt.c
statxtest.o: ../include/sys/statx.h statxtest.c
testcpfile.o: ../include/sys/unistdx.h testcpfile.c
test_poll.o: ../include/sys/unistdx.h test_poll.c
mmaptest.o: ../include/sys/unistdx.h mmaptest.c
testusleep.o: ../include/sys/unistdx.h testusleep.c

# Generic part: rules

%.a: %.def
	$(EMXIMP) -o $@ $<

%.c : %.l
	$(LEX) -o $@ $<

%.dll: %.lib %.def
	$(CC) -o $@ $< $(DLLFLAGS)

%.exe: %.obj
	$(CC) -Zomf -o $@ $^ $(LDFLAGS)

%.exe: %.o
	$(CC) -o $@ $^ $(LDFLAGS)

%.lib: %.a
	$(EMXOMF) $<

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

%.o : %.C
	$(CC) $(CFLAGS) -c $< -o $@

%.o : %.cpp
	$(CC) $(CFLAGS) -c $< -o $@

%.o : %.cxx
	$(CC) $(CFLAGS) -c $< -o $@

%.obj : %.c
	$(CC) $(CFLAGS) -Zomf -c $< -o $@

%.obj : %.C
	$(CC) $(CFLAGS) -Zomf -c $< -o $@

%.obj : %.cpp
	$(CC) $(CFLAGS) -Zomf -c $< -o $@

%.obj : %.cxx
	$(CC) $(CFLAGS) -Zomf -c $< -o $@

#
# not-programming related
#

%.dvi: %.tex
	$(TEX) $<

%.ps: %.dvi
	$(DVIPS) $<

#
# OS/2 specific targets
#
%.hlp: %.ipf
	$(IPFC) $<

%.inf: %.ipf
	$(IPFC) -i $<

%.res: %.rc
	$(RC) -r $<

#
# Common maintainance targets
#
clean:
	$(RM) *.o *.obj *.res *.aux *.log *.toc core *.a *.lib dummy exp \
 *.exe *.dll copy.dat *.tst mmaptest.tmp 

install:

tags:
	$(CTAGS) -R *

