DEBUGFLAGS=	-DNDEBUG
CFLAGS=		-fPIC -O2 -Wall $(DEBUGFLAGS)
LDFLAGS=	-Wall

all: cctool

hexdump.o: hexdump.h hexdump.c
	gcc $(CFLAGS) -c hexdump.c

my_cipher.o: cipher.h my_cipher.c
	 gcc $(CFLAGS) -c my_cipher.c

Cipher.o: cipher.h
	@if test -f my_cipher.c; \
	then \
		$(MAKE) my_cipher.o && \
		ln -sf my_cipher.o Cipher.o; \
	elif test ! -f Cipher.o; \
	then \
		echo "Error: Cipher.o not found!"; \
		exit 1; \
	fi

test.o: test.c cipher.h
	gcc $(CFLAGS) -c test.c

test: hexdump.o test.o Cipher.o
	gcc -o test $(LDFLAGS) hexdump.o test.o Cipher.o

cctool.o: cctool.c cipher.h
	gcc $(CFLAGS) -c cctool.c

cctool: cctool.o Cipher.o
	gcc $(LDFLAGS) -o cctool cctool.o Cipher.o

clean:
	rm -f hexdump.o my_cipher.o test.o test cctool.o cctool
	test "`readlink "Cipher.o"`" = "my_cipher.o" && rm -f Cipher.o || true

debug:
	@$(MAKE) $* "DEBUGFLAGS=-DDEBUG -g"

.PHONY: clean

# vim600: noet sw=8 ts=8
