#
# Makefile for the linux HFS filesystem module
#
# Copyright 1995-1997  Paul H. Hargrove
# This file may be distributed under the terms of the GNU Public License.
#

# CHANGE THIS IF YOUR KERNEL SOURCES ARE IN SOME OTHER PLACE:
include /usr/src/linux/.config

# cross-compilation prefix
XPREFIX=
#XPREFIX=i486-linux-

CC	= $(XPREFIX)gcc -I.
LD	= $(XPREFIX)ld
SIZE	= $(XPREFIX)size

MODFLAGS = -DMODULE
ifdef CONFIG_MODVERSIONS
MODFLAGS += -DMODVERSIONS -include /usr/include/linux/modversions.h
endif
WARN    = -Wall -Wstrict-prototypes -Werror
OPT     = -O2 -fno-strength-reduce -fomit-frame-pointer -fno-builtin
MACHINE = -pipe

CFLAGS	= -D__KERNEL__ $(MODFLAGS) $(WARN) $(OPT) $(MACHINE) $(EXTRA)

# B-tree sources and headers:
BSRCS	= balloc.c    bdelete.c   bfind.c     bins_del.c  \
	  binsert.c   bnode.c     brec.c      btree.c
BHDRS	= hfs_btree.h

# HFS sources and headers:
HSRCS	= bitmap.c    bitops.c    catalog.c   extent.c    \
	  mdb.c       part_tbl.c  string.c
HHDRS	= hfs.h

# Linux sources and headers:
LSRCS	= dir.c       dir_cap.c   dir_dbl.c   dir_nat.c   \
	  file.c      file_cap.c  file_hdr.c  inode.c     \
	  super.c     sysdep.c    trans.c     version.c
LHDRS	= linux/hfs_fs.h linux/hfs_fs_i.h linux/hfs_fs_sb.h linux/hfs_sysdep.h

MISC	= COPYING ChangeLog Makefile TODO
	  
DOCSRCS	= HFS.sgml INSTALL.sgml FAQ.sgml
DOCS	= $(DOCSRCS:.sgml=.txt) $(DOCSRCS:.sgml=.dvi)
ALTDOCS	= $(DOCSRCS:.sgml=.ps) $(DOCSRCS:.sgml=.info)

SRCS	= $(BSRCS) $(HSRCS) $(LSRCS)
HDRS	= $(BHDRS) $(HHDRS) $(LHDRS)
OBJS	= $(SRCS:.c=.o)

default: hfs.o

ifeq (.depend,$(wildcard .depend))
include .depend
endif

.SUFFIXES: .c .o .h .s .txt .dvi .sgml .ps .info

%.o:	%.c
	$(CC) $(CFLAGS) -c -o $@ $<

%.s:	%.c
	$(CC) $(CFLAGS) -fverbose-asm -S -o $@ $<

%.txt:	%.sgml
	sgml2txt $<

%.dvi:	%.sgml
	sgml2latex -d $<

%.ps:	%.sgml
	sgml2latex -p $<

%.info:	%.sgml
	sgml2info $<

hfs.o:	$(OBJS)
	$(LD) -r -o $@ $(OBJS)
	$(SIZE) $@

$(OBJS): .depend

dep .depend:
	$(CPP) -M $(SRCS) > .tmpdepend
	mv .tmpdepend .depend
	rm -f $(OBJS) hfs.o $(SRCS:.c=.s)

clean:
	rm -f $(OBJS) hfs.o $(SRCS:.c=.s) $(ALTDOCS) a.out core .tmpdepend

veryclean: clean
	rm -f $(DOCS) .depend

docs:	$(DOCS)

TODAY	= $(shell date +%d%b%y)
SNAPSHOT= HFS_SNAPSHOT_$(TODAY)

snapshot: $(DOCS)
	#cvs tag -F SNAP$(shell date +%y%m%d)
	mkdir $(SNAPSHOT)
	cp $(SRCS) $(BHDRS) $(HHDRS) $(MISC) $(DOCS) $(SNAPSHOT)
	mkdir $(SNAPSHOT)/linux
	cp $(LHDRS) $(SNAPSHOT)/linux
	tar cvfz $(TODAY).tgz $(SNAPSHOT)
	rm -rf $(SNAPSHOT)
