# 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 go in here
DOCDIR  = /usr/doc/crond

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

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

# Directory containing 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 = 30

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

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

# Default timeout for command queue in seconds
DQTMOUT = 3*60

# Name of the crontab file for root. Giving it another name
# makes it possible to keep a separate user crontab for root
# or make 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

# Time period to update TIMEFILE in minutes (can be changed with 
# the -u option).This file will also be updated during termination 
PERIOD = 30

# Nothing to edit after this line

BINARIES = crond dtime crontab 
DISTFILES= Makefile COPYING README build.c crontab.c daemon.c main.c dtime.c \
           pipe.c cronlog.pl crond.8 crontab.1 dtime.1 crond.h extern.h crontab.sample
DVERSION = 1.1.0
STRVARS = 'PIDFILE "$(PIDFILE)"' 'TIMEFILE "$(TIMEFILE)"' 'CRONTABS "$(CRONTABS)"' \
          'SENDMAIL "$(SENDMAIL)"' 'EDITOR "$(EDITOR)"' 'NCTROOT "$(NCTROOT)"' \
          'VERSION "$(DVERSION)"' \
          "UTABMAX $(UTABMAX)" "BDELAY $(BDELAY)" "RTABNICE $(RTABNICE)" \
          "UTABNICE $(UTABNICE)" "DQTMOUT $(DQTMOUT)" "PERIOD $(PERIOD)" 

.SUFFIXES: .c .o

all: config $(BINARIES)

config: Makefile
	echo "#define DPATH" '"PATH=$(DPATH)"' > conf.h 
	
	for CNF in $(STRVARS) ; do  \
		echo "#define" $${CNF} >> conf.h ; \
	done

	touch config

clean:
	rm -f $(BINARIES) *.o core

distclean: clean
	rm -f conf.h config

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

# Binaries

crond: daemon.o pipe.o build.o main.o 
	$(CC) -o $@ daemon.o pipe.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: config $(BINARIES)
	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)

