--- Makefile.tplt.org	2007-06-01 16:30:47.000000000 -0700
+++ Makefile.tplt	2007-08-04 00:18:25.000000000 -0700
@@ -127,81 +127,71 @@
 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: install-lib install-prog install-conf remove-auth install-data \
+	install-gdata install-perl install-locale install-message
 
 install-lib:
-	-mkdir -p $(INSTALL_LIB)
+	-mkdir -p $(DESTDIR)$(INSTALL_LIB)
 	$(PERL) tools/install_lib -s src -l $(INSTALL_LIB) $(LIBS)
-	cp $(TEXT) $(INSTALL_LIB)/
+	cp $(TEXT) $(DESTDIR)$(INSTALL_LIB)/
 
-install-prog: upgrade-cgi
-	-mkdir -p $(INSTALL_SBIN)
-	-mkdir -p $(INSTALL_BIN)
-	-mkdir -p $(INSTALL_CGI)
-	-mkdir -p $(INSTALL_LIB)
-	cp built/argusd   $(INSTALL_SBIN)/
-	cp built/argusctl $(INSTALL_SBIN)/
-	cp built/arguscgi $(INSTALL_CGI)/
-	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_CGI)/
-
-# previously, cgi was installed in sbin with symlink
-# cleanup old the files
-upgrade-cgi:
-	-rm $(INSTALL_SBIN)/arguscgi $(INSTALL_CGI)/arguscgi
+install-prog:
+	-mkdir -p $(DESTDIR)$(INSTALL_SBIN)
+	-mkdir -p $(DESTDIR)$(INSTALL_BIN)
+	-mkdir -p $(DESTDIR)$(INSTALL_CGI)
+	-mkdir -p $(DESTDIR)$(INSTALL_LIB)
+	cp built/argusd   $(DESTDIR)$(INSTALL_SBIN)/
+	cp built/argusctl $(DESTDIR)$(INSTALL_SBIN)/
+	cp built/arguscgi $(DESTDIR)$(INSTALL_CGI)/
+	cp built/graphd   $(DESTDIR)$(INSTALL_LIB)/
+	cp built/picasso  $(DESTDIR)$(INSTALL_LIB)/
+	cp built/argus-config $(DESTDIR)$(INSTALL_BIN)/
+	cp built/argus-agent  $(DESTDIR)$(INSTALL_SBIN)/
+	cp built/argusvxml    $(DESTDIR)$(INSTALL_CGI)/
 
 # in case the format of the auth file has changed
 REMOVEAUTH=1
 remove-auth:
-	@if test "$(REMOVEAUTH)" -a -f $(INSTALL_DATA)/auth; then rm $(INSTALL_DATA)/auth; fi
+#	@if test "$(REMOVEAUTH)" -a -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
+install-data:
+	mkdir -p $(DESTDIR)$(INSTALL_DATA)/stats $(DESTDIR)$(INSTALL_DATA)/html $(DESTDIR)$(INSTALL_DATA)/notify
+	touch $(DESTDIR)$(INSTALL_DATA)/log
+	$(PERL) -e 'print getppid, "\n"' > $(DESTDIR)$(INSTALL_DATA)/notno
+	chmod a+rwx $(DESTDIR)$(INSTALL_DATA)
+	chmod a+r $(DESTDIR)$(INSTALL_DATA)/html $(DESTDIR)$(INSTALL_DATA)/log
 	@echo ''
 	@echo creating example files...
 	@sleep 1
-	@cp examples/users  $(INSTALL_DATA)/users.example
-	@cp examples/config $(INSTALL_DATA)/config.example
+	@cp examples/users  $(DESTDIR)$(INSTALL_DATA)/users.example
+	@cp examples/config $(DESTDIR)$(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-gdata:
+	mkdir -p $(DESTDIR)$(INSTALL_DATA)/gdata;
+		chmod a+rwx $(DESTDIR)$(INSTALL_DATA)/gdata;
+	mkdir -p $(DESTDIR)$(INSTALL_DATA)/gcache;
+		chmod a+rwx $(DESTDIR)$(INSTALL_DATA)/gcache; 
+
+install-perl:
+		mkdir $(DESTDIR)$(INSTALL_DATA)/perl;
+		chmod a+rwx $(DESTDIR)$(INSTALL_DATA)/perl;
+
+install-locale:
+		mkdir $(DESTDIR)$(INSTALL_DATA)/locale;
+		chmod a+rx $(DESTDIR)$(INSTALL_DATA)/locale;
+	-cp locale/* $(DESTDIR)$(INSTALL_DATA)/locale
 
 install-conf:
-	cp built/conf.pl  $(INSTALL_LIB)
+	cp built/conf.pl  $(DESTDIR)$(INSTALL_LIB)
 
 HTML/config-details.html: $(BUILD)
 	built/argusd -DH > HTML/config-details.html
