# makefile for atoms for (gcc)
# runs under DOS, Windows, OS/2 and many Linux based OS
#
TARGET_LIB_NAME = libatoms.a
TEST_NAME_STR = TetStrings.exe

FLAGS=-Wall -I./include/
#FLAGS+=-DERROR_HANDLER
CFLAGS=@CPPFLAGS@ @CFLAGS@ @OPTIMIZE_CFLAGS@ -DOPTIMISE_SPEED $(FLAGS)
CXXFLAGS=@CPPFLAGS@ @CXXFLAGS@ @OPTIMIZE_CFLAGS@ -DOPTIMISE_SPEED $(FLAGS)

OBJ=.o

OBJECTS=struct$(OBJ)

%OBJECTS=containe$(OBJ)
OBJECTS+=dbllist$(OBJ)
OBJECTS+=sets$(OBJ)
OBJECTS+=std_str$(OBJ)
OBJECTS+=struct$(OBJ)
OBJECTS+=lists$(OBJ)
OBJECTS+=strings$(OBJ)
OBJECTS+=stack$(OBJ)

OBJECTS+=raster$(OBJ)
OBJECTS+=rasterut$(OBJ)
OBJECTS+=rasterc$(OBJ) 
OBJECTS+=xlat_swp$(OBJ) 

OBJECTS+=utf8$(OBJ)
OBJECTS+=mtx_impl$(OBJ)


COMMONDEP=include/common.h $(MAKEFILE_LIST)


.SUFFIXES: .c .cc $(OBJ) .exe .a
.PHONY: all default distclean generic clean test


.cc$(OBJ): include/*.h
	@CXX@ $(CXXFLAGS) $(DEBUG) -c $*.cc $(ERROR) -o $*$(OBJ) $(GETTEXT)

.c$(OBJ): include/*.h
	@CC@ $(CFLAGS) $(DEBUG) -c $*.c $(ERROR) -o $*$(OBJ) $(GETTEXT)


$(TARGET_LIB_NAME): $(OBJECTS)
	@AR@ rcs $(TARGET_LIB_NAME) $(OBJECTS)


struct$(OBJ):	struct.c $(COMMONDEP) include/struct.h
utf8$(OBJ):	utf8.c $(COMMONDEP)

%complex$(OBJ):	complex.cc $(COMMONDEP)
containe$(OBJ):	containe.cc $(COMMONDEP)
interval$(OBJ):	interval.cc $(COMMONDEP) include/interval.h
std_str$(OBJ):	std_str.cc $(COMMONDEP) include/std_str.h
raster$(OBJ):	stack.cc $(COMMONDEP) include/ras_prot.h include/raster.h 
stack$(OBJ):	stack.cc $(COMMONDEP) include/stacks.h
sets$(OBJ):	sets.cc $(COMMONDEP) include/sets.h
strings$(OBJ):	strings.cc $(COMMONDEP) include/stringa.h


all:     $(TARGET_LIB_NAME)
#	cp -f strings/*.h include/*.h
#	cp -f sets/*.h include/*.h


default: $(TARGET_LIB_NAME)


clean:
	rm -f $(TARGET_LIB_NAME) *.exe *$(OBJ) *.obj *.o *.bak core *.bkp *.a *.tmp
	rm -f include/*.bak include/*.bkp
	rm -f test/*$(OBJ)
	rm -f TestLists/*$(OBJ) TestLists/*.exe
	rm -f TestRaster/*$(OBJ) TestRaster/*.exe
	rm -f TestSets/*$(OBJ) TestSets/*.exe
	rm -f TestStack/*$(OBJ) TestStack/*.exe
	rm -f TestString/*$(OBJ) TestString/*.exe
	rm -f TestStruct/*$(OBJ) TestStruct/*.exe


distclean: clean
	cp include/common.h.gen include/common.h
	cp makefile.gen makefile

generic:
	cp include/common.h.gen include/common.h
	rm makefile
	cp makefile.gen makefile


#################### TEST ONLY #######################

test/bench$(OBJ): test/bench.c $(MAKEFILE_LIST)

TestLists/test$(OBJ): TestLists/test.cc include/*.h $(MAKEFILE_LIST)

TestLists/test.exe: TestLists/test$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CXX@ -o $@ $*$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)

TestString/test$(OBJ): TestString/test.cc include/*.h $(MAKEFILE_LIST)

TestString/test.exe: TestString/test$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CXX@ -o $@ $*$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)

TestSets/test$(OBJ): TestSets/test.cc include/*.h $(MAKEFILE_LIST)

TestSets/test.exe: TestSets/test$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CXX@ -o $@ $*$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)

TestStack/test$(OBJ): TestStack/test.cc include/*.h $(MAKEFILE_LIST)

TestStack/test.exe: TestStack/test$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CXX@ -o $@ $*$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)

TestStruct/test$(OBJ): TestStruct/test.c include/*.h $(MAKEFILE_LIST)

TestStruct/test.exe: TestStruct/test$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CC@ -o $@ $*$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)

TestRaster/test.exe: TestRaster/test$(OBJ) TestRaster/error$(OBJ) test/bench$(OBJ) $(TARGET_LIB_NAME)
	@CXX@ -o $@ $*$(OBJ) TestRaster/error$(OBJ) test/bench$(OBJ) $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)


test: TestString/test.exe TestSets/test.exe TestStack/test.exe TestStruct/test.exe TestRaster/test.exe TestLists/test.exe
	TestLists/test.exe -test
	TestString/test.exe -test
	TestSets/test.exe -test
	TestStack/test.exe -test
	TestStruct/test.exe -test
	TestRaster/test.exe -test
