#
#   @(#)$Id: makefile,v 1.6 1996/12/22 03:48:05 steve Exp steve $
#
#   cddbd - CD Database Protocol Server
#
#   Copyright (C) 1996  Steve Scherf
#   Email: steve@moonsoft.com
#   Moondog Software Productions - makers of fine public domain software.
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

CMD =    cddbd.exe
SRC =    cddbd.c crc.c db.c encode.c fuzzy.c help.c inet.c mail.c xmit.c os2.c
OBJ =    cddbd.o crc.o db.o encode.o fuzzy.o help.o inet.o mail.o secure.o \
	 xmit.o os2.o
HDR =    cddbd.h crc.h list.h patchlevel.h
GHDR =	 access.h
GSRC =	 secure.c
GEN =    $(GHDR) $(GSRC)
SCRIPT = config.sh install.sh
TEXT =   CDDBPROTO CDDBD_HOWTO COPYING DBFORMAT README
MISC =   access.hdr Imakefile makefile passwd.hdr sites.hdr
MANIFEST=MANIFEST

CFLAGS = -O $(OSCFLAGS)
LDFLAGS = $(OSLDFLAGS)

# SVR4-derived systems might need these libraries
#LDFLAGS = -lnsl -lsocket
LDFLAGS = -lsocket

# HPUX requires special flags for to make the compiler ANSI
#OSFLAGS = -Ae

CDDBDVER = cddbd-1.4.b41

all: $(CMD)

$(CMD):	$(OBJ)
	$(CC) $(CFLAGS) -o $(CMD) $(OBJ) $(LDFLAGS)
	@echo You must run install.sh to install the new server.

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

clean:
	rm -rf $(OBJ) $(GEN) $(CDDBDVER)

lint:
	lint $(SRC) $(GSRC)

touch:
	touch $(SRC) $(GSRC)

tags:
	ctags $(SRC) $(HDR) $(GEN)

tar:
	# Make the tar directory.
	-rm -rf $(CDDBDVER)
	mkdir $(CDDBDVER)
	cp $(SRC) $(HDR) $(SCRIPT) $(TEXT) $(MISC) $(CDDBDVER)

	# Create a dummy manifest.
	touch $(CDDBDVER)/$(MANIFEST)
	chmod 444 $(CDDBDVER)/*

	# Create the second dummy manifest, which should be the correct size.
	rm -f $(MANIFEST)
	cp $(MANIFEST).hdr $(MANIFEST)
	ls -l $(CDDBDVER) | grep -v total >> $(MANIFEST)
	chmod 644 $(CDDBDVER)/$(MANIFEST)
	cp $(MANIFEST) $(CDDBDVER)
	chmod 444 $(CDDBDVER)/*

	# Create the real manifest.
	cp $(MANIFEST).hdr $(MANIFEST)
	ls -l $(CDDBDVER) | grep -v total >> $(MANIFEST)
	chmod 644 $(CDDBDVER)/$(MANIFEST)
	cp $(MANIFEST) $(CDDBDVER)

	# Create the tar file.
	chmod 444 $(CDDBDVER)/*
	chmod 755 $(CDDBDVER)
	tar cvf $(CDDBDVER).tar $(CDDBDVER)

gzip: tar
	gzip -c9 $(CDDBDVER).tar > $(CDDBDVER).tar.gz

uu: tar
	gzip -c9 $(CDDBDVER).tar > $(CDDBDVER).tar.gz
	uuencode $(CDDBDVER).tar.gz $(CDDBDVER).tar.gz > $(CDDBDVER).uu

size:
	wc $(SRC) $(HDR)

ci:
	ci $(TEXT) $(HDR) $(MISC) $(SCRIPT) $(SRC) $(MANIFEST).hdr

co:
	co -l $(TEXT) $(HDR) $(MISC) $(SCRIPT) $(SRC) $(MANIFEST).hdr

# Header dependencies
cddbd.o: access.h cddbd.h crc.h list.h patchlevel.h
crc.o: cddbd.h crc.h list.h
db.o: cddbd.h list.h patchlevel.h
encode.o: cddbd.h list.h
fuzzy.o: cddbd.h list.h
help.o:
inet.o: access.h cddbd.h list.h patchlevel.h
mail.o: cddbd.h crc.h list.h
secure.o:
xmit.o: cddbd.h list.h
