
VERSION = dev-20060722
MESSAGE = This is unstable development code

BUILD = built/argusd built/arguscgi built/argusctl built/conf.pl built/rc.argusd \
	built/graphd built/picasso built/argus-config \
	built/argus-agent built/argusvxml

TOOLS = Makefile tools/fixup built

# text files
TEXT  = README LOCATION LICENSE Artistic

# core code
LIBS_A = Alias.pm BaseIO.pm Commands.pm Conf.pm \
	Configable.pm Control.pm Cron.pm \
	Doc.pm Group.pm MonEl.pm Notify.pm \
	NotMe.pm Override.pm Server.pm Service.pm Stats.pm \
	Web.pm NullConf.pm Error.pm Argus::Ctl.pm Argus::Encode.pm \
	NullCtl.pm UserCron.pm TestPort.pm Resolv.pm \
	misc.pl localization.pl
# Service Modules
LIBS_S =  Argus::IP.pm TCP.pm UDP.pm Ping.pm Prog.pm \
	SNMP.pm Argus::BER.pm DNS.pm DNS::UDP.pm DNS::TCP.pm Self.pm \
	DataBase.pm SSL.pm Argus::Agent.pm \
	Argus::SIP.pm Argus::SIP::TCP.pm Argus::SIP::UDP.pm Argus::Asterisk.pm \
	Argus::RPC.pm Argus::RPC::UDP.pm Argus::RPC::TCP.pm

# web code
LIBS_W = web_acl.pl web_auth_file.pl web_misc.pl web_notify.pl web_override.pl \
	web_page.pl web_login.pl web_about.pl web_utils.pl web_graph.pl
# graphing code
LIBS_G = Graph.pm GraphData.pm Chart::Strip.pm
# experimental code
LIBS_X = 

LIBS  = $(LIBS_A) $(LIBS_S) $(LIBS_W) $(LIBS_G) $(LIBS_X)

FIXUP = $(PERL) tools/fixup -l "$(INSTALL_LIB)" -d "$(INSTALL_DATA)" -s "$(INSTALL_SBIN)" \
	-b "$(INSTALL_BIN)" -P "$(PERL)" -S "$(SENDMAIL)" -Q "$(QPAGE)" -F "$(FPING)" \
	-V "$(VERSION)" -D "$(DATABASE)" -g "$(HAVE_GD)" -6 "$(FPING6)" -A "$(AUTH_FILE)"

CLEAN = $(BUILD) Makefile


all: $(BUILD) message

message:
	@echo
	@echo build of argus version $(VERSION) complete
	@if test '$(MESSAGE)'; then echo '==>' $(MESSAGE); fi
	@echo now run \'make install\'

install-message:
	@echo
	@echo install of argus version $(VERSION) complete
	@if test '$(MESSAGE)'; then echo '==>' $(MESSAGE); fi

built:
	-mkdir built

built/argusd: $(TOOLS) src/main.pl
	$(FIXUP) src/main.pl > built/argusd
	chmod a+x built/argusd

built/arguscgi: $(TOOLS) src/cgi
	$(FIXUP) src/cgi > built/arguscgi
	chmod a+x built/arguscgi

built/argusvxml: $(TOOLS) src/vxml
	$(FIXUP) src/vxml > built/argusvxml
	chmod a+x built/argusvxml

built/argusctl: $(TOOLS) src/argusctl
	$(FIXUP) src/argusctl > built/argusctl
	chmod a+x built/argusctl

built/rc.argusd: $(TOOLS) src/rc.argusd
	$(FIXUP) src/rc.argusd > built/rc.argusd
	chmod a+x built/rc.argusd

built/conf.pl: $(TOOLS) src/conf.pl
	$(FIXUP) src/conf.pl > built/conf.pl

built/graphd: $(TOOLS) src/graphd.pl
	$(FIXUP) src/graphd.pl > built/graphd
	chmod a+x built/graphd

built/picasso: $(TOOLS) src/picasso.pl
	$(FIXUP) src/picasso.pl > built/picasso
	chmod a+x built/picasso

built/argus-config: $(TOOLS) src/argus-config
	$(FIXUP) src/argus-config > built/argus-config
	chmod a+x built/argus-config

built/argus-agent: $(TOOLS) src/sys_agent.pl
	$(FIXUP) src/sys_agent.pl > built/argus-agent
	chmod a+x built/argus-agent

Makefile:
	@echo Maybe run Configure\?

clean:
	-rm $(CLEAN)

install: install-lib install-prog install-conf remove-auth $(INSTALL_DATA) \
	$(INSTALL_DATA)/gdata $(INSTALL_DATA)/perl install-locale install-message

install-lib:
	-mkdir -p $(INSTALL_LIB)
	$(PERL) tools/install_lib -s src -l $(INSTALL_LIB) $(LIBS)
	cp $(TEXT) $(INSTALL_LIB)

install-prog:
	-mkdir -p $(INSTALL_SBIN)
	-mkdir -p $(INSTALL_BIN)
	cp built/argusd   $(INSTALL_SBIN)
	cp built/argusctl $(INSTALL_SBIN)
	cp built/arguscgi $(INSTALL_SBIN)
	cp built/graphd   $(INSTALL_LIB)
	cp built/picasso  $(INSTALL_LIB)
	cp built/argus-config $(INSTALL_BIN)
	cp built/argus-agent  $(INSTALL_SBIN)
	cp built/argusvxml    $(INSTALL_SBIN)

# in case the format of the auth file has changed
remove-auth:
	@if test -f $(INSTALL_DATA)/auth; then rm $(INSTALL_DATA)/auth; fi

# this only happens if there isn't already a data dir
# if the user is upgrading, we leave it all alone
# while a+rwx may be not be optimal security-wise,
# it reduces the amount of support email the author receives
$(INSTALL_DATA):
	mkdir -p $(INSTALL_DATA)/stats $(INSTALL_DATA)/html $(INSTALL_DATA)/notify
	touch $(INSTALL_DATA)/log
	$(PERL) -e 'print getppid, "\n"' > $(INSTALL_DATA)/notno
	chmod a+rwx $(INSTALL_DATA)
	chmod a+r $(INSTALL_DATA)/html $(INSTALL_DATA)/log
	@echo ''
	@echo creating example files...
	@sleep 1
	@cp examples/users  $(INSTALL_DATA)/users.example
	@cp examples/config $(INSTALL_DATA)/config.example
	@echo ''
	@echo '***' you will need to create/edit the files \'$(INSTALL_DATA)/config\' 
	@echo '***      ' and \'$(INSTALL_DATA)/users\'
	@echo '***' be sure to check permissions on \'$(INSTALL_DATA)\' and its contents
	@echo ''

# if this is an upgrade, gdata might not exist even though data does
$(INSTALL_DATA)/gdata: $(INSTALL_DATA)
	if test ! -d $(INSTALL_DATA)/gdata;  then mkdir $(INSTALL_DATA)/gdata;  \
		chmod a+rwx $(INSTALL_DATA)/gdata;  fi
	if test ! -d $(INSTALL_DATA)/gcache; then mkdir $(INSTALL_DATA)/gcache; \
		chmod a+rwx $(INSTALL_DATA)/gcache; fi

$(INSTALL_DATA)/perl: $(INSTALL_DATA)
	if test ! -d $(INSTALL_DATA)/perl;  then \
		mkdir $(INSTALL_DATA)/perl;  \
		chmod a+rwx $(INSTALL_DATA)/perl;  \
	fi

install-locale: $(INSTALL_DATA)
	if test ! -d $(INSTALL_DATA)/locale; then \
		mkdir $(INSTALL_DATA)/locale; \
		chmod a+rx $(INSTALL_DATA)/locale;  \
	fi
	cp locale/* $(INSTALL_DATA)/locale \

install-conf:
	cp built/conf.pl  $(INSTALL_LIB)

HTML/config-details.html: $(BUILD)
	built/argusd -DH > HTML/config-details.html

HTML/debug-details.html: $(BUILD)
	built/argusd -EH > HTML/debug-details.html

love:
	@echo not war

