Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.38
diff -u -u -r1.38 Makefile
--- Makefile	21 Oct 2003 09:18:13 -0000	1.38
+++ Makefile	25 Oct 2003 13:41:09 -0000
@@ -66,6 +66,12 @@
 # Default -> leave empty
 INSTALL_PREFIX=
 
+# Staging directory
+# Files are copied here temporarily during the install process
+# For example, make DESTDIR=/tmp/asterisk woud put things in
+# /tmp/asterisk/etc/asterisk
+DESTDIR=
+
 # Original busydetect routine
 BUSYDETECT = #-DBUSYDETECT
 
@@ -89,7 +95,6 @@
 ASTSBINDIR=$(INSTALL_PREFIX)/usr/sbin
 ASTVARRUNDIR=$(INSTALL_PREFIX)/var/run
 
-
 MODULES_DIR=$(ASTLIBDIR)/modules
 AGI_DIR=$(ASTVARLIBDIR)/agi-bin
 
@@ -233,10 +238,10 @@
 	$(MAKE) -C stdtime clean
 
 datafiles: all
-	mkdir -p $(ASTVARLIBDIR)/sounds/digits
+	mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits
 	for x in sounds/digits/*.gsm; do \
 		if grep -q "^%`basename $$x`%" sounds.txt; then \
-			install $$x $(ASTVARLIBDIR)/sounds/digits ; \
+			install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds/digits ; \
 		else \
 			echo "No description for $$x"; \
 			exit 1; \
@@ -244,18 +249,18 @@
 	done
 	for x in sounds/vm-* sounds/transfer* sounds/pbx-* sounds/ss-* sounds/beep* sounds/dir-* sounds/conf-* sounds/agent-* sounds/invalid* sounds/tt-* sounds/auth-* sounds/privacy-*; do \
 		if grep -q "^%`basename $$x`%" sounds.txt; then \
-			install $$x $(ASTVARLIBDIR)/sounds ; \
+			install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
 		else \
 			echo "No description for $$x"; \
 			exit 1; \
 		fi; \
 	done
-	mkdir -p $(ASTVARLIBDIR)/mohmp3
-	mkdir -p $(ASTVARLIBDIR)/images
+	mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/mohmp3
+	mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/images
 	for x in images/*.jpg; do \
-		install $$x $(ASTVARLIBDIR)/images ; \
+		install $$x $(DESTDIR)$(ASTVARLIBDIR)/images ; \
 	done
-	mkdir -p $(AGI_DIR)
+	mkdir -p $(DESTDIR)$(AGI_DIR)
 
 update: 
 	@if [ -d CVS ]; then \
@@ -267,37 +272,37 @@
 	fi
 
 bininstall: all
-	mkdir -p $(MODULES_DIR)
-	mkdir -p $(ASTSBINDIR)
-	mkdir -p $(ASTETCDIR)
-	mkdir -p $(ASTBINDIR)
-	mkdir -p $(ASTSBINDIR)
-	mkdir -p $(ASTVARRUNDIR)
-	mkdir -p $(ASTSPOOLDIR)/voicemail
-	install -m 755 asterisk $(ASTSBINDIR)/
-	install -m 755 astgenkey $(ASTSBINDIR)/
-	install -m 755 safe_asterisk $(ASTSBINDIR)/
+	mkdir -p $(DESTDIR)$(MODULES_DIR)
+	mkdir -p $(DESTDIR)$(ASTSBINDIR)
+	mkdir -p $(DESTDIR)$(ASTETCDIR)
+	mkdir -p $(DESTDIR)$(ASTBINDIR)
+	mkdir -p $(DESTDIR)$(ASTSBINDIR)
+	mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
+	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
+	install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
+	install -m 755 astgenkey $(DESTDIR)$(ASTSBINDIR)/
+	install -m 755 safe_asterisk $(DESTDIR)$(ASTSBINDIR)/
 	for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done
-	install -d $(ASTHEADERDIR)
-	install include/asterisk/*.h $(ASTHEADERDIR)
-	rm -f $(ASTVARLIBDIR)/sounds/vm
-	rm -f $(ASTVARLIBDIR)/sounds/voicemail
-	if [ ! -h $(ASTSPOOLDIR)/vm ] && [ -d $(ASTSPOOLDIR)/vm ]; then \
-		mv $(ASTSPOOLDIR)/vm $(ASTSPOOLDIR)/voicemail/default; \
+	install -d $(DESTDIR)$(ASTHEADERDIR)
+	install include/asterisk/*.h $(DESTDIR)$(ASTHEADERDIR)
+	rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/vm
+	rm -f $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail
+	if [ ! -h $(DESTDIR)$(ASTSPOOLDIR)/vm ] && [ -d $(DESTDIR)$(ASTSPOOLDIR)/vm ]; then \
+		mv $(DESTDIR)$(ASTSPOOLDIR)/vm $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
 	else \
-		mkdir -p $(ASTSPOOLDIR)/voicemail/default; \
-		rm -f $(ASTSPOOLDIR)/vm; \
+		mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default; \
+		rm -f $(DESTDIR)$(ASTSPOOLDIR)/vm; \
 	fi
-	ln -s $(ASTSPOOLDIR)/voicemail/default $(ASTSPOOLDIR)/vm
-	rm -f $(MODULES_DIR)/chan_ixj.so
-	rm -f $(MODULES_DIR)/chan_tor.so
-	rm -f $(MODULES_DIR)/cdr_mysql.so
-	mkdir -p $(ASTVARLIBDIR)/sounds
-	mkdir -p $(ASTLOGDIR)/cdr-csv
-	mkdir -p $(ASTVARLIBDIR)/keys
-	install -m 644 keys/iaxtel.pub $(ASTVARLIBDIR)/keys
-	( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
-	( cd $(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
+	ln -s $(ASTSPOOLDIR)/voicemail/default $(DESTDIR)$(ASTSPOOLDIR)/vm
+	rm -f $(DESTDIR)$(MODULES_DIR)/chan_ixj.so
+	rm -f $(DESTDIR)$(MODULES_DIR)/chan_tor.so
+	rm -f $(DESTDIR)$(MODULES_DIR)/cdr_mysql.so
+	mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/sounds
+	mkdir -p $(DESTDIR)$(ASTLOGDIR)/cdr-csv
+	mkdir -p $(DESTDIR)$(ASTVARLIBDIR)/keys
+	install -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTVARLIBDIR)/keys
+	( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/vm . )
+	( cd $(DESTDIR)$(ASTVARLIBDIR)/sounds  ; ln -s $(ASTSPOOLDIR)/voicemail . )
 	@echo " +---- Asterisk Installation Complete -------+"  
 	@echo " +                                           +"
 	@echo " +    YOU MUST READ THE SECURITY DOCUMENT    +"
@@ -325,58 +330,58 @@
 upgrade: all bininstall
 
 adsi: all
-	mkdir -p $(ASTETCDIR)
+	mkdir -p $(DESTDIR)$(ASTETCDIR)
 	for x in configs/*.adsi; do \
-		if ! [ -f $(ASTETCDIRX)/$$x ]; then \
-			install -m 644 $$x $(ASTETCDIR)/`basename $$x` ; \
+		if ! [ -f $(DESTDIR)$(ASTETCDIRX)/$$x ]; then \
+			install -m 644 $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x` ; \
 		fi ; \
 	done
 
 samples: all datafiles adsi
-	mkdir -p $(ASTETCDIR)
+	mkdir -p $(DESTDIR)$(ASTETCDIR)
 	for x in configs/*.sample; do \
-		if [ -f $(ASTETCDIR)/`basename $$x .sample` ]; then \
-			mv -f $(ASTETCDIR)/`basename $$x .sample` $(ASTETCDIR)/`basename $$x .sample`.old ; \
+		if [ -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ]; then \
+			mv -f $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample`.old ; \
 		fi ; \
-		install $$x $(ASTETCDIR)/`basename $$x .sample` ;\
+		install $$x $(DESTDIR)$(ASTETCDIR)/`basename $$x .sample` ;\
 	done
-	echo "[directories]" > $(ASTETCDIR)/asterisk.conf
-	echo "astetcdir => $(ASTETCDIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astmoddir => $(MODULES_DIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astagidir => $(AGI_DIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astspooldir => $(ASTSPOOLDIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astrundir => $(ASTVARRUNDIR)" >> $(ASTETCDIR)/asterisk.conf
-	echo "astlogdir => $(ASTLOGDIR)" >> $(ASTETCDIR)/asterisk.conf
+	echo "[directories]" > $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astetcdir => $(ASTETCDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astmoddir => $(MODULES_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astvarlibdir => $(ASTVARLIBDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astagidir => $(AGI_DIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astspooldir => $(ASTSPOOLDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astrundir => $(ASTVARRUNDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
+	echo "astlogdir => $(ASTLOGDIR)" >> $(DESTDIR)$(ASTETCDIR)/asterisk.conf
 	for x in sounds/demo-*; do \
 		if grep -q "^%`basename $$x`%" sounds.txt; then \
-			install $$x $(ASTVARLIBDIR)/sounds ; \
+			install $$x $(DESTDIR)$(ASTVARLIBDIR)/sounds ; \
 		else \
 			echo "No description for $$x"; \
 			exit 1; \
 		fi; \
 	done
 	for x in sounds/*.mp3; do \
-		install $$x $(ASTVARLIBDIR)/mohmp3 ; \
+		install $$x $(DESTDIR)$(ASTVARLIBDIR)/mohmp3 ; \
 	done
-	mkdir -p $(ASTSPOOLDIR)/voicemail/default/1234/INBOX
-	:> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
+	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail/default/1234/INBOX
+	:> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm
 	for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isunavail; do \
-		cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
+		cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/unavail.gsm ; \
 	done
-	:> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
+	:> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm
 	for x in vm-theperson digits/1 digits/2 digits/3 digits/4 vm-isonphone; do \
-		cat $(ASTVARLIBDIR)/sounds/$$x.gsm >> $(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
+		cat $(DESTDIR)$(ASTVARLIBDIR)/sounds/$$x.gsm >> $(DESTDIR)$(ASTVARLIBDIR)/sounds/voicemail/default/1234/busy.gsm ; \
 	done
 
 webvmail:
-	@[ -d $(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
-	@[ -d $(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
-	@[ -d $(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
-	install -m 4755 -o root -g root vmail.cgi $(HTTPDIR)/cgi-bin/vmail.cgi
-	mkdir -p $(HTTPDIR)/html/_asterisk
+	@[ -d $(DESTDIR)$(HTTPDIR) ] || ( echo "No HTTP directory" && exit 1 )
+	@[ -d $(DESTDIR)$(HTTPDIR)/html ] || ( echo "No http directory" && exit 1 )
+	@[ -d $(DESTDIR)$(HTTPDIR)/cgi-bin ] || ( echo "No cgi-bin directory" && exit 1 )
+	install -m 4755 -o root -g root vmail.cgi $(DESTDIR)$(HTTPDIR)/cgi-bin/vmail.cgi
+	mkdir -p $(DESTDIR)$(HTTPDIR)/html/_asterisk
 	for x in images/*.gif; do \
-		install -m 644 $$x $(HTTPDIR)/html/_asterisk/; \
+		install -m 644 $$x $(DESTDIR)$(HTTPDIR)/html/_asterisk/; \
 	done
 	@echo " +--------- Asterisk Web Voicemail ----------+"  
 	@echo " +                                           +"
@@ -396,8 +401,8 @@
 __rpm: _version
 	rm -rf /tmp/asterisk ; \
 	mkdir -p /tmp/asterisk/redhat/RPMS/i386 ; \
-	$(MAKE) INSTALL_PREFIX=/tmp/asterisk install ; \
-	$(MAKE) INSTALL_PREFIX=/tmp/asterisk samples ; \
+	$(MAKE) DESTDIR=/tmp/asterisk install ; \
+	$(MAKE) DESTDIR=/tmp/asterisk samples ; \
 	mkdir -p /tmp/asterisk/etc/rc.d/init.d ; \
 	cp -f redhat/asterisk /tmp/asterisk/etc/rc.d/init.d/ ; \
 	cp -f redhat/rpmrc /tmp/asterisk/ ; \
Index: agi/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/agi/Makefile,v
retrieving revision 1.3
diff -u -u -r1.3 Makefile
--- agi/Makefile	19 Aug 2003 16:42:30 -0000	1.3
+++ agi/Makefile	25 Oct 2003 13:41:09 -0000
@@ -18,7 +18,8 @@
 all: depend $(AGIS)
 
 install: all
-	for x in $(AGIS); do $(INSTALL) -m 755 $$x $(AGI_DIR) ; done
+	mkdir -p $(DESTDIR)$(AGI_DIR)
+	for x in $(AGIS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(AGI_DIR) ; done
 
 eagi-test: eagi-test.o
 	$(CC) -o eagi-test eagi-test.o
Index: apps/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/Makefile,v
retrieving revision 1.22
diff -u -u -r1.22 Makefile
--- apps/Makefile	22 Oct 2003 13:34:59 -0000	1.22
+++ apps/Makefile	25 Oct 2003 13:41:09 -0000
@@ -50,7 +50,7 @@
 	$(CC) -shared -Xlinker -x -o $@ $< -ltonezone
 
 install: all
-	for x in $(APPS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(APPS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 app_todd.o: app_todd.c
 	gcc -pipe -O6 -g  -Iinclude -I../include -D_REENTRANT -march=i586 -DDO_CRASH -c -o  app_todd.o app_todd.c
Index: astman/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/astman/Makefile,v
retrieving revision 1.4
diff -u -u -r1.4 Makefile
--- astman/Makefile	19 Aug 2003 16:42:30 -0000	1.4
+++ astman/Makefile	25 Oct 2003 13:41:10 -0000
@@ -8,7 +8,7 @@
 install:
 	if [ "$(TARGET)" != "none" ]; then \
 		for x in $(TARGET); do \
-			install -m 755 $$x $(ASTSBINDIR)/astman; \
+			install -m 755 $$x $(DESTDIR)$(ASTSBINDIR)/astman; \
 		done ; \
 	fi
 
Index: cdr/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr/Makefile,v
retrieving revision 1.8
diff -u -u -r1.8 Makefile
--- cdr/Makefile	1 Oct 2003 15:03:30 -0000	1.8
+++ cdr/Makefile	25 Oct 2003 13:41:10 -0000
@@ -34,7 +34,7 @@
 all: depend $(MODS)
 
 install: all
-	for x in $(MODS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 clean:
 	rm -f *.so *.o .depend
Index: channels/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/Makefile,v
retrieving revision 1.13
diff -u -u -r1.13 Makefile
--- channels/Makefile	21 Oct 2003 02:57:29 -0000	1.13
+++ channels/Makefile	25 Oct 2003 13:41:10 -0000
@@ -128,7 +128,7 @@
 #	$(CC) -rdynamic -shared -Xlinker -x -o $@ $<
 
 install: all
-	for x in $(CHANNEL_LIBS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(CHANNEL_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 depend: .depend
 
Index: codecs/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/codecs/Makefile,v
retrieving revision 1.8
diff -u -u -r1.8 Makefile
--- codecs/Makefile	21 Oct 2003 02:57:29 -0000	1.8
+++ codecs/Makefile	25 Oct 2003 13:41:10 -0000
@@ -97,7 +97,7 @@
 include .depend
 
 install: all
-	for x in $(CODECS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(CODECS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 depend: .depend
 
Index: formats/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/formats/Makefile,v
retrieving revision 1.7
diff -u -u -r1.7 Makefile
--- formats/Makefile	19 Aug 2003 16:42:30 -0000	1.7
+++ formats/Makefile	25 Oct 2003 13:41:10 -0000
@@ -40,7 +40,7 @@
 	$(CC) -shared -Xlinker -x -o $@ $< -lm
 
 install: all
-	for x in $(FORMAT_LIBS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(FORMAT_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 depend: .depend
 
Index: pbx/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx/Makefile,v
retrieving revision 1.4
diff -u -u -r1.4 Makefile
--- pbx/Makefile	19 Aug 2003 16:42:30 -0000	1.4
+++ pbx/Makefile	25 Oct 2003 13:41:10 -0000
@@ -62,7 +62,7 @@
 endif
 
 install: all
-	for x in $(PBX_LIBS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(PBX_LIBS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 depend: .depend
 
Index: res/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/res/Makefile,v
retrieving revision 1.7
diff -u -u -r1.7 Makefile
--- res/Makefile	19 Aug 2003 16:42:30 -0000	1.7
+++ res/Makefile	25 Oct 2003 13:41:10 -0000
@@ -25,7 +25,7 @@
 all: depend $(MODS)
 
 install: all
-	for x in $(MODS); do $(INSTALL) -m 755 $$x $(MODULES_DIR) ; done
+	for x in $(MODS); do $(INSTALL) -m 755 $$x $(DESTDIR)$(MODULES_DIR) ; done
 
 res_crypto.so: res_crypto.o
 	$(CC) -shared -Xlinker -x -o $@ $< $(CRYPTO_LIBS)
