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


ifeq ($(MAKE),)
MAKE=make
endif


FLAGS=-Wall -I../atoms/include/
#FLAGS+=-DERROR_HANDLER
CFLAGS= -g -O2 -D_REENTRANT -O2 -Dpng_sizeof=sizeof -DOPTIMISE_SPEED $(FLAGS)
CXXFLAGS= -g -O2 -fno-rtti -fno-exceptions -DFIX_LONGLONG -fpermissive -O2 -Dpng_sizeof=sizeof -DOPTIMISE_SPEED -DNO_EXTENSIONS $(FLAGS)

OBJ=.o
GCC=gcc
GXX=gpp


#### OS autodetection part of makefile ####


#Nothing is an indentifier for DOS? Too bad.
ifeq ($(OSTYPE),)
ifeq ($(HOSTTYPE),iris4d)
OSTYPE = iris4d
else
OSTYPE = dos
endif
endif


# for Linux - debian
ifeq ($(OSTYPE),linux-gnu)
CXXFLAGS+= -D_REENTRANT
GXX = g++
endif

# for 'linux' - Slackware; 'Linux' - Red Hat
#ifeq ($(OSTYPE),$(filter $(OSTYPE),linux Linux))
#endif
#end of Linux


# for MAC
ifeq ($(OSTYPE),darwin)
GXX = g++
CXXFLAGS+=-D_REENTRANT
endif

ifeq ($(OSTYPE),msys)
GXX = g++
CXXFLAGS+=-D_REENTRANT -fpermissive
endif

ifeq ($(OSTYPE),cygwin)
GXX = g++
CXXFLAGS+=-D_REENTRANT -fpermissive
endif


# for sun
#ifeq ($(OSTYPE),solaris)
#LIBS=-lm
#endif
#ifeq ($(OSTYPE),$(filter $(OSTYPE),solaris2.9 solaris2.10))
#endif

#ifeq ($(OSTYPE),sunos4)
#endif
#end of sun

#for OS/2
ifneq "$(OS2_SHELL)" ""
OSTYPE = os2
endif

# for aix
#ifeq ($(OSTYPE),aix)
#endif
#end of aix

# for MSDOS under djgpp
ifeq ($(OSTYPE),msdosdjgpp)
CXXFLAGS+=-DPOINTER_SIZE=32 -DSupportWEBP=0 -DSupportPNG=0
endif
#end of MSDOS under DJGPP



OBJECTS=imgop$(OBJ)
OBJECTS+=img_tool$(OBJ)
OBJECTS+=rasterOp$(OBJ) 

OBJECTS+=filehnd$(OBJ)
OBJECTS+=img_futi$(OBJ)
OBJECTS+=imgsupp$(OBJ)
OBJECTS+=imgut$(OBJ)
OBJECTS+=ras_bmp$(OBJ)
OBJECTS+=ras_gif$(OBJ)
OBJECTS+=ras_img$(OBJ)
OBJECTS+=ras_jpg$(OBJ)
OBJECTS+=ras_png$(OBJ)
OBJECTS+=ras_webp$(OBJ)
OBJECTS+=vecimage$(OBJ)


COMMONDEP=../atoms/include/common.h $(MAKEFILE_LIST)


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


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

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


$(TARGET_LIB_NAME): $(OBJECTS)
	ar rcs $(TARGET_LIB_NAME) $(OBJECTS)


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
	rm -f test/*$(OBJ) test/*.exe test/*.bak test/*.bkp

distclean: clean
	cp makefile.gen makefile

generic:
	rm makefile
	cp makefile.gen makefile

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

../atoms/libatoms.a: ../atoms/include/*.h ../atoms/*.c ../atoms/*.cc
	$(MAKE) -C ../atoms libatoms.a

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

test/test$(OBJ): test/test.cc *.h ../atoms/include/*.h $(MAKEFILE_LIST)
	$(GXX) $(CXXFLAGS) $(DEBUG) -c $*.cc $(ERROR) -o $*$(OBJ) -I../ -I../atoms $(GETTEXT)

test/test.exe: test/test$(OBJ) ../atoms/test/bench$(OBJ) error$(OBJ) $(TARGET_LIB_NAME) ../atoms/libatoms.a
	$(GXX) -o $@ $*$(OBJ) ../atoms/test/bench$(OBJ) error$(OBJ) ../atoms/libatoms.a $(LDFLAGS) $(LIBS) $(TARGET_LIB_NAME) $(ERROR)


test: test/test.exe
	test/test.exe -test
