# $Id: Makefile,v 1.13 1999/03/16 18:51:56 alinden Exp $
# Makefile for ucron

SHELL = /bin/sh
CC=gcc
CFLAGS = -Wall -Wstrict-prototypes -O2 -pipe

# Probably change PREFIX to /usr/local to avoid overwriting 
# existing crond
PREFIX = /usr
BINDIR  = $(PREFIX)/bin
SBINDIR = $(PREFIX)/sbin
MANDIR  = $(PREFIX)/man

# Docfiles
DOCDIR  = /usr/doc/crond

# PID file
PIDFILE = /var/run/ucrond.pid

# The time information will be stored here 
TIMEFILE = /var/log/uptime

# Directory for crontab files
CRONTABS = /var/lib/crontabs

# Mail command
SENDMAIL = /usr/lib/sendmail -i

# Allowed number of entries for user crontabs (environment and commands)
UTABMAX = 200

# Delay for program execution after reboot in seconds.
BDELAY = 15

# Reduce the relative process priority for commands executed
# from root crontab. A higher number means a lower priority.
RTABNICE = 5

# Reduce the relative process priority for commands executed
# from user crontabs.
UTABNICE = 10

# Default timeout for command queue in seconds
DQTMOUT = 180

# Name of the default crontab file for root. Assignment of
# a different name makes it possible to keep a separate crontab
# for root or make one of them a symbolic link to /etc/crontab.
NCTROOT = crontab.main

# Default editor
EDITOR = /usr/bin/vi

# Default PATH environment
DPATH = /bin:/sbin:/usr/bin:/usr/sbin

# Update TIMEFILE if no job was executed within n minutes.
PERIOD = 15

# Nothing to edit after this line

BINARIES = crond dtime crontab 
DISTFILES= Makefile COPYING CHANGES README build.c crontab.c daemon.c main.c dtime.c \
           socket.c queue.c parser.c cronlog.pl crond.8.in crontab.1.in dtime.1.in crond.h \
           extern.h runparts.sample crontab.sample
DVERSION = 1.2.4
SERVDIR  = $(CRONTABS)/@cron
STRVARS = 'DPATH "$(DPATH)"' 'PIDFILE "$(PIDFILE)"' 'TIMEFILE "$(TIMEFILE)"' \
          'CRONTABS "$(CRONTABS)"' 'SENDMAIL "$(SENDMAIL)"' 'EDITOR "$(EDITOR)"' \
          'SERVDIR "$(SERVDIR)"' 'SERVCTRL "$(SERVDIR)/control"' 'SERVPERM "$(SERVDIR)/permissions"' \
          'SERVREST "$(SERVDIR)/restart"' 'NCTROOT "$(NCTROOT)"' 'VERSION "$(DVERSION)"' \
          "UTABMAX $(UTABMAX)" "BDELAY $(BDELAY)" "RTABNICE $(RTABNICE)" \
          "UTABNICE $(UTABNICE)" "DQTMOUT $(DQTMOUT)" "PERIOD $(PERIOD)"
MANVARS = DVERSION CRONTABS PERIOD TIMEFILE EDITOR SERVDIR DOCDIR BDELAY DQTMOUT UTABMAX
manvals := $(foreach i, $(MANVARS), -e s%@$(i)@%$($(i))%g)

.SUFFIXES: .c .o

all: config $(BINARIES) manpages

manpages: Makefile
	for m in crond.8 crontab.1 dtime.1 ; do sed $(manvals) < $${m}.in > $${m} ; done ; \
	touch manpages

conf.h:
config: Makefile conf.h 
	echo -e "/* Created by Makefile */\n" > conf.h ; \
	for CNF in $(STRVARS) ; do echo "#define" $${CNF} >> conf.h ; done ; \
	touch config

clean:
	rm -f $(BINARIES) *.o conf.h config manpages *.[1-8] core

dist:   
	d=ucrond-$(DVERSION) ; \
	rm -f ../$${d}.tar.gz ; \
	cd .. ; \
	ln -s ucrond $${d} ; \
	files="" ; \
	for f in $(DISTFILES); do files="$${files} $${d}/$${f}"; done ; \
	tar cvzhf $${d}.tar.gz $${files} ; \
	rm $${d}

# Binaries

crond: daemon.o socket.o queue.o parser.o build.o main.o 
	$(CC) -o $@ daemon.o socket.o queue.o parser.o build.o main.o
dtime: dtime.o
	$(CC) -o $@ dtime.o	
crontab: crontab.o
	$(CC) -o $@ crontab.o	

depend: 
	makedepend *.c 2> /dev/null	

install: all
	install -o root -s ./crond    $(SBINDIR)/crond
	install -o root -s ./dtime    $(BINDIR)/dtime
	install -o root -s -m 4555 ./crontab  $(BINDIR)/crontab
	
	install -o root -m 0644 ./crond.8     $(MANDIR)/man8/crond.8
	install -o root -m 0644 ./crontab.1   $(MANDIR)/man1/crontab.1
	install -o root -m 0644 ./dtime.1     $(MANDIR)/man1/dtime.1
	
	mkdir -p $(DOCDIR)
	install -o root -m 0644 ./README   $(DOCDIR)/README
	install -o root -m 0644 ./Makefile $(DOCDIR)/Makefile
	install -o root -m 0644 ./crontab.sample $(DOCDIR)/crontab.sample 
	mkdir -p $(CRONTABS)

