#
# @(#) $Id: Makefile 2 2022-02-25 17:44:09Z perette $
#

CXXFLAGS = -Wall -g
INSTALL = /usr/local
INITDIR= /etc/rc.d/init.d
RC2DIR = /etc/rc.d/rc2.d
RC3DIR = /etc/rc.d/rc3.d
RC5DIR = /etc/rc.d/rc5.d
LIBS=

ifndef X10MANAGER
X10MANAGER:=x10
endif

DEBUG=-g

all: x10iod.o x10io.o x10map.o settings.o twoway.o cp290.o
	$(CXX) $(DEBUG) -o x10iod x10iod.o x10io.o x10map.o settings.o \
	twoway.o cp290.o $(LIBS)

print:
	echo $(INITDIR)

installroot: all
	@ # We use numeric group ID because Linux uses 'root' and BSD 'wheel'
	install -d -o root -g 0 -m 0755 $(INSTALL)/bin
	install    -o root -g $(X10MANAGER) -m 0750 -s x10iod $(INSTALL)/bin/x10iod
	install -d -o root -g 0 -m 0755 $(INSTALL)/man
	install -d -o root -g 0 -m 0755 $(INSTALL)/man/man1
	install    -o root -g 0 -m 0440 x10iod.1 $(INSTALL)/man/man1/x10iod.1
	install -d -o root -g 0 -m 0755 $(INSTALL)/man/man5
	install    -o root -g 0 -m 0440 x10event.5 $(INSTALL)/man/man5/x10event.5

install:
	@ # If we don't specify owner/group, current user is used.
	install -d -m 0744 ~/bin
	install -m 0750 -b ../contrib/x10rotate ~/bin/x10rotate
	install -d -m 0744 ~/Logs
	install -d -m 0744 /var/lock/x10

templates:
	@ [ ! -s ~/x10event ] || echo "NOTE: Not overwriting x10event."
	@ [ -s ~/x10event ] || install -m 0740 x10event ~/x10event
	@ [ ! -s ~/x10iod.ini ] || echo "NOTE: Not overwriting x10iod.ini."
	@ [ -s ~/x10iod.ini ] || install -m 0640 x10iod.ini ~/x10iod.ini
	@ ! crontab -l >/dev/null || echo "NOTE: Not overwriting existing crontab."
	@ crontab -l >/dev/null || crontab x10cron

uninstallroot:
	rm -f $(INSTALL)/bin/x10iod
	rm -f $(INSTALL)/man/man1/x10iod.1 $(INSTALL)/man/man5/x10event.5

uninstall:
	crontab -u x10 -r
	rm -f ~/x10iod.ini ~/x10event
	rm -f ~/bin/action ~/bin/x10rotate
	rm -rf ~/Logs
	rm -f /var/lock/x10 

clean:
	rm -f core a.out x10iod *.o
	rm -rf SunWS_cache


