# Makefile for file(1) cmd. 
# Copyright (c) Ian F. Darwin 86/09/01 - see LEGAL.NOTICE.
# @(#)$Header: Makefile,v 1.17 88/01/15 13:03:16 ian Exp $
#

SHELL	= /bin/sh
MAGIC	= $(INSTALLDIR)/magic
DEFS	= -DMAGIC='"$(MAGIC)"' # -Dvoid=int
COPTS	= -O # -g
CFLAGS	= $(COPTS) $(DEFS)
SHAR	= bundle
OFILE	= /bin/file.orig	# old or distributed version, for comparison
# Where new binary lives; typically /usr/local (BSD), /usr/lbin (USG).
BINDIR	= $(INSTALLDIR)
# For installing our man pages; 
# MANCxxx is manual section for Commands, MANFxxx is section for file formats.
# MANxDIR is directory names; MANxEXT is the filename extention. Usual values:
# Variable	V7		4BSD		Sys V
# MANCDIR 	/usr/man/man1	/usr/man/man1	/usr/man/u_man/man1
# MANFDIR 	/usr/man/man5	/usr/man/man5	/usr/man/u_man/man4
# MANCEXT	1		1		1
# MANFEXT	5		5		4
# --- possible alternative for 4BSD ---
# MANCDIR			/usr/man/manl
# MANCEXT			l
# --- possible alternative for USG ---
# MANCDIR			/usr/man/local/man1
# MANCEXT			1

MANCDIR	= $(MANDIR)/man1
MANFDIR	= $(MANDIR)/man5
MANCEXT	= 1
MANFEXT	= 5

# There are no system-dependant configuration options (except maybe CFLAGS).
# Delete any of LOCALSRCS and LOCALOBJS that are in your C library.
LOCALSRCS = getopt.c strtol.c strtok.c strchr.c
SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c is_tar.c \
	print.c $(LOCALSRCS)
LOCALOBJS = getopt.o strtol.o strtok.o strchr.o
OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o is_tar.o \
	print.o $(LOCALOBJS)

ALLSRC = LEGAL.NOTICE README PORTING $(SRCS) *.h \
	Makefile file.1 magic.4 magdir/[a-z]* tst/Makefile

all:		file magic

try:		all $(OFILE)
		cd tst; make
		time $(OFILE) -m ./magic * tst/* >/tmp/t1
		time ./file -m ./magic * tst/* >/tmp/t2
		-diff -b /tmp/t[12]
		what ./file >lastnocore

file:		$(OBJS)
		cc $(CFLAGS) $(OBJS) -o $@
lint:		$(SRCS)
		lint -ha $(DEFS) $(SRCS) | tee $@
magic:		magdir
#		exclude RCS or SCCS dirs:
		cat magdir/[a-z]* >$@

ascmagic.o:	names.h

apprentice.o ascmagic.o file.o fsmagic.o print.o softmagic.o: file.h

install:	file magic file.1 magic.4 $(BINDIR) $(MANCDIR) $(MANCDIR)
		install -c -s -m 755  file $(BINDIR)/file
		install -c -m 644 magic	$(MAGIC)
		install -c -m 644 file.1 $(MANCDIR)/file.$(MANCEXT)
		install -c -m 644 magic.4 $(MANFDIR)/magic.$(MANFEXT)

clean:
		rm -f *.o file magic lint.out
		(cd tst; make clean)

dist:		$(ALLSRC)
#		Some versions of shar can't handle a single file from
#		a subdirectory, so we manually insert mkdir as needed.
#		Put the extra "mkdir" AFTER the ": to unbundle..." line.
		$(SHAR) $(ALLSRC) | sed -e '1a\
		mkdir magdir tst' >$@

