
srcdir = @srcdir@
VPATH = @srcdir@

CC = @CC@
CFLAGS = @CFLAGS@
USER_DEFS = @DEFS@
INSTALL = @INSTALL@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

#
# DESTDIR NOTE:
# At build time:    DESTDIR has _nothing_ to do with the paths used.
# At install time:  All paths are relative to DESTDIR.
#
# This lets you make a test installation by doing "make DESTDIR=/xyz install",
# and then visually verifying that all files are correctly located
# w.r.t. DESTDIR and have correct permissions.  This is also useful for
# generating an RPM.
# However, since the compiled-in paths _never_ include DESTDIR, a
# correctly functioning install for runtime use must do simply "make install".
#
DESTDIR=

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir=@bindir@
sysconfdir = @sysconfdir@
localstatedir = @localstatedir@
mandir = @mandir@

#
# Where the super(1) binary is installed
#
BINDIR = $(bindir)

#
# Name of the timestamps directory
#
TIMESTAMP_DIR=$(localstatedir)/super/timestamps
D_TIMESTAMP_DIR=-DTIMESTAMP_DIR=\"$(TIMESTAMP_DIR)\"

#
# Where the super.tab and super.init files are installed:
#
SUPERDIR=$(sysconfdir)
D_SUPERDIR=-DSUPERDIR=\"$(SUPERDIR)\"

#
# If your system supports "const", define D_CONST to be "", but if
# your system doesn't support "const", define D_CONST to be "-Dconst=".
# (When used in CFLAGS, it will define away the const keyword for
# systems that don't support it, but have no effect on those that do.)
#
D_CONST=@ConstDef@

#
#
# Where the user man page is placed.
#
MAN1DIR = $(mandir)/man1
# Do _not_ include a leading dot in the extension!
MAN1EXT = 1

#
# Where the man page for the super.tab file is placed.
#
MAN_FORMAT_DIR = $(mandir)/man5
# Do _not_ include a leading dot in the extension!
MAN_FORMAT_EXT = 5

# SYSLOG_PRIORITY specifies the priority of syslog messages.
#	If you don't define it, the default is LOG_ERR.
#	(Regardless of this setting, _successful_ executions are logged
#	at priority LOG_INFO.)

#	If you are using standard syslog(), you may define it symbolically,
#	for example:
#		-DSYSLOG_PRIORITY=LOG_ERR
#	or
#		-DSYSLOG_PRIORITY="(LOG_LOCAL1 | LOG_WARNING)"

#	But if you are using rsyslog(), you should define it differently:
#	its value depends on the machine which will _receive_ the log
#	messages, NOT the sending machine.  It should be defined in the
#	Makefile because the value can differ on the machine that compiles
#	and runs super, compared to the value on the log host.

#	For example, if your receiving machine is a Sun running SunOS 4.1.3,
#	or HP-UX 8.x or 9.x, using -DSYSLOG_PRIORITY='((17<<3)+4)' will set
#	the priority of the networked syslog to the facility LOG_LOCAL1, with
#	the priority LOG_WARNING.  The log machine should have a line that
#	matches this in its syslog.conf file; for the above priority, use
#	an entry like:
#		/etc/syslog.conf:local1.warning        /var/adm/super.log
#
SYSLOG_PRIORITY=LOG_ERR
D_SYSLOG_PRIORITY=-DSYSLOG_PRIORITY=$(SYSLOG_PRIORITY)


# Even if this system is PAM-capable, don't use unless WITH_PAM is defined.
D_WITH_PAM=-DWITH_PAM=@with_pam@


BASIC_DEFS = $(D_SUPERDIR) $(D_TIMESTAMP_DIR) $(D_SYSLOG_PRIORITY) $(D_CONST) $(D_WITH_PAM)

#
# ###################################################################
# You probably don't have to edit anything below here.
# ###################################################################
#
COMPILE = $(CC) -c $(BASIC_DEFS) $(USER_DEFS) -I. $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(LDFLAGS) -o $@
 
.SUFFIXES:
.SUFFIXES: .c .o .in
.c.o:
	$(COMPILE) $<

.in:
	sed -e 's!@SUPERDIR@!$(SUPERDIR)!g' \
	    -e 's!@SAFE_PATH@!@SafePath@!g' \
	    -e 's!@TIMESTAMP_DIR@!$(TIMESTAMP_DIR)!g' < $< > $@

  
####################################################################
# You really shouldn't have to modify anything below this line.
####################################################################

MOST_SRC= $(SUPER_SRC) $(SETUID_SRC)

SUPER_C_SRC = super.c approve.c checks.c colon.c braces.c error.c \
	getpass.c gsgroups.c s_hsearch.c options.c pam.c \
	p_regex.c s_regex.c s_re_fail.c rsyslog.c \
	strqtokS.c time.c utils.c wildmat.c

SUPER_H_SRC = s_hsearch.h version.h options.h super.h

SUPER_SRC = $(SUPER_C_SRC) $(SUPER_H_SRC)

SETUID_SRC = setuid.c

SUPER_OBJ= super.o approve.o checks.o colon.o braces.o error.o \
	getpass.o gsgroups.o s_hsearch.o options.o \
	p_regex.o s_regex.o s_re_fail.o rsyslog.o \
	strqtokS.o time.o utils.o wildmat.o @LIBOBJS@

# Files that go into the shar file.  The files after $(MOST_SRC)
# are those that are conditionally compiled via the configure-substituted
# LIBOBJS.
ALL= README README.Y2K INSTALL INSTALL.notes Artistic Copying WhatsNew \
	configure configure.in install-sh localsys.h mkdir_p \
	Makefile.in super.1.in super.5.in config.h.in \
	setuid.1.in super.spec.in barebones.tab \
	sample.tab sample.cdmount sample.cdumount \
	$(MOST_SRC) misc_conv.c pam_misc.h

all: config.h super setuid super.1 super.5 setuid.1

super: config.h $(SUPER_OBJ)
	$(CC) $(LDFLAGS) -o super $(SUPER_OBJ) $(LIBS)

debug: config.h $(SUPER_OBJ)
	$(CC) $(LDFLAGS) -o super $(SUPER_OBJ) $(LIBS) /usr/lib/debug/malloc.o

setuid: setuid.o
	$(CC) $(LDFLAGS) -o setuid setuid.o

config.h:
	@echo "'config.h' doesn't exist or is out of date compared to config.h.in..."
	@echo "You must run './configure' to generate config.h."
	@echo "If you are making 'super' for the first time on this system,"
	@echo "you should probably do a 'make veryclean' before executing ./configure."
	@exit 1

cflow:
	cflow $(SUPER_C_SRC) > cflow.out
	cflow -r $(SUPER_C_SRC) > cflow.rev

# NOTICE NOTICE NOTICE!
# You must install super as "super", and not use any other program name.
# This is because at run-time, the program assumes that if it's invoked
# with a different name, it must have been invoked via a symlink, and
# it treats
#	% myothernameforsuper args
# as if you typed
#	% super myothernameforsuper args
# If you insist on installing under another name, then you must
# change the #define ONETRUENAME from "super" to your other
# name, and edit the documentation to match.
install: install-bin install-man


install-bin: super setuid
	./mkdir_p -p755 $(DESTDIR)/$(BINDIR)
	./mkdir_p -p755 $(DESTDIR)/$(localstatedir)
	./mkdir_p -p755 $(DESTDIR)/$(sysconfdir)
	./install-sh -c -o root -m 04755 super $(DESTDIR)/$(BINDIR)/super
	./install-sh -c -o root -m  0755 setuid $(DESTDIR)/$(BINDIR)/setuid
	test -f $(DESTDIR)/$(sysconfdir)/super.tab && \
	    echo "Not overwriting existing file $(DESTDIR)/$(sysconfdir)/super.tab" || \
	    ./install-sh -c -o root -m  0644 barebones.tab \
		$(DESTDIR)/$(sysconfdir)/super.tab

install-man: super.1 setuid.1 super.5
	./install-sh -c -o root -m  0644 super.1 \
		$(DESTDIR)/$(MAN1DIR)/super.$(MAN1EXT)
	./install-sh -c -o root -m  0644 setuid.1 \
		$(DESTDIR)/$(MAN1DIR)/setuid.$(MAN1EXT)
	./install-sh -c -o root -m  0644 super.5 \
		$(DESTDIR)/$(MAN_FORMAT_DIR)/super.$(MAN_FORMAT_EXT)

clean:
	-rm -f super setuid *.o

distclean veryclean: clean
	-rm -f super.1 super.5 setuid.1 config.h config.cache config.status config.log

$(ALL): 
	co $@

tellversion: version.h
	( echo "#include <stdio.h>" ; \
	echo '#include "version.h"' ; \
	echo 'main() {printf("%s.%s",Version,Patchlevel);exit(0);}') > temp.c
	$(CC) -o tellversion temp.c
	rm temp.c

# Because of the wide variation in shar commands, the shar arguments
# used below sticks to a minimal set, and we generate various shar file
# headers by hand.  
shar super.shar: $(ALL) tellversion
	V=super-`./tellversion`; mkdir $$V && cp $(ALL) $$V && \
	    (echo "Submitted-by: will@ucolick.org" ; \
	    echo "Archive-name: $$V/part01" ; echo "" ; \
	    echo "---- Cut Here and feed the following to sh ----" ; \
	    shar $$V ) > super.shar && rm -rf $$V && cp -p super.shar $$V.shar

tar super.tar: $(ALL) tellversion
	V=super-`./tellversion`; mkdir $$V && cp $(ALL) $$V && \
	    tar -cf super.tar $$V && rm -rf $$V

# Make both super.tgz and copy it to the version'd -tar.gz form that
# rpm wants.
tgz super.tgz: $(ALL) tellversion
	V=super-`./tellversion`; mkdir $$V && cp $(ALL) $$V && \
	    gtar -czf super.tgz $$V && rm -rf $$V && cp -p super.tgz $$V-tar.gz

# Create an RPM spec file.  Note that super.spec is copied to a
# versioned .spec file of the form wanted by rpm.  (The non-versioned
# form gives us a simple makefile targett.)
spec super.spec: super.spec.in tellversion
	sed -e "s!@version@!`./tellversion`!" super.spec.in > super.spec
	cp -p super.spec super-`./tellversion`-`./rpmrelease`.spec

#
# Only invoke this if you want to create source and binary rpm's from
# this source tree.
#
# To create rpm's: set rpmdir to the directory tree (e.g.  /usr/src/redhat)
# in which you want to create the RPM's.
rpmdir=/u/will/myrpm
rpm: super.tgz super.spec tellversion
	cp super-`./tellversion`-`./rpmrelease`.spec $(rpmdir)/SPECS
	cp super-`./tellversion`-tar.gz $(rpmdir)/SOURCES
	rpmbuild -ba --buildroot /var/tmp/super-`./tellversion` \
	    $(rpmdir)/SPECS/super-`./tellversion`-`./rpmrelease`.spec

depend:
	makedepend -- $(CFLAGS) -- $(SRC)

