# $Header: /cvsroot/posix2/posix2/libext/Makefile,v 1.7 2000/05/02 07:47:59 veit Exp $
# requires GNUmake 

# tools section
AR     = ar r
CC     = gcc
CP     = cp
EMXEXP = emxexp -o20 -n
EMXIMP = emximp
EMXOMF = emxomf -s -l
EMXOMFAR = emxomfar r
RANLIB = ar s
RM     = rm -f

DEBUG     = -s -O2 -mpentium -D_DEBUG -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. -Iinclude -I$(X11ROOT)/XFree86/include
CFLAGS  = $(DEFINES) $(DEBUG) $(WFLAGS) $(INCLUDE)

DLLFLAGS  = -Zomf -Zmt -Zdll -Zcrtdll -s -Zlinker /M -Zlinker /NOI -Zlinker /EXEPACK:2
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

all: default

default: extensions.a exp libs

dll: 
	$(RM) libExt.DLL ext.def
	$(MAKE) libExt.DLL

extensions.a: sub
	$(AR) $@ libm/*.o
	$(AR) $@ libz/*.o
	$(RANLIB) $@


sub:
	cd libc && $(MAKE) all
	cd libc && cp *.a *.lib ..
	cd libm && $(MAKE) all
	cd libm && cp *.a *.lib ..
	cd libz && $(MAKE) all
	cd libz && cp *.a *.lib ..
	cd uni  && $(MAKE) all

test: extensions.a
	cd test && $(MAKE) test

run: test
	cd test && $(MAKE) run


libExt.DLL: all ext.def dll.obj extensions.lib ext.lib
	$(CC) $(DLLFLAGS) -o $@ ext.def dll.obj $(LIBRARY)
	\os2\apps\lxlite\lxlite *.dll

ext.def: ext.def.in extensions.lib
	$(CP) ext.def.in $@
	$(EMXEXP) extensions.lib >>$@

ext.lib: ext.def
	$(EMXIMP) -o $@ ext.def

dll.obj: rev.h


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

#
# not-programming related
#
exp: extensions.a 
	$(EMXEXP) -u $^ > $@ 

libs: extensions.a uni/libuni.a uni/uconv.a uni/unikbd.a
	$(EMXOMF) extensions.a 
	$(AR) extensions.a uni/libuni.a uni/uconv.a uni/unikbd.a
	$(EMXOMFAR) extensions.lib uni/libuni.lib uni/uconv.lib uni/unikbd.lib

clean:
	$(RM) *.o *.obj *.res *.aux *.log *.toc dummy core *.tmp *.bak
	cd libc && $(MAKE) clean
	cd libm && $(MAKE) clean
	cd libz && $(MAKE) clean
	cd test && $(MAKE) clean

veryclean: 
	$(RM) *.o *.obj *.res *.aux *.log *.toc dummy core *.tmp *.bak *.a \
 *.lib exp uni/*.a uni/*.lib tags *.DLL *.def
	cd libc && $(MAKE) veryclean
	cd libz && $(MAKE) veryclean
	cd libm && $(MAKE) clean
	cd test && $(MAKE) clean
