#
# $Id: Makefile.in,v 1.2.2.1 2000/10/08 03:16:25 lha Exp $
#

SHELL = /bin/sh

srcdir = @srcdir@
VPATH = @srcdir@

CC = @CC@
AR = ar
RANLIB = @RANLIB@
DEFS = @DEFS@
CFLAGS = @CFLAGS@
YACC = @YACC@
LEX = @LEX@
LN_S = @LN_S@

INSTALL = @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@
MKINSTALLDIRS = @top_srcdir@/mkinstalldirs

prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = @libdir@
bindir = @bindir@
mandir = @mandir@
includedir = @includedir@

LIBPREFIX = lib
LIBEXT = a
LIBNAME = $(LIBPREFIX)cmd
cmd_LIB = $(LIBNAME).$(LIBEXT)

testc_BIN = testc
testc_1_MAN = testc.1

PROGS = $(testc_BIN)
install_MANS = cmd.3
MANS = $(testc_1_MAN) $(install_MANS)

LIB_SOURCES = cmd.c
testc_SOURCES = testc.c

SOURCES = $(LIB_SOURCES) $(BIN_SOURCES)

LIB_OBJECTS = cmd.o
testc_OBJECTS = testc.o

OBJECTS = $(LIB_OBJECTS) $(testc_OBJECTS)

all: $(cmd_LIB) $(PROGS) $(MANS)

Wall:
	make CFLAGS="-g -Wall -Wno-comment -Wmissing-prototypes -Wmissing-declarations -D__USE_FIXED_PROTOTYPES__"

.c.o:
	$(CC) -c $(DEFS) -I../../include -I. -I$(srcdir) $(KRB4_INC_FLAGS) $(CFLAGS) $(CPPFLAGS) $(PICFLAGS) $<

install: all
	$(MKINSTALLDIRS) $(DESTDIR)$(includedir)/afs
	$(INSTALL_DATA) $(srcdir)/cmd.h $(DESTDIR)$(includedir)/afs/cmd.h
	$(MKINSTALLDIRS) $(DESTDIR)$(libdir)
	$(INSTALL) -m 555 $(cmd_LIB) $(DESTDIR)$(libdir)/$(cmd_LIB)
	for man in $(install_MANS) ; do \
		for a in 1 2 3 4 5 6 7 8 9 0 ; do \
			if test `basename $$man .$$a`.$$a = $$man; then \
				if test -f $$man ; then \
					man_inst=$$man ; \
				else \
					man_inst=$(srcdir)/$$man; \
				fi ;\
				$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man$$a; \
				$(INSTALL_DATA) $$man_inst $(mandir)/man$$a/$$man; \
			fi ; \
		done ; \
	done

uninstall:
	rm -f $(DESTDIR)$(includedir)/afs/cmd.h
	rm -f $(DESTDIR)$(libdir)/$(cmd_LIB)
	for man in $(install_MANS) ; do \
		for a in 1 2 3 4 5 6 7 8 9 0 ; do \
			if test `basename $$man .$$a`.$$a = $$man; then \
				rm -f $(DESTDIR)$(mandir)/man$$a/$$man ; \
			fi ; \
		done ; \
	done

TAGS: $(SOURCES)
	etags $(SOURCES)

check:

clean:
	rm -f $(cmd_LIB) $(PROGS) $(testc_1_MAN) *.o *.a

mostlyclean: clean

distclean: clean
	rm -f Makefile *~

realclean: distclean
	rm -f TAGS

$(LIBNAME).a: $(LIB_OBJECTS)
	rm -f $@
	$(AR) cr $@ $(LIB_OBJECTS)
	-$(RANLIB) $@

testc: $(testc_OBJECTS) $(cmd_LIB)
	$(CC) $(CFLAGS) -o $@ $(testc_OBJECTS)  -L. -lcmd -L../roken -lroken

testc.1: testc
	srcdir=$(srcdir) CMD_MANDOC=foo ./testc help > testc.1

Makefile:	Makefile.in ../../config.status
	cd ../..; CONFIG_FILES=lib/cmd/Makefile CONFIG_HEADERS= $(SHELL) config.status

$(OBJECTS): ../../include/config.h

.PHONY: all Wall install uninstall check clean mostlyclean distclean realclean
