##########################################################################
# SEQUENT SYMMETRY INSTALLATION:                                         #
##########################################################################
# On the Sequent Symmetry use command '/etc/online -N' to find out about
# the number of processors on line. On other machines either use an 
# equivalent command or define the number yourself. Also, if you wish to
# restrict magic to smaller number of processors define your own number
# which must be less than `/etc/online -N`
 
  NO_OF_PROC	= `/etc/online -N`
  LOCLIB	= -lseq
  PARLIB	= -lpps
  WARNINGS	= -w
 
##########################################################################
# SUN INSTALLATION:                                                      #
##########################################################################
# On the Sun define 
 
# HASTIMES	= -DHASTIMES
 
##########################################################################
# DESTINATION DIRECTORIES, GROUPS AND UIDS                               #
##########################################################################

# where the binaries go
BIN		= /usr/local/bin
# owner of the binaries
BINOWN		= root
# group of the binaries
BINGRP		= daemon
# where the help files go
MAGLIB		= /usr/local/lib/magic
# the root of man directories
MANROOT		= /usr/man
# manual section
MANSECT		= l
# owner of manual and help files
MANOWN		= root
# group of manual and help files
MANGRP		= daemon
# permissions on the MAGLIB directory
MANDMODE	= 775
# permissions on manual entries and help files
MANMODE		= 664
# permissions on the binaries
BINMODE		= 775

##########################################################################
# You should not have to change the stuff below                          #
##########################################################################

CPP		= /lib/cpp
CFLAGS		= -O $(HASTIMES) $(WARNINGS) -DDATA_DIR=\"$(MAGLIB)/\"
MACDIR		= ./monmacs
MACROS		= $(MACDIR)/c.m4.monmacs $(MACDIR)/c.m4.smacs
MACLIB		= $(MACDIR)/mplib.a
MANDIR		= $(MANROOT)/man$(MANSECT)
CATDIR		= $(MANROOT)/cat$(MANSECT)
PSRC		= MaGIC.m4 MaGIC.U
SSRC		= MaGIC1.c

all: sequential

sequential: smagic

parallel: pmagic

pmagic: MaGIC.c $(MACLIB)
	$(CC) $(CFLAGS) -DPARALLEL=$(NO_OF_PROC) -o pmagic MaGIC.c \
	      $(MACLIB) $(PARLIB) $(LOCLIB)

MaGIC.c: $(PSRC) $(MACROS)
	m4 $(MACROS) $(PSRC) > MaGIC.c

$(MACLIB):
	(cd $(MACDIR); make mplib.a)

smagic: MaGIC1.o
	$(CC) -o smagic MaGIC1.o $(LOCLIB)

install_parallel: pmagic
	install -s -c -o $(BINOWN) -g $(BINGRP) -m $(BINMODE) pmagic \
		$(BIN)/magic
	make install_help
	make install_man

install_sequential: smagic
	install -s -c -o $(BINOWN) -g $(BINGRP) -m $(BINMODE) smagic \
		$(BIN)/magic
	make install_help
	make install_man

install_help:
	- if [ ! -d $(MAGLIB) ] ; \
	  then \
	     rm -f $(MAGLIB) ; \
	     mkdir $(MAGLIB) ; \
	     chown $(MANOWN) $(MAGLIB) ; \
	     chgrp $(MANGRP) $(MAGLIB) ; \
	     chmod $(MANDMODE) $(MAGLIB) ; \
	  fi
	  ( cd ./mstuff; cp * $(MAGLIB); \
	    cd $(MAGLIB); chown $(MANOWN) *; chgrp $(MANGRP) *; \
	    chmod $(MANMODE) * )

install_man:
	install -c -m $(MANMODE) -o $(MANOWN) -g $(MANGRP) magic.man \
		$(MANDIR)/magic.$(MANSECT)
	nroff -man $(MANDIR)/magic.$(MANSECT) > $(CATDIR)/magic.$(MANSECT)
	chown $(MANOWN) $(CATDIR)/magic.$(MANSECT)
	chgrp $(MANGRP) $(CATDIR)/magic.$(MANSECT)
	chmod $(MANMODE) $(CATDIR)/magic.$(MANSECT)
	- if [ -f /dynix ] ; \
	  then \
	     compress $(MANDIR)/magic.$(MANSECT); \
	     compress $(CATDIR)/magic.$(MANSECT); \
	  fi
	
install:
	make install_sequential

clean:
	(cd $(MACDIR); make clean)
	rm -f *.o MaGIC.c core pmagic smagic magic

deinstall:
	rm -f $(BIN)/magic $(BIN)/pmagic $(BIN)/smagic
	rm -rf $(MAGLIB)
	rm -f $(MANDIR)/magic.$(MANSECT)*
	rm -f $(CATDIR)/magic.$(MANSECT)*

depend:
	echo '# DO NOT DELETE THIS LINE, MAKE DEPEND NEEDS IT' > dependencies
	for i in $(PSRC); \
	do \
	   $(CPP) -M $$i >> dependencies; \
	done
	sed 's/^MaGIC.o4*:/MaGIC.c:/' dependencies > dependencies.2
	for i in $(SSRC); \
	do \
	   $(CPP) -M $$i >> dependencies.2; \
	done
	sed '/^\# DO NOT DELETE/,$$d' Makefile > Makefile.tmp
	cat Makefile.tmp dependencies.2 > Makefile
	rm Makefile.tmp dependencies dependencies.2

# DO NOT DELETE THIS LINE, MAKE DEPEND NEEDS IT
MaGIC.c: MaGIC.m4
MaGIC.c: MaGIC.U
MaGIC.c: ./MaGIC.h
MaGIC.c: /usr/include/stdio.h
MaGIC.c: /usr/include/ctype.h
MaGIC.c: ./lid.c
MaGIC.c: ./logic.c
MaGIC.c: ./logic_io_s.c
MaGIC.c: ./logic_test.c
MaGIC.c: ./logic_set.c
MaGIC.c: ./isom.c
MaGIC.c: ./dialog.c
MaGIC.c: ./mp_parse.c
MaGIC.c: ./TR.c
MaGIC.c: ./setup.c
MaGIC1.o: MaGIC1.c
MaGIC1.o: ./MaGIC.h
MaGIC1.o: /usr/include/stdio.h
MaGIC1.o: /usr/include/ctype.h
MaGIC1.o: /usr/include/sys/types.h
MaGIC1.o: /usr/include/sys/time.h
MaGIC1.o: ./lid.c
MaGIC1.o: ./logic.c
MaGIC1.o: ./logic_io_s.c
MaGIC1.o: ./logic_test.c
MaGIC1.o: ./logic_set.c
MaGIC1.o: ./isom.c
MaGIC1.o: ./dialog.c
MaGIC1.o: ./mp_parse.c
MaGIC1.o: ./setup.c
MaGIC1.o: ./TR.c
