#
# Makefile for PolyglotMan BeOS version
# Written by Daniel Lundin <sorrowd@acc.umu.se>
#
# Based upon the original makefile by Tom Phelps
# distributed with this package as Makefile.original


### you may need to localize the paths on these lines

# The executable `rman' is placed in BINDIR.
# MANDIR holds the man page.

BINDIR = /boot/home/config/bin

# In lack of a "real" place to put the man pages in BeOS
# I just set this to something almost appropriate
MANDIR = /boot/home/config/man

# These lines are for egoistic purposes (my own dir structure)
# I provided them in case someone else shares my view on system dirs

#BINDIR = /boot/usr/local/bin
#MANDIR = /boot/usr/man

# If you have geek gadgets installed, you might want to 
# install the man page into the geek gadgets man directory
#MANDIR=$GG/man



### Use Metrowerks mwcc

CC = mwcc
CFLAGS = -O3 -inline auto

### If you wish to use gcc use the following

#CC = gcc
#CFLAGS = -O2 -finline-functions

# list of valid volume numbers and letters
# you can also set these at runtime with -V
VOLLIST = "1:2:3:4:5:6:7:8:9:o:l:n:p"

# the printf strings used to set the <TITLE> and
# to set URL hyperlinks to referenced manual pages
# can be defined at runtime.  The defaults are defined below.
# The first %s parameter is the manual page name,
# the second the volume/section number.
# you can set these at runtime with -l and -r, respectively

MANTITLEPRINTF = "%s(%s) manual page"
MANREFPRINTF = "/cgi-bin/man2html?%s&%s"


CP = cp
# or you can use GNU's cp and backup files that are about to be overwritten
#CP = cp -b
RM = rm

#--------------------------------------------------
#
# you shouldn't modify anything below here
#
#   ( Yes I should and I did ... -Daniel )
#
#--------------------------------------------------

version = "3.0.4-BeOS"
rman = rman-$(version)
srcs = rman.c getopt.c macish.c
objs = rman
defs = -DVOLLIST='$(VOLLIST)' -DMANTITLEPRINTF='$(MANTITLEPRINTF)' -DMANREFPRINTF='$(MANREFPRINTF)'
libs = 
aux = ANNOUNCE-rman README-rman README-BeOS Makefile Makefile.mac Makefile.original rman.1 rman.html CHANGES
distrib = $(srcs) $(libs) $(aux) contrib

all:  rman
	@echo 'Files made in current directory.'
	@echo 'You should "make install".'

# everyone but me zaps assertions with the -DNDEBUG flag
rman: rman.c Makefile
	$(CC) -DNDEBUG $(defs) -DPOLYGLOTMANVERSION=\"$(version)\" $(CFLAGS) -o rman rman.c
	
debug:
	$(CC) $(defs) -DDEBUG -DPOLYGLOTMANVERSION=\"debug\" -g -w all -o rman rman.c

install: rman
#	$(INSTALL) -s rman $(BINDIR)
	$(RM) -f $(BINDIR)/rman
	$(CP) rman $(BINDIR)
	$(RM) -f $(MANDIR)/rman.1
	$(CP) rman.1 $(MANDIR)/

# test version includes assertions
#	ginstall rman $(BINDIR)/`arch`
test: rman.c Makefile
	$(CC) $(defs) -DPOLYGLOTMANVERSION=\"$(version)\" $(CFLAGS)  -o rman rman.c
	ls -l rman
#	ginstall rman $(BINDIR) rman -v 
	rman --help
	@echo 'Assertion checks:'
	rman -f html rman.1 > /dev/null
#	nroff -man rman.1 | rman -f html > /dev/null
	@echo 'Test done. All well.'
	
clean:
	rm -f $(objs)

bindist: bintodist mkdist
	mv -f $(rman).tar.gz $(rman)-bin.tar.gz
	@echo "binary distribution package made"

dist: srctodist mkdist
	@echo "source-only distribution package made"

bintodist: srctodist
	$(CP) -R $(objs) $(rman)
	
srctodist:
	rm -rf $(rman)*
	mkdir $(rman)
	$(CP) -R $(distrib) $(rman)

mkdist: 
	rm -f $(rman)/contrib/*~
	@echo 'gcksum crc   length name' > MANIFEST
	@echo '----------   ------ ----' >> MANIFEST
	cksum $(filter-out contrib, $(filter-out %~, $(distrib) $(wildcard contrib/*))) | tee -a MANIFEST
	mv MANIFEST $(rman)
	tar chvf $(rman).tar $(rman)
	gzip -9v $(rman).tar 
	rm -rf $(rman)
	@echo "*** Did you remember to ci -l first?"

uu: tar
	gznew $(rman).tar.Z
	@echo 'uudecode, gunzip (from GNU), untar' > $(rman).tar.gz.uu
	uuencode $(rman).tar.gz $(rman).tar.gz >> $(rman).tar.gz.uu
