#
# Makefile for StegFS components
#

LINUX := /usr/src/linux

CC := gcc
INSTALL := /usr/bin/install
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

CIPHEROBJS := serpent.o mars.o aes.o aesstub.o twofish.o
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

aes.o: aes.c aes.h

aesstub.o: aesstub.c aes.h

twofish.o: twofish.c

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

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

stegfs.h: ../kernel/fs.h

../kernel/fs.h:
	../kernel/make_fs_h.pl ../kernel/ $(LINUX)

install:
	$(INSTALL) -m755 $(MAINPROGS) $(DESTDIR)/sbin

uninstall:
	(cd $(DESTDIR)/sbin && \
	$(RM) $(MAINPROGS))

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