# stegdetect 0.1 Makefile (c) 2001 Niels Provos

srcdir		= @srcdir@
VPATH		= @srcdir@

install_prefix	=
prefix		= @prefix@
exec_prefix	= @exec_prefix@
bindir		= @bindir@
mandir		= @mandir@
datadir		= @datadir@

JPEGDIR		= ./jpeg-6b
JPEGINC		= -I$(JPEGDIR)
JPEGLIB		= -L$(JPEGDIR) -ljpeg
JPEGDEP		= $(JPEGDIR)/libjpeg.a

FILEDIR		= ./file
FILEINC		= -I$(FILEDIR)
FILELIB		= -L$(FILEDIR) -lfile
FILEDEP		= $(FILEDIR)/libfile.a

GTKINC		= @GTKINC@
GTKLIB		= @GTKLIB@
EVENTINC	= @EVENTINC@
EVENTLIB	= @EVENTLIB@

CC		= @CC@
CFLAGS		= -Wall @CFLAGS@ $(JPEGINC) $(FILEINC) -I$(srcdir)/missing
LDFLAGS		= @LDFLAGS@
LIBS		= $(JPEGLIB)

INSTALL		= @INSTALL@
INSTALL_PROG	= @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@

CSRCS=		common.c jphide_table.c
DSRCS=		stegdetect.c chi2cdf.c
DOBJS=		$(DSRCS:.c=.o) $(CSRCS:.c=.o) @LIBOBJS@
BSRCS=		stegbreak.c break_jphide.c cfg.c rpp.c rules.c bf_skey.c \
		db.c break_outguess.c break_jsteg.c arc4.c
XOBJS=		@BFOBJ@
BOBJS=		$(BSRCS:.c=.o) $(CSRCS:.c=.o) $(XOBJS) @LIBOBJS@
XSSRCS=		xsteg.c xsteg_xpm.c
XSOBJS=		$(XSSRCS:.c=.o)

PROGS=		stegdetect stegbreak @XSTEG@

all: $(PROGS)

stegdetect: $(JPEGDEP) $(DOBJS)
	$(CC) $(CFLAGS) $(INCS) -o $@ $(DOBJS) $(LIBS)

stegbreak: $(JPEGDEP) $(FILEDEP) $(BOBJS)
	$(CC) -static $(CFLAGS) $(INCS) -o $@ $(BOBJS) $(LIBS) $(FILELIB)

$(XSOBJS):
	$(CC) $(CFLAGS) $(EVENTINC) $(GTKINC) -c $*.c

xsteg:	$(XSOBJS) @LIBOBJS@
	$(CC) $(CFLAGS) $(INCS) -o $@ @LIBOBJS@ $(XSOBJS) $(GTKLIB) $(EVENTLIB)

$(JPEGDEP):
	cd $(JPEGDIR); $(MAKE) libjpeg.a

$(FILEDEP):
	cd $(FILEDIR); $(MAKE) libfile.a

install: all
	test -d $(install_prefix)$(bindir) || \
	   $(INSTALL) -d $(install_prefix)$(bindir)
	test -d $(install_prefix)$(datadir)/stegbreak || \
	   $(INSTALL) -d $(install_prefix)$(datadir)/stegbreak
	$(INSTALL_DATA) rules.ini $(install_prefix)$(datadir)/stegbreak
	for file in $(PROGS); do \
	   $(INSTALL_PROG) -m 755 $$file $(install_prefix)$(bindir); \
	done
	test -d $(install_prefix)$(mandir)/man1 || \
	   $(INSTALL) -d $(install_prefix)$(mandir)/man1
	for file in *.1; do \
	   $(INSTALL_DATA) $$file $(install_prefix)$(mandir)/man1; \
	done

clean:
	cd $(JPEGDIR); $(MAKE) $@
	cd $(FILEDIR); $(MAKE) $@
	rm -f $(PROGS) *~ $(DOBJS) $(BOBJS) $(POBJS) $(XSOBJS)

distclean: clean
	cd $(JPEGDIR); $(MAKE) $@
	cd $(FILEDIR); $(MAKE) $@
	rm -f Makefile config.h config.status config.cache config.log

strlcat.o: $(srcdir)/missing/strlcat.c
	$(CC) $(CFLAGS) -c $(srcdir)/missing/strlcat.c

strlcpy.o: $(srcdir)/missing/strlcpy.c
	$(CC) $(CFLAGS) -c $(srcdir)/missing/strlcpy.c

err.o: $(srcdir)/missing/err.c
	$(CC) $(CFLAGS) -c $(srcdir)/missing/err.c

md5.o: $(srcdir)/missing/md5.c
	$(CC) $(CFLAGS) -c $(srcdir)/missing/md5.c
