#
#       Makefile for Mtools
#
# check the Configure file for some examples of device-specific setups
# Berkeley flavors of Unix should include -DBSD in the CFLAGS.  Pick
# a lock method... either -DLOCKF, -DFLOCK, or -DFCNTL and put that
# string in the CFLAGS line below.

# for Dell
#CFLAGS	= -O -DDELL -DLOCKF
# for Sparc
#CFLAGS	= -O -DSPARC -DBSD -DFLOCK
# for Xenix
#CFLAGS = -O -M2e -DINT16 -DXENIX -DLOCKF
#LDFLAGS = -s -M2e -i -f 5000

# for Linux (locking device files does not work reliably?)
# CFLAGS	= -O2 -DLOADDEVS -Wall -m486 #-DFLOCK

# for Sparc-odd (Sparc reading 1.72 Mb disks)
CC      = gcc
CFLAGS	= -O2 -DLOADDEVS -D_POSIX_SOURCE -traditional -Wall -DSPARC_ODD -DNO_STRERROR #-DFLOCK
LDFLAGS	= -s -N

LD	= $(CC)
LINT	= lint
SHLIB	=
SHAR	= shar -a
BINDIR	= ${DEST}/usr/bin
ETCDIR	= ${DEST}/etc
MAN1EXT	= 1
MAN1DIR	= ${DEST}/usr/man/man$(MAN1EXT)
MAN5EXT	= 5
MAN5DIR	= ${DEST}/usr/man/man$(MAN5EXT)
#
# for AT&T Unix PC 7300/3b1 style shared libraries.
#SHOBJ	= /lib/crt0s.o /lib/shlib.ifile
#LD	= ld

LINKS=mattrib mcd mcopy mdel mdir mformat mlabel mmd mmount mrd mread mren  \
      mtype mwrite
MTOOLS = mattrib.o mcd.o mcopy.o mdel.o mdir.o mformat.o misc.o mlabel.o mmd.o \
	 mmount.o mrd.o mread.o mren.o mtype.o mwrite.o buf_read.o buf_write.o \
	 devices.o dir_make.o dir_read.o dir_write.o expand.o fat_free.o \
	 fat_read.o fat_write.o file_read.o file_write.o init.o is_dir.o \
	 match.o parse.o subdir.o mtools.o

MKMAN1IFEST = mkmanifest.o

all:	mtools $(LINKS)

mtools:	$(MTOOLS)
	$(LD) $(LDFLAGS) $(MTOOLS) $(SHOBJ) -o mtools $(SHLIB)

$(LINKS):	mtools
	for name in $(LINKS); \
	do rm -f $$name && ln mtools $$name; done

mkmanifest:	$(MKMAN1IFEST)
	$(LD) $(LDFLAGS) $(MKMAN1IFEST) $(SHOBJ) -o mkmanifest $(SHLIB)

clean:
	-rm *.o 2>/dev/null

spotless:	clean
	-rm mtools $(LINKS) 2>/dev/null

install:	$(BINDIR)/mtools ${ETCDIR}/mtools install-man install-links

$(BINDIR)/mtools: mtools
	cp mtools $(BINDIR)/mtools

$(ETCDIR)/mtools: mtools.etc
	cp mtools.etc $(ETCDIR)/mtools

install-links: $(BINDIR)/mtools
	cd $(BINDIR) && for name in $(LINKS); \
	do rm -f $$name && ln mtools $$name; done

install-man:
	install -c -m 644 mattrib.1 $(MAN1DIR)/mattrib.$(MAN1EXT)
	install -c -m 644 mcd.1 $(MAN1DIR)/mcd.$(MAN1EXT)
	install -c -m 644 mcopy.1 $(MAN1DIR)/mcopy.$(MAN1EXT)
	install -c -m 644 mdel.1 $(MAN1DIR)/mdel.$(MAN1EXT)
	install -c -m 644 mdir.1 $(MAN1DIR)/mdir.$(MAN1EXT)
	install -c -m 644 mformat.1 $(MAN1DIR)/mformat.$(MAN1EXT)
	install -c -m 644 mlabel.1 $(MAN1DIR)/mlabel.$(MAN1EXT)
	install -c -m 644 mmd.1 $(MAN1DIR)/mmd.$(MAN1EXT)
	install -c -m 644 mmount.1 $(MAN1DIR)/mmount.$(MAN1EXT)
	install -c -m 644 mrd.1 $(MAN1DIR)/mrd.$(MAN1EXT)
	install -c -m 644 mread.1 $(MAN1DIR)/mread.$(MAN1EXT)
	install -c -m 644 mren.1 $(MAN1DIR)/mren.$(MAN1EXT)
	install -c -m 644 mtools.1 $(MAN1DIR)/mtools.$(MAN1EXT)
	install -c -m 644 mtools.5 $(MAN5DIR)/mtools.$(MAN5EXT)
	install -c -m 644 mtype.1 $(MAN1DIR)/mtype.$(MAN1EXT)
	install -c -m 644 mwrite.1 $(MAN1DIR)/mwrite.$(MAN1EXT)
	install -c -m 644 mkmanifest.1 $(MAN1DIR)/mkmanifest.$(MAN1EXT)

buf_read.o:	msdos.h
buf_write.o:	msdos.h
devices.o:	msdos.h
dir_make.o:	msdos.h
dir_read.o:	msdos.h
dir_write.o:	msdos.h
fat_free.o:	msdos.h
fat_read.o:	msdos.h
fat_write.o:	msdos.h
file_read.o:	msdos.h
file_write.o:	msdos.h
init.o:		msdos.h
is_dir.o:	msdos.h
misc.o:		msdos.h

mattrib.o:	msdos.h mattrib.c
mcd.o:		msdos.h mcd.c
mcopy.o:	msdos.h getopt.h mcopy.c
mdel.o:		msdos.h mdel.c
mdir.o:		msdos.h mdir.c
mformat.o:	msdos.h getopt.h mformat.c
mlabel.o:	msdos.h mlabel.c
mmd.o:		msdos.h mmd.c
mmount.o:	msdos.h
mrd.o:		msdos.h mrd.c
mread.o:	msdos.h mread.c
mren.o:		msdos.h mren.c
mtype.o:	msdos.h getopt.h mtype.c
mwrite.o:	msdos.h mwrite.c

parse.o:	msdos.h
subdir.o:	msdos.h

mtools.o:	msdos.h patchlevel.h mtools.c
# DO NOT DELETE THIS LINE -- make depend depends on it.
