SHELL	= /bin/sh
MAKE	= make
RPCGEN	= rpcgen
PID     = `echo $$`
what:
	@echo "Usage: make system-type. Known types are:"

	@echo "    aix osf bsd bsdi dgux irix4 irix freebsd" 
	@echo "    hpux9 hpux linux linux-nansi sunos4 sunos5 trusted-sunos5 sysv4"

	@echo
	@echo "Maintenance: make clean, make distclean"

aix osf bsd hpux9 sunos4:
	@$(MAKE) all LIBS= XFLAGS="-DGETGROUPS_T=int"

hpux:
	@$(MAKE) all LIBS="-lrpcsvc" XFLAGS="-DGETGROUPS_T=int"

ultrix4:
	@$(MAKE) rpcgen all LIBS= XFLAGS="-DGETGROUPS_T=int" \
		RPCGEN="../../bin/rpcgen"

bsdi:
	@$(MAKE) all LIBS="-lrpc" XFLAGS="-DGETGROUPS_T=int"

freebsd:
	@$(MAKE) all LIBS= XFLAGS="-DGETGROUPS_T=int -DSYS_ERRLIST_DECLARED"

linux:
	@$(MAKE)  all LIBS= XFLAGS="-I `pwd`/include/ansi -D_BSD_SOURCE  \
                -DSYS_ERRLIST_DECLARED -DGETGROUPS_T=int -g" 

linux-nansi:
	@$(MAKE) all LIBS= XFLAGS="-I `pwd`/include -D_BSD_SOURCE \
		-DSYS_ERRLIST_DECLARED -DGETGROUPS_T=int -g"

irix4:
	@$(MAKE) all LIBS="-lXm_s -lXt_s -lX11_s -lPW -lc_s -lsun" \
		XFLAGS="-DGETGROUPS_T=int"

irix:
	@$(MAKE) all LIBS= XFLAGS="-DGETGROUPS_T=gid_t"

dgux:
	@$(MAKE) all LIBS="-lnsl" XFLAGS="-DGETGROUPS_T=gid_t -DTIRPC"

sunos5:
	@$(MAKE) all LIBS="-L/usr/ucblib -R/usr/ucblib -lrpcsoc -lrpcsvc \
		-lresolv -lsocket -lnsl" \
		XFLAGS="-DGETGROUPS_T=gid_t  -DTIRPC"

trusted-sunos5:
	@$(MAKE) all LIBS="-lsocket -lnsl" XFLAGS="-DGETGROUPS_T=gid_t \
		-DTIRPC -DSun_TSOL"

sysv4:
	@$(MAKE) rpcgen all LIBS="-lsocket -lnsl" \
		XFLAGS="-DGETGROUPS_T=gid_t -DTIRPC" \
		RPCGEN="../../bin/rpcgen"

rpcgen:
	cd src/rpcgen; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)"

all:
	cd src/misc; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)" "RPCGEN=$(RPCGEN)"
	cd src/boot; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)" "RPCGEN=$(RPCGEN)"
	cd src/port_scan; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)"
	cd src/nfs-chk; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)" "RPCGEN=$(RPCGEN)"
	cd src/yp-chk; $(MAKE) "LIBS=$(LIBS)" "XFLAGS=$(XFLAGS)" "RPCGEN=$(RPCGEN)"
	cd src/fping; $(MAKE) "LIBS=$(LIBS)" "CFLAGS=$(XFLAGS)"

	cd src/ddos_scan; $(MAKE) "LIBS=$(LIBS)" "CFLAGS=$(XFLAGS)"

	cd src/contrib; $(MAKE) "LIBS=$(LIBS)" "CFLAGS=$(XFLAGS)"

	perl reconfig

checksums:
	@find * -type f -print | sort | xargs md5

clean:
	cd src/misc; $(MAKE) clean
	cd src/boot; $(MAKE) clean
	cd src/port_scan; $(MAKE) clean
	cd src/nfs-chk; $(MAKE) clean
	cd src/yp-chk; $(MAKE) clean
	cd src/fping; $(MAKE) clean
	cd src/rpcgen; $(MAKE) clean
	cd src/ddos_scan; $(MAKE) clean
	cd src/contrib; $(MAKE) clean
	rm -f html/sara.html html/sara_documentation.html status_file \
	bit_bucket tmp*

tidy:	clean
	rm -f *.old *.bak *.orig */*.old */*.bak */*.orig tmp_file* tmp1_file*
	rm -f *.sh *.txt *.html *.doc *.tar core perl/core fact.* 
	rm -f  config/passwd `find ./ -name ".*swp" -print`
	rm -f html/tutorials/vulnerability/*.html
	rm -f html/tutorials/vulnerability/no_cve/*.html zap
	rm -f config/password html/plugins/images/* sss.log
	rm -rf results
	chmod -x sara
	@echo ">>>> Delete plugins by typing 'make noplugins' <<<<"
noplugins:
	@echo "plugins will be stored in /tmp/plugins.xx.tar"
	tar -cvf "/tmp/plugins..tar" ./plugins/*
	rm -rf plugins/*
	rm -rf html/images/plugins/*

distclean:	tidy

