#-----------------------------------------------------------------
#	1er Fevrier 2000: Je met une cible pour installer
#		les fichiers dans le systeme. C'est assez
#		rudimentaire/arbitraire, mais c,a marche
#		a peu pres, mieux que le Momo...
#
#-----------------------------------------------------------------

DESTDIR=/usr/local
SHARED_FILES=$(DESTDIR)/share/libimage
HTML_DIR=$(DESTDIR)/html

#-----------------------------------------------------------------
#
#	pour le debuging: option -g
#	pour le profiling: option -pg
#	pour tracer plein de trucs: -DDEBUG_LEVEL=1
#	if IMGCOMMENT, the image comment is written to the TGA file,
#		but this files can't be loaded by Xv...
#	pour coredumper dans les situations graves: -DABORT=1
#
#	--> see file 'PORTING.txt' for porting tips on misc
#	    architextures (just sparc64 for now)
#

LIBIMG_OPT=-DFORCE_ABORT=1 -DDEBUG_LEVEL=0 -DIMGCOMMENT=0
CC_OPTS=-Wall -W -g -ansi  -Wmissing-prototypes -fPIC -no-pie
CC_HACKS=-DNEED_ALLOCA_H 
CFLAGS= $(CC_OPTS)			\
	$(LIBIMG_OPT)			\
	$(CC_HACKS) 			\
	-DDESTDIR=\"$(DESTDIR)\"	\
	-DSHAREDIR=\"$(SHARED_FILES)\"	\
	-DCC_OPTS=\"'$(CC_OPTS)'\"
LINKOPT=-lm
RANLIB=wc -c

# modify it 'as you like'
AR=ar 

#-------- essentials targets

all:		testtga libs
libs:		libimage.a libimageSO.so
trucs:		t_t16x24  fnt8to16 t_png

#-----------------------------------------------------------------

image.o:    	image.c     tthimage.h	Makefile
filtres.o:  	filtres.c   tthimage.h
filtadapt.o:	filtadapt.c tthimage.h
sobel4.o:	sobel4.c	tthimage.h
showdiff.o:  	showdiff.c  tthimage.h
effects.o:  	effects.c   tthimage.h Makefile
effects2.o:  	effects2.c  tthimage.h
effects3.o:  	effects3.c  tthimage.h
television.o:  	television.c  tthimage.h	Makefile
tele_2.o:	tele_2.c    tthimage.h Makefile
classif.o:	classif.c   tthimage.h
combine.o:  	combine.c   tthimage.h
combine2.o:  	combine2.c  tthimage.h
combine3.o:  	combine3.c  tthimage.h
combine4.o:  	combine4.c  tthimage.h
combine5.o:  	combine5.c  tthimage.h
combine6.o:  	combine6.c  tthimage.h Makefile
combine_rnd.o: 	combine_rnd.c  tthimage.h
basic_io.o:  	basic_io.c  tthimage.h
pcx.o:      	pcx.c       tthimage.h 
png.o:      	png.c       tthimage.h 
bmp.o:		bmp.c       tthimage.h bmp.h
tga.o:      	tga.c       tthimage.h Makefile
eps.o:      	eps.c       tthimage.h
pht.o:      	pht.c       tthimage.h 
pnm.o:      	pnm.c       tthimage.h
fits.o:		fits.c	    tthimage.h
zoom.o:		zoom.c	    tthimage.h
gadgrect.o:	gadgrect.c	tthimage.h
ascii.o:      	ascii.c     tthimage.h
asciiart.o:    	asciiart.c  tthimage.h
glitch.o:	glitch.c    tthimage.h Makefile
contours.o:	contours.c    tthimage.h Makefile
calculs.o:  	calculs.c   tthimage.h Makefile
contrast.o:  	contrast.c   tthimage.h Makefile
calcluts.o:  	calcluts.c  tthimage.h
luts15bits.o:	luts15bits.c tthimage.h
gamma.o:  	gamma.c   tthimage.h
quadpics.o:	quadpics.c tthimage.h Makefile
colors.o:   	colors.c    tthimage.h Makefile
colors2.o:   	colors2.c    tthimage.h
col_xyz.o:   	col_xyz.c   tthimage.h
palettes.o:	palettes.c	tthimage.h
indexcol.o:	indexcol.c	tthimage.h
col_reduc.o:	col_reduc.c	tthimage.h	Makefile
drawpatt.o:	drawpatt.c	tthimage.h
operat.o:   	operat.c    tthimage.h		Makefile
stereo.o:	stereo.c	tthimage.h
tools.o:    	tools.c     tthimage.h
mircol.o:    	mircol.c    tthimage.h
mustopen.o:    	mustopen.c     tthimage.h	Makefile
msglib.o:    	msglib.c    tthimage.h 		Makefile
ptlist.o:	ptlist.c	tthimage.h	Makefile
dither.o:   	dither.c	tthimage.h 	Makefile
dither2.o:   	dither2.c	tthimage.h 	Makefile
dither3.o:   	dither3.c	tthimage.h 	Makefile
dither4.o:   	dither4.c	tthimage.h 	Makefile
bitblt.o:	bitblt.c	tthimage.h	Makefile
detect.o:	detect.c	tthimage.h	Makefile
detect2.o:	detect2.c	tthimage.h	Makefile
op2x2.o:	op2x2.c		tthimage.h
morpho.o:	morpho.c	tthimage.h
recurse.o:	recurse.c	tthimage.h
drawing.o:	drawing.c	tthimage.h	Makefile
draw_alpha.o:	draw_alpha.c	tthimage.h
marques.o:	marques.c	tthimage.h	Makefile
pov_hf15.o:	pov_hf15.c	tthimage.h
pov_hf15b.o:	pov_hf15b.c	tthimage.h
pov_hf15c.o:	pov_hf15c.c	tthimage.h
pov_hf15d.o:	pov_hf15d.c	tthimage.h
pov_hf15e.o:	pov_hf15e.c	tthimage.h
pov_hf15f.o:	pov_hf15f.c	tthimage.h
pov_hf_synth.o:	pov_hf_synth.c	tthimage.h
df3.o:		df3.c		tthimage.h
df3b.o:		df3b.c		tthimage.h
cadres.o:	cadres.c	tthimage.h	Makefile
cadres2.o:	cadres2.c	tthimage.h
cadres3.o:	cadres3.c	tthimage.h
cadres4.o:	cadres4.c	tthimage.h
cadres84.o:	cadres84.c	tthimage.h
cadresbox.o:	cadresbox.c	tthimage.h	Makefile
alpha.o:	alpha.c		tthimage.h	Makefile
alpha2.o:	alpha2.c	tthimage.h
alpha3.o:	alpha3.c	tthimage.h
mosaic.o:	mosaic.c	tthimage.h	Makefile
text0.o:	text0.c		tthimage.h	Makefile
text1.o:	text1.c		tthimage.h	Makefile
text2.o:	text2.c		tthimage.h	Makefile
text16x24.o:	text16x24.c	tthimage.h Makefile
freetype.o:	freetype.c	tthimage.h
vectfont.o:	vectfont.c	tthimage.h
scale.o:	scale.c		tthimage.h
halfsize.o:	halfsize.c	tthimage.h	Makefile
doublesz.o:	doublesz.c	tthimage.h
levels.o:	levels.c	tthimage.h
patterns2.o:	patterns2.c	tthimage.h	Makefile
patterns.o:	patterns.c	tthimage.h
patterns3.o:	patterns3.c	tthimage.h
patterns4.o:	patterns4.c	tthimage.h
insert.o:	insert.c	tthimage.h	Makefile
plotteur.o:	plotteur.c	tthimage.h	Makefile
imprime.o:	imprime.c	tthimage.h	Makefile
col4bits.o:	col4bits.c	tthimage.h	Makefile
dumppix.o:	dumppix.c	tthimage.h
warp0.o:	warp0.c		tthimage.h
warp1.o:	warp1.c		tthimage.h
warp2.o:	warp2.c		tthimage.h
warp3.o:	warp3.c		tthimage.h
xper.o:		xper.c		tthimage.h	Makefile
dissolve.o:	dissolve.c	tthimage.h
troisD.o:	troisD.c	tthimage.h
turtle.o:	turtle.c	tthimage.h
cjpeg.o:	cjpeg.c 	tthimage.h
rgbmask.o:	rgbmask.c	tthimage.h
octree.o:	octree.c	tthimage.h
addborder.o:	addborder.c	tthimage.h
fill_pat.o:	fill_pat.c	tthimage.h
vectfont.o:	vectfont.c	tthimage.h
photomaton.o:	photomaton.c	tthimage.h	Makefile
pixeliz.o:	pixeliz.c	tthimage.h Makefile
pixels.o:	pixels.c	tthimage.h Makefile
anamorphose.o:	anamorphose.c	tthimage.h	Makefile
life.o:		life.c		tthimage.h
tamppool.o:	tamppool.c	tthimage.h
vignetize.o:	vignetize.c	tthimage.h
7seg.o:		7seg.c		tthimage.h Makefile
bitplanes.o:	bitplanes.c	tthimage.h Makefile
distances.o:	distances.c	tthimage.h Makefile
gray_ops.o:	gray_ops.c	tthimage.h Makefile
extractbits.o:	extractbits.c	tthimage.h Makefile
jauges.o:	jauges.c	tthimage.h Makefile

#-----------------------------------------------------------------

OBJECTS=  image.o filtres.o effects.o operat.o			\
	  tamppool.o gray_ops.o					\
          calculs.o calcluts.o luts15bits.o			\
	  octree.o filtadapt.o sobel4.o				\
	  classif.o vignetize.o					\
	  gamma.o zoom.o gadgrect.o				\
	  pht.o eps.o pnm.o png.o				\
	  bmp.o pcx.o tga.o 					\
	  colors.o colors2.o col_reduc.o col_xyz.o		\
	  tools.o mircol.o imprime.o				\
	  combine.o combine2.o combine3.o combine4.o combine5.o	\
	  combine6.o combine_rnd.o				\
	  turtle.o marques.o rgbmask.o				\
	  television.o tele_2.o					\
	  effects2.o effects3.o					\
	  contrast.o glitch.o					\
	  basic_io.o mustopen.o ptlist.o			\
	  anamorphose.o quadpics.o 				\
	  dither.o dither2.o dither3.o dither4.o		\
	  bitblt.o detect.o op2x2.o detect2.o			\
	  drawing.o draw_alpha.o drawpatt.o			\
	  pov_hf15.o pov_hf15b.o pov_hf15c.o pov_hf15d.o	\
	  pov_hf15e.o pov_hf15f.o				\
	  pov_hf_synth.o df3.o df3b.o				\
	  alpha.o alpha2.o alpha3.o				\
	  text0.o text1.o text2.o text16x24.o			\
	  freetype.o vectfont.o					\
	  cadres.o cadres2.o cadres3.o cadres4.o		\
	  cadres84.o cadresbox.o 7seg.o				\
	  dissolve.o photomaton.o				\
	  mosaic.o life.o extractbits.o				\
	  palettes.o col4bits.o indexcol.o			\
	  xper.o showdiff.o					\
	  scale.o halfsize.o doublesz.o				\
	  levels.o stereo.o jauges.o				\
	  patterns4.o patterns3.o patterns2.o patterns.o	\
	  fill_pat.o pixeliz.o pixels.o				\
	  insert.o addborder.o					\
	  morpho.o ascii.o plotteur.o dumppix.o asciiart.o	\
	  warp0.o warp1.o warp2.o warp3.o			\
	  fits.o recurse.o msglib.o troisD.o			\
	  cjpeg.o bitplanes.o distances.o

libimage.a: 	$(OBJECTS)
	$(AR) r libimage.a $?
	$(RANLIB) libimage.a

#-----------------------------------------------------------------
#	WARNING !!!
#		this is my first trial on shared library, so
#		use with care... and what is the "-PIC" option ?
#

libimageSO.so: $(OBJECTS)
	gcc -o libimageSO.so -shared $(OBJECTS)

#-----------------------------------------------------------------
#
#	fabrication du (des) programme(s) de test.
#

essais.o:	essais.c tthimage.h  Makefile essais.h
essais2.o:	essais2.c tthimage.h  Makefile essais.h
all_tests.o:	all_tests.c tthimage.h  Makefile essais.h
essai3d.o:	essai3d.c tthimage.h Makefile

testtga.o:	testtga.c tthimage.h essais.h Makefile
	gcc $(CFLAGS) -c testtga.c
testtga:    testtga.o libimage.a essais.o essais2.o all_tests.o Makefile
	gcc $(CFLAGS) testtga.o essais.o essais2.o all_tests.o libimage.a -lm -o testtga

testrect.o:	testrect.c tthimage.h essais.h Makefile
	gcc $(CFLAGS) -c testrect.c
testrect:    testrect.o libimage.a Makefile
	gcc $(CFLAGS) testrect.o libimage.a -lm -o testrect

testSO:		testtga.o libimageSO.so
	gcc testtga.o -o testSO libimageSO.so -lm

essai3d:	essai3d.o libimage.a Makefile
	gcc $(CFLAGS) essai3d.o -o essai3d libimage.a -lm

t_ascii:	t_ascii.c libimage.a tthimage.h Makefile
	gcc $(CFLAGS) t_ascii.c -o t_ascii libimage.a -lm -g

t_png:	t_png.c libimage.a tthimage.h Makefile
	gcc $(CFLAGS) t_png.c -o t_png libimage.a -lm -lpng -g

t_t16x24.o:	t_t16x24.c tthimage.h Makefile
	gcc -c $(CFLAGS) t_t16x24.c 
t_t16x24:	t_t16x24.o libimage.a Makefile
	gcc $(CFLAGS) t_t16x24.o -o t_t16x24 libimage.a -lm -g
all16x24chars.tga:	bigfont.txt t_t16x24 Makefile
	./t_t16x24
all16x24chars.png:	all16x24chars.tga	
	convert all16x24chars.tga all16x24chars.png

testpcx:	testpcx.c libimage.a Makefile
	gcc $(CFLAGS) -g testpcx.c -o testpcx libimage.a -lm 
testbmp:	testbmp.c libimage.a Makefile
	gcc $(CFLAGS) -g testbmp.c -o testbmp libimage.a -lm 

foo:		foo.c Makefile libimage.a
	gcc $(CFLAGS) foo.c libimage.a -o foo -lm 

fnt8to16:	fnt8to16.c Makefile
	gcc -Wall fnt8to16.c -o fnt8to16

#-----------------------------------------------------------------
#
#	procedure d'installation en chantier...
#

install_lib:
	install -d         $(DESTDIR)/lib/
	install libimage.a $(DESTDIR)/lib/libimage.a
	install libimageSO.so $(DESTDIR)/lib/
	install -d         $(DESTDIR)/include/
	install -m 0644 tthimage.h    $(DESTDIR)/include/tthimage.h
#	install -m 0644 img77.fi   $(DESTDIR)/include/img77.fi
	install -d         $(SHARED_FILES)
	install -m 0644 libimage.fonte $(SHARED_FILES)/
	install -m 0644 8x8thin $(SHARED_FILES)/
	install -m 0644 16x24thin $(SHARED_FILES)/
	install -m 0644 bigfont.txt $(SHARED_FILES)/
	install -m 0644 neon.map $(SHARED_FILES)/neon.map
	install -m 0644 volcano.map $(SHARED_FILES)/volcano.map
	install -m 0644 primaires.map $(SHARED_FILES)/primaires.map

install_doc:
	install -m 0644 libimage.html $(HTML_DIR)/libimage.html
	install -m 0644 img-effets.html $(HTML_DIR)/img-effets.html
	install -m 0644 img-fichiers.html $(HTML_DIR)/img-fichiers.html
	install -m 0644 img-calculs.html $(HTML_DIR)/img-calculs.html
	install -m 0644 img-cadres.html $(HTML_DIR)/img-cadres.html
	install -m 0644 img-combine.html $(HTML_DIR)/img-combine.html
	install -m 0644 img-couleurs.html $(HTML_DIR)/img-couleurs.html
	install -m 0644 img-dither.html $(HTML_DIR)/img-dither.html
	install -m 0644 img-filtres.html $(HTML_DIR)/img-filtres.html
	install -m 0644 img-povhf15.html $(HTML_DIR)/img-povhf15.html
	install -m 0644 img-patterns.html $(HTML_DIR)/img-patterns.html
	install -m 0644 img-showdiff.html $(HTML_DIR)/img-showdiff.html
	install -m 0644 img-stereo.html $(HTML_DIR)/
	install -m 0644 image77.html $(HTML_DIR)/image77.html
	install -m 0644 img-devel.html $(HTML_DIR)/img-devel.html
	install -m 0644 img-texte.html $(HTML_DIR)/img-texte.html
	install -m 0644 img-alpha.html $(HTML_DIR)/img-alpha.html
	install -m 0644 img-operat.html $(HTML_DIR)/img-operat.html

install: install_lib 
	@echo
	@echo "Use 'make install_doc' for installing doc in " $(HTML_DIR)
	@echo

#-----------------------------------------------------------------

TXTFILES=*.c *.h Makefile Doc/*.html *.txt  \
	neon.map volcano.map primaires.map *.sh *.css *.fonte

TOTAR=$(TXTFILES) pov.tga 8x8thin machin.bin 16x24thin

lines:          $(TXTFILES)
	@wc $^ | sort -g

tarball:	$(TOTAR)	
	date >> tarball
	ls $(TOTAR) | sed 's/^/LibImage\//'  > MANIFEST
	( cd .. ; tar zcvf libimage.tar.gz `cat LibImage/MANIFEST` )

#----------- fini ------------------------------------------------