#
# Makefile for StegFS components
#

CC = gcc
INSTALL = /usr/bin/install -c
AR = ar rc

CFLAGS = -Wall
#CFLAGS = -Wall -I/usr/src/linux/include
# CFLAGS = -g -Wall -DDEVEL_ZEROFILL
LINUX_INCLUDE = -I/usr/src/linux/include

DESTDIR = /usr/local/stegfs

CIPHEROBJS = serpent.o rc6.o mars.o
OLDPROGS = stegfslevel addlevel
MAINPROGS = mkstegfs rerepl stegfsopen stegfsclose stegfsctrl tunestegfs
DEVPROGS = readdata junkblock inolist
MANPAGES = mkstegfs.8 stegfsopen.8 stegfsclose.8 stegfsctrl.8 tunestegfs.8

CFLAGS += $(LINUX_INCLUDE)

all: $(MAINPROGS)
devtools: $(DEVPROGS)

mkstegfs: mkstegfs.o stegfs.o sha1.o $(CIPHEROBJS)
	$(CC) $(CFLAGS) -o mkstegfs mkstegfs.o stegfs.o sha1.o $(CIPHEROBJS) \
	-lext2fs

mkstegfs.o: mkstegfs.c stegfs.h

stegfs.o: stegfs.c stegfs.h sha1.h crypto.h

sha1.o: sha1.c sha1.h

serpent.o: serpent.c crypto.h

rc6.o: rc6.c crypto.h

mars.o: mars.c crypto.h

readdata: readdata.o stegfs.o sha1.o $(CIPHEROBJS)
	$(CC) $(CFLAGS) -o readdata readdata.o stegfs.o sha1.o $(CIPHEROBJS) \
	-lext2fs

readdata.o: readdata.c stegfs.h

inolist: inolist.o stegfs.o sha1.o $(CIPHEROBJS)
	$(CC) $(CFLAGS) -o inolist inolist.o stegfs.o sha1.o $(CIPHEROBJS) \
	-lext2fs

inolist.o: inolist.c stegfs.h

junkblock: junkblock.o
	$(CC) $(CFLAGS) -o junkblock junkblock.o

rerepl: rerepl.o
	$(CC) $(CFLAGS) -o rerepl rerepl.o

stegfslevel: stegfslevel.o
	$(CC) $(CFLAGS) -o stegfslevel stegfslevel.o

stegfsopen: stegfsopen.o
	$(CC) $(CFLAGS) -o stegfsopen stegfsopen.o

stegfsclose: stegfsclose.o
	$(CC) $(CFLAGS) -o stegfsclose stegfsclose.o

stegfsctrl: stegfsctrl.o stegfs.o sha1.o $(CIPHEROBJS)
	$(CC) $(CFLAGS) -o stegfsctrl stegfsctrl.o stegfs.o sha1.o \
	$(CIPHEROBJS) -lext2fs

stegfsctrl.o: stegfsctrl.c stegfs.h

tunestegfs: tunestegfs.o
	$(CC) $(CFLAGS) -o tunestegfs tunestegfs.o

addlevel: addlevel.o stegfs.o sha1.o $(CIPHEROBJS)
	$(CC) $(CFLAGS) -o addlevel addlevel.o stegfs.o sha1.o $(CIPHEROBJS) \
	-lext2fs

addlevel.o: addlevel.c stegfs.h

installprogs:
	install -m755 $(MAINPROGS) $(DESTDIR)/usr/sbin

installman:
	(cd man && \
	install -m644 $(MANPAGES) $(DESTDIR)/usr/share/man/man8)
#	gzip -9 $(DESTDIR)/usr/share/man/man8/*.8

installdocs:
	(cd docs && \
	install -m644 COPYING ChangeLog FAQ.txt README TODO \
	$(DESTDIR)/usr/share/doc/stegfs-tools)

install: installprogs installman installdocs

clean:
	rm -f *~ *.o *.so *.a $(MAINPROGS) $(DEVPROGS) a.out

