# Generic Makefile template
# $Header: /cvsroot/posix2/posix2/libext/libc/Makefile,v 1.2 2000/03/24 08:52:08 veit Exp $
# programming parts    Alexander Mai
# requires GNUmake    Version 19990917

# tools section
AR     = ar rc
AWK    = gawk
CC     = gcc
CP     = cp
CTAGS  = ctags
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

INC = ../include/

# 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. -I$(INC) -I$(X11ROOT)/XFree86/include
CFLAGS  = $(DEFINES) $(DEBUG) $(WFLAGS) $(INCLUDE)

LIBRARY    = -L. -L$(X11ROOT)/XFree86/lib -lextensions
#-lsocket -lstdcpp

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

default: exp

all: exp tags

SRCS = errnox.c dlfcn.c grpx.c itimer.c poll.c statx.c timext.c strxtens.c \
 direntx.c msgx.c shmx.c

# Has to be adapted to the used suffix(es)
#STDIOBJS = stdiox/fgetln.o
STDOBJS  = stdlibx/rand48.o stdlibx/random.o stdlibx/heapsort.o \
 stdlibx/rev.o stdlibx/radixsort.o stdlibx/daemon.o
UNIOBJS  = unistdx/symlink.o unistdx/stubs.o unistdx/sync.o \
 unistdx/param.o unistdx/usleep.o

OBJS     = $(SRCS:.c=.o) $(STDIOBJS) $(STDOBJS) $(UNIOBJS) mman/mm.o

sub:
#	cd stdiox && $(MAKE) all
	cd stdlibx && $(MAKE) all
	cd unistdx && $(MAKE) all
	cd mman && $(MAKE) all

extensions.a: sub $(OBJS) 
	$(RM) $@ 
	$(AR) $@ $(OBJS) 
	$(RANLIB) $@
	$(EMXOMF) -l -s -o extensions.lib $@

dl.a: dlfcn.o
	@-del $@
	$(AR) $@ $^
	$(RANLIB) $@
	$(EMXOMF) -l -s -o dl.lib $@

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
$(OBJS): $(INC)sys/errnox.h $(INC)sys/types.h
gnumath.o: $(INC)mathx.h
grpx.o: $(INC)sys/grpx.h $(INC)sys/unistdx.h 
itimer.o timext.o: $(INC)sys/timext.h $(INC)sys/unistdx.h 
poll.o: $(INC)sys/poll.h $(INC)sys/unistdx.h 
statx.o: $(INC)sys/statx.h $(INC)stringx.h $(INC)sys/unistdx.h 
strxtens.o: $(INC)stringx.h
dlfnc.o: $(INC)dlfcn.h $(INC)sys/unistdx.h 
msgx.o: $(INC)sys/ipc.h $(INC)sys/msg.h
shmx.o: $(INC)sys/ipc.h $(INC)sys/shm.h

# 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
#
exp: extensions.a
	$(EMXEXP) -u -o extensions.a > exp.cx

%.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
	cd stdlibx && $(MAKE) clean
	cd unistdx && $(MAKE) clean
	cd mman && $(MAKE) clean

veryclean: clean
	$(RM) *.exe *.dll copy.dat symlnk.tst exp.cx

install:

tags:
	$(CTAGS) *.c

# DO NOT DELETE THIS LINE -- make  depend  depends  on it.
