#
# Country Codes Makefile
#

#
# Modify this, if you need to and if you know what you are doing.
#

srcdir = .

prefix = /usr/local
bindir = ${prefix}/bin
docdir = ../doc

mandir = ${prefix}/man/man1

# For system that doesn't support mkdir -p.
# If you have Linux, don't bother.

MKDIRECTORY = mkdir -p

# Mode for user binaries
BINMODE=755

# Mode for the log directory
LOGDIRMODE=700

# Compiler to use
CC=gcc

# Compiler warnings
WARNINGS= -pedantic -Wall

# Compiler flags
CCOPTS = -O2 -fomit-frame-pointer

# The makefile standards document I read says that I have to put it here...
SHELL = /bin/sh

# Clear and set suffixes 
.SUFFIXES:
.SUFFIXES: .c .o

# Install program
INSTALL = install

# Miscellaneous
COCO_VERSION = 1.0.5
RELEASEDATE  = February 2003

# Location of sed
SEDBIN  = sed

# sed command
SEDCMDS = "s/@version@/$(COCO_VERSION)/g;s/@releasedate@/$(RELEASEDATE)/g"

ISO3166OBJ = iso3166.o common.o

PROGRAM = iso3166

all: $(PROGRAM)

$(PROGRAM): $(ISO3166OBJ)
	$(CC) $(CCOPTS) $(ISO3166OBJ) -o $@

clean:
	rm -f $(ISO3166OBJ) core defines.h $(PROGRAM)

strip:
	strip $(PROGRAM)

install:
	$(INSTALL) -g root -m $(BINMODE) -o root -s ${srcdir}/$(PROGRAM) ${bindir}
	@echo "Installing man page..."
	@$(SEDBIN) $(SEDCMDS) ${docdir}/iso3166.1.in > ${mandir}/iso3166.1
	@chown 0.0 ${mandir}/iso3166.1
	@echo

uninstall:
	rm -f ${bindir}/$(PROGRAM)
	rm -f ${mandir}/iso3166.1

.c.o:
	$(CC) $(CCOPTS) $(WARNINGS) -c $<

$(ISO3166OBJ): common.h defines.h protos.h tables.h

defines.h:
	@echo "Creating file \"defines.h\""
	@echo "/*"                                                           >> $(srcdir)/defines.h
	@echo "   Global #defines for Country Codes"                         >> $(srcdir)/defines.h
	@echo "   Copyright (C) 1999, 2000 Diego Javier Grigna <diego@grigna.com>" >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "   File automatically created by the Makefile."               >> $(srcdir)/defines.h
	@echo "   Do not edit by hand, modify the Makefile instead."         >> $(srcdir)/defines.h
	@echo "*/"                                                           >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define COCO_VERSION    \"$(COCO_VERSION)\""                  >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h

