CC=		gcc
COMPILE_ET=../et/compile_et

CFLAGS_NO=	-Wall -I..
CFLAGS=		$(OPT) $(CFLAGS_NO)
LDFLAGS=	$(OPT)

#
# Optimization flags
#
#OPT=		-g -O
OPT=		-O2 -fomit-frame-pointer

ARCHIVE=ar r
RANLIB=ranlib
RM=rm -f
MV=mv
LN=ln -s

OBJS= ext2_err.o openfs.o bitmaps.o inode.o unix_io.o block.o namei.o \
	get_pathname.o bitops.o link.o alloc.o expanddir.o

DISTFILES= Makefile *.c *.h image

.c.o:
	$(CC) $(CFLAGS) -c $*.c
	$(CC) $(CFLAGS_NO) -pg -o profiled/$*.o -c $*.c
#	$(CC) $(CFLAGS_NO) -checker -g -o checker/$*.o -c $*.c

all: libext2fs.a libext2fs_p.a 

libext2fs.a: $(OBJS)
	$(RM) $@.bak
	-$(MV) $@ $@.bak
	$(ARCHIVE) $@ $(OBJS)
	$(RANLIB) $@
	$(RM) ../$@
	$(LN) ext2fs/$@ ../$@

libext2fs_p.a: $(OBJS)
	$(RM) $@.bak
	-$(MV) $@ $@.bak
	(cd profiled; $(ARCHIVE) ../$@ $(OBJS))
	$(RANLIB) $@
	$(RM) ../$@
	$(LN) ext2fs/$@ ../$@

libext2fs_chk.a: $(OBJS)
	$(RM) $@.bak
	-$(MV) $@ $@.bak
	(cd checker; $(ARCHIVE) ../$@ $(OBJS))
	$(RANLIB) $@
	$(RM) ../$@
	$(LN) ext2fs/$@ ../$@

ext2_err.c ext2_err.h: ext2_err.et
	$(COMPILE_ET) ext2_err.et

clean:
	rm -f \#* *.s *.o *.a *~ *.bak core profiled/* checker/*

really-clean: clean
	rm -f .depend ext2_err.c ext2_err.h

dep depend: ext2_err.h
	$(CC) -M $(CFLAGS) *.c >.depend

include .depend
