File:  [LON-CAPA] / loncom / build / Makefile
Revision 1.162.2.10: download - view: text, annotated - select for diffs
Mon Aug 30 02:39:13 2004 UTC (20 years, 4 months ago) by albertel
Branches: version_1_2_X
- version bump

# The LearningOnline Network with CAPA

# $Id: Makefile,v 1.162.2.10 2004/08/30 02:39:13 albertel Exp $

# TYPICAL USAGE of this Makefile is primarily for two targets:
# "make build" and "make install".
# Many other targets and features are supported (see the initial
# help targets).

# ======================================= Default settings for Makefile options
DISTPROBE=`perl ./distprobe`
DIST=$(DISTPROBE)
CATEGORY="development"
SOURCE=../..
TARGET=""
NORESTORECONF="0"
HOSTNAME=""
LAUNCH=| perl
QUERYLAUNCH=> /tmp/loncapa_query.pl; perl /tmp/loncapa_query.pl
OUTSTREAM=>
SAVE=program.pl.$(TIMESTAMP)
LAUNCHSAVE=$(OUTSTREAM) $(SAVE)
METAMTARGET=""
MTARGET=""
VERSION=1.2.0
# The current working definition for "RELEASE" is: changes not in the software,
# but in the operating system dependent packaging of the software.  Thus, the
# generic tarball releases do not need to have a release number specified.
RELEASE=1 # As a general rule for now, this is always being set to "1".
DIRTARGET=loncapa-$(VERSION)
LOCALAUTHPATH=/home/httpd/lib/perl

# =============================================== Help targets for the Makefile
# If 'make' is run without any arguments, the 'help' target is called since
# it is the first target.
help:
	@echo "*** You need to specify a valid target ***"
	@echo "To get a list of valid targets: \"make help_TARGETS\""
	@echo "To get a list of valid options: \"make help_OPTIONS\""
	@echo " "
	@echo "Typically invoked targets are:"
	@echo "    make build"
	@echo "    make install"
	@echo "    make test"
	@echo "    make clean"

help_OPTIONS:
	@echo "* ADJUSTABLE OPTIONS *"
	@echo "(option) DIST can be redhat7, debian, redhat6.2, or default"
	@echo "         You probably do not need to specify this; it is"
	@echo "         automatically probed for."
	@echo "(option) CATEGORY can be 'runtime' or 'development'; currently"
	@echo "         the 'development' setting is the most reliable;"
	@echo "         eventually, production machines should be using the"
	@echo "         'runtime' settings"
	@echo "(option) SOURCE is an absolute or relative directory path."
	@echo "         SOURCE corresponds to the root directory of the"
	@echo "         loncapa source release"
	@echo "(option) TARGET is an absolute or relative directory path."
	@echo "         This is where files will be installed on your system."
	@echo "         Typically, this should be set to nothing (which"
	@echo "         corresponds to the '/' root of the entire filesystem)."
	@echo "(option) NORESTORECONF, when set to a non-zero value, stops"
	@echo "         filesystem upgrades from overwriting existing "
	@echo "         configuration files.  Ordinarily, NORESTORECONF=0, "
	@echo "         because the existing configuration files are safely"
	@echo "         dealt with (or so one hopes... :) )."
	@echo "(option) HOSTNAME specifies the name of a remote server for"
	@echo "         which a NET_* Makefile target should be launched"
	@echo "(option) VERSION; especially useful for the 'tardist' target"
	@echo "         this tags the tarball file and internal directories"
	@echo "         with a specific version string (conventionally "
	@echo "         numeric)"

help_TARGETS:
	@echo "*** RUNNING TESTS TO ENSURE SOLID PERFORMANCE ***"
	@echo "test: test different parts of the LON-CAPA system (TEST_*)."
	@echo "      Makefile-dependent processes as well as horizontal and"
	@echo "      vertical aspects of the LON-CAPA system architecture"
	@echo "      are all tested."
	@echo "TEST_lpml_scripts: make sure that the system can process"
	@echo "                   the Linux Packaging Markup Language."
	@echo "                   This is neither horizontal or vertical"
	@echo "                   testing.  The idea is to make sure that"
	@echo "                   the installation software itself works"
	@echo "                   as expected."
	@echo "TEST_system_dependencies: make sure that all needed system "
	@echo "                          components are active and present "
	@echo "                          on the server such as perl modules"
	@echo "                          and the MySQL database"
	@echo "                          (horizontal testing)"
	@echo "TEST_web_layer: mimic a login and various vertical actions on "
	@echo "                a LON-CAPA system"
	@echo "TEST_hosts_and_domain_tab: make sure that a "
	@echo "        loncapa/loncom/hosts.tab and loncapa/loncom/domain.tab"
	@echo "        file is specified for installation"
	@echo "TEST_html2ps: test for the presence of html2ps which is needed"
	@echo "              for making a PDF compilation for pdfdoc"
	@echo "*** GENERAL TARGETS SUCH AS 'build' AND 'install' ***"
	@echo "build: compile the source tree"
	@echo "buildflag: a semaphore that helps educate the user to run"
	@echo "           'make build' first before running 'make install'"
	@echo "configinstall: install configuration files and restore with"
	@echo "               prior information"
	@echo "install: install from a ***compiled*** source tree"
	@echo "         (see make build) to a specified TARGET destination"
	@echo "         on the filesystem (default setting is TARGET=/)."
	@echo "rawinstall: just install files, links and directories without"
	@echo "            any bells or whistles (e.g. double-checking"
	@echo "            configurations, fine-tuning webserver, etc.)"
	@echo "hosts_and_domain_tab: install the hosts.tab and domain.tab" 
	@echo "                      to the filesystem"
	@echo "webserverconf: fine-tune the web server configuration;"
	@echo "               make sure the proper 'Include' statements"
	@echo "               are appended to httpd.conf"
	@echo "vanillatar: generate top-level files such as README, UPDATE,"
	@echo "            CHECKRPMS, and TEST (needed by tardist)"
	@echo "tardist: build a tarball that will upgrade the software on a "
	@echo "         system"
	@echo "sanitycheck: probe for common errors and recommend fixes to"
	@echo "             the user"
	@echo "accesscount_seed: Migrate the access counting mechanism from "
	@echo "    nohist_reseval.db to nohist_accesscount.db."
	@echo "modify_config_files: Perform automatic update of the "
	@echo "    configuration files for yum and MySQL."
	@echo "ntpcheck: test to see if ntp is installed and running."
	@echo "cron_lpmlcheck: remove cron file /etc/cron.d/loncapa.lpml."
	@echo "rpmcheck: test to see if rpms known to confict are installed."
	@echo "updatequery: solicit the user for machine configuration"
	@echo "             information; to be incorporated during an update"
	@echo "             procedure (via the UPDATE command)"
	@echo "postinstall: double-check things after installation"
	@echo "VERSION: tag the filesystem with version information inside"
	@echo "         /etc/loncapa-release and"
	@echo "         /home/httpd/html/lon-status/version.txt"
	@echo "aboutVERSION: place version information inside about.html"
	@echo "              and loncapa_apache.conf"
	@echo "*** Makefile.* TARGETS BUILT DYNAMICALLY FROM loncapafiles.lpml ***"
	@echo "Makefile.configinstall: generate a Makefile for configuration"
	@echo "                        files; built dynamically from"
	@echo "                        loncapafiles.lpml"
	@echo "Makefile.build: generate a Makefile for compiling"
	@echo "                files inside the source directory; "
	@echo "                Makefile.build is generated from"
	@echo "                loncapafiles.lpml"
	@echo "Makefile.install: generate a Makefile for installing"
	@echo "                  files; built dynamically from"
	@echo "                  loncapafiles.lpml"
	@echo "*** TARGETS FOR OPERATING ON FILESYSTEMS ACROSS THE NETWORK ***"
	@echo "lpmladm: coordinates username=lpmladm mediated secure shell"
	@echo "         processes; needed for the NET_* targets"
	@echo "NET_hosts_and_domain_tab: install the hosts.tab and domain.tab"
	@echo "                          to a filesystem elsewhere"
	@echo "                          on the network"
	@echo "NET_webserverconf: fine-tune the web server configuration on a"
	@echo "                   filesystem elsewhere on the network"
	@echo "NET_rawinstall: launch the rawinstall target on a filesystem"
	@echo "                elsewhere on the network"
	@echo "*** TARGETS FOR MAKING LISTS (MANIFESTS) OF LON-CAPA FILES ***"
	@echo "MANIFEST_all: generate a list of all files to be included in"
	@echo "              the distributed tarball"
	@echo "MANIFEST_cvs: essentially a list of all CVS/Entries files used"
	@echo "              for 'time-checking' intelligence"
	@echo "MANIFEST_lpml: a list of all LON-CAPA files to be installed,"
	@echo "               compile from, used as building software, and"
	@echo "               testing"
	@echo "MANIFEST_vanillatar: 'README'-type top-level files that a user"
	@echo "                     of the distributed tarball would first"
	@echo "                     look at and work with"
	@echo "*** STATUS REPORT TARGETS ***"
	@echo "warningnote: analyze the WARNINGS file and produce a synopsis"
	@echo "             and recommended action to the user"
	@echo "HTML: generate an HTML-formatted description of the LON-CAPA"
	@echo "      source files"
	@echo "status: compare the TARGET filesystem with a compiled loncapa "
	@echo "        source directory"
	@echo "statuspost: post the results of "make status" to "
	@echo "            TARGET/home/httpd/html/lon-status/filestatus.html"
	@echo "rpmstatus: compare the rpms on a system to defined lists "
	@echo "           loncapa/doc/otherfiles/cd_rpms and "
	@echo "           loncapa/doc/otherfiles/rpm_list.txt"
	@echo "rpmstatuspost: post the results of 'make rpmstatus' to "
	@echo "            TARGET/home/httpd/html/lon-status/rpmstatus.html"
	@echo "*** ALTERNATIVE PACKAGING TARGETS ***"
	@echo "RPM: build LON-CAPA-base RPM from loncapa source repository"
	@echo "     (still under development)"
	@echo "DPKG: build a loncapa Debian package from loncapa source"
	@echo "      repository (still under development)"
	@echo "base_rpm_file_list: create a file listing to be used for"
	@echo "                    generating an RPM software package"
	@echo "BinaryRoot: create a BinaryRoot directory to be used for"
	@echo "            generating an RPM software package"
	@echo "*** MASTER DOCUMENTATION TARGETS ***"	
	@echo "doc: generate web-page documentation for install.lon-capa.org"
	@echo "     (and eventually for documentation on installed machines)"
	@echo "pdfdoc: make a PDF-formatted compilation of all installation"
	@echo "        documentation"
	@echo "*** KEEPING THINGS CLEAN ***"
	@echo "clean: remove any files that might (even by remote chance)"
	@echo "       interfere with rebuilding/recompiling software"
	@echo "reallyclean: remove all files that were generated during"
	@echo "             building or compilation of the software"
	@echo "uninstall: remove all directories that do not contain files"
	@echo "           from other software packages and that do not contain"
	@echo "           student and instructor data; NOTE THAT THIS IS"
	@echo "           INTERACTIVE--you will be given a final chance"
	@echo "           to look at what will and will not be deleted."
	@echo "           Still, be careful.  This is a very new target and is"
	@echo "           an alpha-level software feature for now."
	@echo "backup: rolls a tarball backup of all important student and "
	@echo "        instructor data (NOT YET IMPLEMENTED)"
	@echo "restore: reseeds a LON-CAPA server with tarball backups "
	@echo "         generated by \"make backup\" (NOT YET IMPLEMENTED)"
	@echo "*** AUXILIARY TESTS ***"
	@echo "localauth: tests to see if localauth exists or not and run"
	@echo "           appropriate tests"
	@echo "*** A HELPFUL DEPENDENCY ***"
	@echo "alwaysrun: blank target that is a dependency for targets"
	@echo "           that should \"always run\""

# =========================== *** RUNNING TESTS TO ENSURE SOLID PERFORMANCE ***

test: TEST_lpml_scripts TEST_system_dependencies TEST_web_layer
	@echo "ALL SYSTEM DEPENDENCY TESTS SUCCESSFUL"

TEST_system_dependencies:
	@echo "TESTING SYSTEM DEPENDENCIES"
	cd system_dependencies; make

TEST_lpml_scripts:
	@echo "TESTING LPML INSTALLATION CODE"
	cd ../test; perl filecomparetest.pl

TEST_web_layer:
	@echo "TESTING WEB LAYER"
	cd weblayer_test; make

TEST_hosts_tab:
	@echo "Testing hosts.tab"
	@if (test -e ../hosts.tab); then \
		echo "there is a defined link or file; assume okay"; \
	else echo "**** ERROR **** hosts.tab not defined!" && \
	     echo -n "You need to do one of the following within your " && \
	     echo "CVS repository (cd loncapa/loncom)" && \
	     echo "   1) ln -s production_hosts.tab hosts.tab" && \
	     echo "   2) ln -s development_hosts.tab hosts.tab" && \
	     echo "or 3) ln -s rawhide_hosts.tab hosts.tab" && \
	     echo "(you most likely want option #1, production_hosts.tab)" && \
	     exit 1; \
	fi

TEST_domain_tab:
	@echo "Testing domain.tab"
	@if (test -e ../domain.tab); then \
		echo "there is a defined link or file; assume okay"; \
	else echo "**** ERROR **** domain.tab not defined!" && \
	     echo -n "You need to do one of the following within your " && \
	     echo "CVS repository (cd loncapa/loncom)" && \
	     echo "   1) ln -s production_domain.tab domain.tab" && \
	     echo "   2) ln -s development_domain.tab domain.tab" && \
	     echo "or 3) ln -s rawhide_domain.tab domain.tab" && \
	     echo "(you most likely want option #1, production_domain.tab)" && \
	     exit 1; \
	fi

TEST_html2ps:
	@if (test -e /usr/local/html2ps/bin/html2ps); then \
		echo "I can find html2ps; assume okay"; \
	else \
	echo "**** ERROR **** cannot find /usr/local/html2ps/bin/html2ps!" && \
        echo "Please visit http://www.tdb.uu.se/~jan/html2ps.html" && \
	exit 1; \
	fi

# ======================= *** GENERAL TARGETS SUCH AS 'build' AND 'install' ***

build: Makefile.build pod2html.sh pod2man.sh
	install -d $(SOURCE)/doc/man
	install -d $(SOURCE)/doc/scripts
	install -d $(SOURCE)/doc/lib/perl/Apache
	echo -n "" > WARNINGS
	make -f Makefile.build all
	echo '1' > buildflag
	make warningnote

buildflag:
	@echo "**** ERROR **** You need to run 'make build' first" > WARNINGS
	make warningnote
	@need_to_run_make_build_first 2>/dev/null

configinstall: Makefile.configinstall
	make -f Makefile.configinstall SOURCE="$(SOURCE)" TARGET="$(TARGET)" \
	configfiles
	if (test "0" = $(NORESTORECONF)); then \
	perl loncaparestoreconfigurations suffix .lpmlnew; fi

install: buildflag VERSION TEST_hosts_tab TEST_domain_tab Makefile.install Makefile
	echo -n "" > WARNINGS
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" \
	directories
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" files
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" links
	make SOURCE="$(SOURCE)" TARGET="$(TARGET)" \
	NORESTORECONF="$(NORESTORECONF)" configinstall
	make postinstall
	make warningnote
	@echo "You can now run 'make test' to see if your system is ready to go!"
#	@echo "NOTE THAT YOUR SYSTEM MUST HAVE MYSQL WITH A USER=\"www\" AND"
#	@echo -n "PASSWORD=\"localhostkey\" FOR www\@localhost"
#	@echo -n "(YOU MAY NEED TO REINITIALIZE YOUR MYSQL www\@localhost USER)"
#	@echo -n "Please see http://install.lon-capa.org/ for more information"

rawinstall: VERSION Makefile.install Makefile
	echo -n "" > WARNINGS
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" \
	directories
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" files
	make -f Makefile.install SOURCE="$(SOURCE)" TARGET="$(TARGET)" links
	make SOURCE="$(SOURCE)" TARGET="$(TARGET)" \
	NORESTORECONF="$(NORESTORECONF)" configinstall

hosts_and_domain_tab: TEST_hosts_tab TEST_domain_tab
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl xfml_parse.pl $(SOURCE)/doc/loncapafiles/valid_hosts.xfml | \
	perl lpml_parse.pl install $(CATEGORY) $(DIST) "$(SOURCE)" \
	"$(TARGET)" > Makefile.install
	make -f Makefile.install directories
	make -f Makefile.install files
	@echo "If hosts.tab or domain.tab has changed, restart httpd and loncontrol:"
	@echo "   /etc/rc.d/init.d/httpd restart"
	@echo "   /etc/rc.d/init.d/loncontrol restart"

webserverconf:
	cat $(SOURCE)/doc/loncapafiles/webserver.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

# ---------------- Top-level files such as README, UPDATE, CHECKRPMS, and TEST
vanillatar:
	# --------------------------- Point UPDATE to the internal make process
	echo '#!/bin/sh' > $(SOURCE)/UPDATE
	echo 'touch loncom/build/WARNINGS' >> $(SOURCE)/UPDATE;
	echo 'ln -s loncom/build/WARNINGS WARNINGS' >> $(SOURCE)/UPDATE;
	echo 'cd loncom/build; make build' >> $(SOURCE)/UPDATE
	echo 'make rawinstall' >> $(SOURCE)/UPDATE
	echo 'make configinstall' >> $(SOURCE)/UPDATE
	echo 'make updatequery' >> $(SOURCE)/UPDATE
	echo 'make hosts_and_domain_tab' >> $(SOURCE)/UPDATE
	echo 'make postinstall' >> $(SOURCE)/UPDATE
	echo 'make run_searchcat' >> $(SOURCE)/UPDATE
	echo 'make aboutVERSION' >> $(SOURCE)/UPDATE
	echo 'make warningnote' >> $(SOURCE)/UPDATE
	# ----------------------------- Point TEST to the internal make process
	echo '#!/bin/sh' > $(SOURCE)/TEST
	echo 'cd loncom/build; make test' >> $(SOURCE)/TEST
	echo 'cd system_dependencies || cd loncom/build/system_dependencies; cp -v CPAN_STATUS_REPORT ../../../CPAN_STATUS_REPORT' >> $(SOURCE)/TEST
	# ----------------------------- Copy CHECKRPMS to the vanilla top-level
	cp -v $(SOURCE)/loncom/build/CHECKRPMS $(SOURCE)/CHECKRPMS
	# ----------------------- vanilla executables must indeed be executable
	chmod a+rx $(SOURCE)/UPDATE
	chmod a+rx $(SOURCE)/TEST
	chmod a+rx $(SOURCE)/CHECKRPMS
	# -------------------------------- Copy README to the vanilla top-level
	#cp -v $(SOURCE)/doc/shortest_path_redhat7.2.txt $(SOURCE)/README

tardist:
	make MANIFEST_all
	make vanillatar
	# -------------------------------------------------------- Make tardist
	@cd $(SOURCE); \
	if (test -h $(DIRTARGET)); then \
		echo "$(DIRTARGET) link already defined; assume okay"; \
	else \
		ln -s . $(DIRTARGET); \
	fi
	cp -v $(SOURCE)/loncom/license/about.html \
	$(SOURCE)/loncom/license/about.html.orig
	cp -v $(SOURCE)/loncom/loncapa_apache.conf \
	$(SOURCE)/loncom/loncapa_apache.conf.orig
	make aboutVERSION
	cd $(SOURCE); \
	tar --no-recursion --numeric-owner --files-from MANIFEST \
	-h -czf $(DIRTARGET).tar.gz 2>tar_WARNINGS || [ "0" == "0" ]
	mv -v $(SOURCE)/loncom/license/about.html.orig \
	$(SOURCE)/loncom/license/about.html
	mv -v $(SOURCE)/loncom/loncapa_apache.conf.orig \
	$(SOURCE)/loncom/loncapa_apache.conf
	cat $(SOURCE)/tar_WARNINGS | \
	xargs --replace=XXX echo '**** WARNING **** XXX' > WARNINGS
	rm -f $(SOURCE)/tar_WARNINGS
	make warningnote

ntpcheck:
	cat $(SOURCE)/doc/loncapafiles/ntpcheck.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

cron_lpmlcheck:
	cat $(SOURCE)/doc/loncapafiles/cron_lpmlcheck.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS


rpmcheck:
	cat $(SOURCE)/doc/loncapafiles/rpmcheck.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

sanitycheck:
	cat $(SOURCE)/doc/loncapafiles/sanitycheck.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

updatequery:
	cat $(SOURCE)/doc/loncapafiles/updatequery.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(QUERYLAUNCH)

accesscount_seed:
	cat $(SOURCE)/doc/loncapafiles/accesscount_seed.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

modify_config_files:
	cat $(SOURCE)/doc/loncapafiles/modify_config_files.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

reseval_fixup:
	cat $(SOURCE)/doc/loncapafiles/reseval_fixup.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

clearoutoldspreadsheetcache:
	cat $(SOURCE)/doc/loncapafiles/clearoutoldspreadsheetcache.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

sendmail_fix:
	cat $(SOURCE)/doc/loncapafiles/sendmail_fix.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

ownership_fix:
	cat $(SOURCE)/doc/loncapafiles/ownership_fix.piml | \
	perl piml_parse.pl $(CATEGORY) $(DIST) "$(TARGET)" $(LAUNCH) | \
	tee -a WARNINGS

postinstall:
	make webserverconf
	make reseval_fixup
	make accesscount_seed
	make modify_config_files
	make clearoutoldspreadsheetcache
	make rpmcheck
	make ntpcheck
	make cron_lpmlcheck
	make sanitycheck
	make sendmail_fix
	make ownership_fix

VERSION:
	install -d $(TARGET)/etc
	echo -n "LON-CAPA release $(VERSION)-" > $(TARGET)/etc/loncapa-release
	date +"%Y%m%d" >> $(TARGET)/etc/loncapa-release
	install -d $(TARGET)/home/httpd/html/lon-status
	echo -n "$(VERSION)-" > $(TARGET)/home/httpd/html/lon-status/version.txt
	date +"%Y%m%d" >> $(TARGET)/home/httpd/html/lon-status/version.txt

aboutVERSION:
	cat $(SOURCE)/loncom/license/about.html | \
	perl -e '$$d=`date +"%Y%m%d"`;chomp($$d);while(<>){s/\<\!\-\- VERSION \-\-\>/$(VERSION)-$$d/; print;}' > \
	$(SOURCE)/loncom/license/about.html.new
	mv -v $(SOURCE)/loncom/license/about.html.new \
	$(SOURCE)/loncom/license/about.html
	cat $(SOURCE)/loncom/loncapa_apache.conf | \
	perl -e '$$d=`date +"%Y%m%d"`;chomp($$d);while(<>){s/\<\!\-\- VERSION \-\-\>/$(VERSION)-$$d/; print;}' > \
	$(SOURCE)/loncom/loncapa_apache.conf.new
	mv -v $(SOURCE)/loncom/loncapa_apache.conf.new \
	$(SOURCE)/loncom/loncapa_apache.conf

# ========= *** Makefile.* TARGETS BUILT DYNAMICALLY FROM loncapafiles.lpml ***

Makefile.configinstall: $(SOURCE)/doc/loncapafiles/loncapafiles.lpml \
                        lpml_parse.pl
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl configinstall $(CATEGORY) $(DIST) "$(SOURCE)" \
	"$(TARGET)" > Makefile.configinstall

Makefile.build: $(SOURCE)/doc/loncapafiles/loncapafiles.lpml lpml_parse.pl
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl build $(CATEGORY) $(DIST) "$(SOURCE)" "$(TARGET)" \
	> Makefile.build

Makefile.install: alwaysrun
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl install $(CATEGORY) $(DIST) "$(SOURCE)" \
	"$(TARGET)" > Makefile.install

# ============= *** TARGETS FOR OPERATING ON FILESYSTEMS ACROSS THE NETWORK ***

lpmladm:
	@if (test $(METAMTARGET) = "TRANSPORT"); then \
		echo "Transporting to $(HOSTNAME)"; \
		sudo make DIST=$(DIST) CATEGORY=$(CATEGORY) \
		SOURCE="$(SOURCE)" \
		TARGET="lpmladm.$(TIMESTAMP)" \
		NORESTORECONF="$(NORESTORECONF)" "$(MTARGET)"; \
		cd lpmladm.$(TIMESTAMP); \
		sudo tar czvf ../tarball$(TIMESTAMP).tar.gz .; \
		cd ..; scp tarball$(TIMESTAMP).tar.gz \
		lpmladm@$(HOSTNAME):~/tarball$(TIMESTAMP).tar.gz; \
		ssh lpmladm@$(HOSTNAME) sudo mv tarball$(TIMESTAMP).tar.gz /; \
		ssh lpmladm@$(HOSTNAME) sudo tar -x -z -v -C / \
		-p --same-owner -f \
		/tarball$(TIMESTAMP).tar.gz; \
		ssh lpmladm@$(HOSTNAME) sudo rm -f \
		/tarball$(TIMESTAMP).tar.gz; \
	elif (test $(METAMTARGET) = "LAUNCH"); then \
		echo "Launching process on $(HOSTNAME)"; \
		LAUNCHSAVE=$(OUTSTREAM) $(SAVE); \
		make DIST=$(DIST) CATEGORY=$(CATEGORY) SOURCE="$(SOURCE)" \
		TARGET="$(TARGET)" NORESTORECONF="$(NORESTORECONF)" \
		LAUNCH="$(LAUNCHSAVE)" "$(MTARGET)"; \
		scp $(SAVE) lpmladm@$(HOSTNAME):~/$(SAVE); \
		ssh lpmladm@$(HOSTNAME) sudo perl $(SAVE); \
		ssh lpmladm@$(HOSTNAME) sudo rm -f $(SAVE); \
	else \
		echo "**** ERROR **** Incorrect METAMTARGET"; \
	fi

NET_hosts_and_domain_tab:
	make TIMESTAMP=`date +"%s"` METAMTARGET="TRANSPORT" \
	MTARGET="hosts_and_domain_tab" HOSTNAME="$(HOSTNAME)" lpmladm

NET_webserverconf:
	make TIMESTAMP=`date +"%s"` METAMTARGET="LAUNCH" \
	MTARGET="webserverconf" HOSTNAME="$(HOSTNAME)" lpmladm

NET_rawinstall:
	make TIMESTAMP=`date +"%s"` METAMTARGET="TRANSPORT" \
	MTARGET="rawinstall" HOSTNAME="$(HOSTNAME)" lpmladm

# ============== *** TARGETS FOR MAKING LISTS (MANIFESTS) OF LON-CAPA FILES ***

MANIFEST_all:
	# --------------------------------------------------------- start clean
	rm -f $(SOURCE)/MANIFEST
	make MANIFEST_lpml
	make MANIFEST_vanillatar
	make MANIFEST_cvs
	# ---------------------------------- might as well include the MANIFEST
	echo 'MANIFEST' >> $(SOURCE)/MANIFEST
	# ------------------------------------------ hosts.tab are belong to us
	echo 'loncom/rawhide_hosts.tab' >> $(SOURCE)/MANIFEST
	echo 'loncom/production_hosts.tab' >> $(SOURCE)/MANIFEST
	echo 'loncom/development_hosts.tab' >> $(SOURCE)/MANIFEST
	echo 'loncom/production_domain.tab' >> $(SOURCE)/MANIFEST
	echo 'loncom/development_domain.tab' >> $(SOURCE)/MANIFEST
	# ------------------ Files needed for dynamically generated directories
	echo 'doc/man' >> $(SOURCE)/MANIFEST
	echo 'doc/lib' >> $(SOURCE)/MANIFEST
	echo 'doc/lib/perl' >> $(SOURCE)/MANIFEST
	echo 'doc/lib/perl/Apache' >> $(SOURCE)/MANIFEST
	echo 'doc/scripts' >> $(SOURCE)/MANIFEST
	# --------------------------------------------------- Clean up MANIFEST
	cd $(SOURCE); \
	sort MANIFEST | perl -nle 'print "$(DIRTARGET)/$$_"' | \
	perl -nle 's/\w+\/\.\.\///g;s/\w+\/\.\.\///g;print' | \
	perl -nle 's/\w+\/\.\.\///g;s/\w+\/\.\.\///g;print' | \
	perl -nle 's/\w+\/\.\.\///g;s/\w+\/\.\.\///g;print' | \
	perl -nle 's/\/\.\//\//g;print' | sort | uniq > \
	MANIFEST_loncapa
	cd $(SOURCE); mv -v MANIFEST_loncapa MANIFEST

# --------------- MANIFEST files with important CVS versioning/date information
MANIFEST_cvs:
	# ------ CVS/Entries directories to retain 'time-checking' intelligence
	cd $(SOURCE); find . -type f -name 'Entries' | grep 'CVS/Entries' >> \
	MANIFEST

# ------------------- MANIFEST the building, testing and standard loncapa files
MANIFEST_lpml:
	cat $(SOURCE)/doc/loncapafiles/buildfiles.lpml | \
	perl lpml_parse.pl MANIFEST development $(DIST) \
	'$(SOURCE)' '$(TARGET)' | grep '[[:alnum:]]' >> $(SOURCE)/MANIFEST
	cat $(SOURCE)/doc/loncapafiles/testfiles.lpml | \
	perl lpml_parse.pl MANIFEST development $(DIST) \
	'$(SOURCE)' '$(TARGET)' | grep '[[:alnum:]]' >> $(SOURCE)/MANIFEST
	cat $(SOURCE)/doc/loncapafiles/installfiles.lpml | \
	perl lpml_parse.pl MANIFEST development $(DIST) \
	'$(SOURCE)' '$(TARGET)' | grep '[[:alnum:]]' >> $(SOURCE)/MANIFEST
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl MANIFEST development $(DIST) \
	'$(SOURCE)' '$(TARGET)' | grep '[[:alnum:]]' >> $(SOURCE)/MANIFEST

# ------------ Files for top-level (the vanilla layer that the user first sees)
MANIFEST_vanillatar:
	echo 'README' >> $(SOURCE)/MANIFEST
	echo 'UPDATE' >> $(SOURCE)/MANIFEST
	echo 'TEST' >> $(SOURCE)/MANIFEST
	echo 'CHECKRPMS' >> $(SOURCE)/MANIFEST

# =============================================== *** STATUS REPORT TARGETS ***

warningnote:
	@if (test -s WARNINGS); then \
		W=`grep -c '\*\*\*\* WARNING' WARNINGS`; \
		E=`grep -c '\*\*\*\* ERROR' WARNINGS`; \
		N=`grep -c '\*\*\*\* NOTE' WARNINGS`; \
		echo "--->  $$W WARNINGS ENCOUNTERED!       "; \
		echo "--->  $$E ERRORS ENCOUNTERED!         "; \
		echo "--->  $$N NOTES ENCOUNTERED!          "; \
		echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; \
		echo "!!!!  Please read the WARNINGS file !!!!"; \
		echo "!!!!   to make sure everything is   !!!!"; \
		echo "!!!!    correct and taken care of   !!!!"; \
		echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; \
	fi

HTML:
	install -d HTML
	cp $(SOURCE)/doc/loncapafiles/*.gif HTML
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl html development default "$(SOURCE)" '$(TARGET)' \
	> HTML/index.html

status:
	install -d HTML
	cp $(SOURCE)/doc/loncapafiles/*.gif HTML
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl html $(CATEGORY) $(DIST) "$(SOURCE)" "($TARGET)" | \
	perl lpml_html_posteval.pl > \
	HTML/filestatus.html

statuspost: status
	cp $(SOURCE)/doc/loncapafiles/*.gif \
	$(TARGET)/home/httpd/html/lon-status
	cp HTML/filestatus.html \
	$(TARGET)/home/httpd/html/lon-status/filestatus.html

rpmstatus:
	install -d RPMSTATUS
	rpm -qa --queryformat \
	'%{NAME}\t%{VERSION}\t%{RELEASE}\t%{BUILDTIME}\n' | sort > \
	RPMSTATUS/current.tmp
	cat $(SOURCE)/doc/otherfiles/cd_rpms.txt > RPMSTATUS/standard.tmp
	cat $(SOURCE)/doc/otherfiles/rpm_list.txt > RPMSTATUS/expected.tmp
	perl rpmparse.pl RPMSTATUS/standard.tmp RPMSTATUS/current.tmp \
	RPMSTATUS/expected.tmp > RPMSTATUS/rpmstatus.html

rpmstatuspost: rpmstatus
	cp RPMSTATUS/rpmstatus.html /home/httpd/html/lon-status/rpmstatus.html

# ======================================= *** ALTERNATIVE PACKAGING TARGETS ***

RPM: BinaryRoot base_rpm_file_list
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl make_rpm $(CATEGORY) $(DIST) $(SOURCE) $(TARGET) \
	> base_customizerpm.xml
	cat base_rpm_file_list.txt | perl make_rpm.pl base $(VERSION) \
	$(RELEASE) '' '' BinaryRoot base_customizerpm.xml

DPKG:
	make TARGET='lon-capa-$(VERSION)' NORESTORECONF='1' install
	@echo "You will next need to follow instructions at:"
	@echo "http://people.debian.org/~jaldhar/make_package1.html"
	@echo "A directory with a snapshot of the debian package files"
	@echo "is LON-CAPA-base."
# What DPKG steps need to happen (for future implementation):
# export EMAIL="" ... probably sharrison@mail.lon-capa.org
# deb-make
# edit debian/control
# make debian/dirs file
# make debian/copyright file
# debian/README.debian... point them to LON-CAPA URLS
# debian/changelog
# debian/conffiles
# debuild
# and maybe do some GPG-related steps around here

base_rpm_file_list:
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl rpm_file_list $(CATEGORY) $(DIST) $(SOURCE) \
	'BinaryRoot' | sort > base_rpm_file_list.txt

BinaryRoot: base_rpm_file_list
	make TARGET='BinaryRoot' NORESTORECONF='1' install

# ======================================== *** MASTER DOCUMENTATION TARGETS ***

# Generates CVS:loncom/build/docs; root location of install.lon-capa.org
doc:
	install -d docs
	@if (test -e installation_manual.pdf); then \
		cp -vf installation_manual.pdf docs/.; \
	else \
		touch docs/installation_manual.pdf; \
	fi
	install -m 0755 -d docs/icons
	install -m 0644 $(SOURCE)/doc/icons/[^C][^V]* docs/icons
	install -m 0755 -d docs/reconfig
	cd docs; ln -fs installation_manual.pdf index.pdf
	cd docs/reconfig; ln -fs ../installation_manual.pdf index.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/reconfig.html > docs/reconfig/index.html
	install -m 0755 -d docs/reconfig/confexamples
	install -m 0644 $(SOURCE)/doc/build/confexamples/[^C][^V]* \
		docs/reconfig/confexamples
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/installindex.html > docs/index.html
	install -m 0755 -d docs/license
	cd docs/license; ln -fs ../installation_manual.pdf index.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/license.html > docs/license/index.html
	install -m 0755 -d docs/contact
	cd docs/contact; ln -fs ../installation_manual.pdf index.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/contact.html > docs/contact/index.html
	install -m 0755 -d docs/faq
	cd docs/faq; ln -fs ../installation_manual.pdf index.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/faq.html > docs/faq/index.html
	install -m 0755 -d docs/downloads
	cd docs/downloads; ln -fs ../installation_manual.pdf download.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/download.html > docs/downloads/index.html
	install -m 0755 -d docs/install
	cd docs/install; ln -fs ../installation_manual.pdf install.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/install.html > docs/install/index.html
	cp -v $(SOURCE)/doc/install/redhat7.3/new_install_rh73.html \
		docs/install/rh73.html
	cp -v $(SOURCE)/doc/install/redhat7.3/new_install_rh73.html \
		docs/downloads/rh73.html
	install -m 0755 -d docs/upgrade
	cd docs/upgrade; ln -fs ../installation_manual.pdf upgrade.pdf
	perl doc_template.pl $(SOURCE)/doc/templates/template.html \
		$(SOURCE)/doc/build/upgrade.html > docs/upgrade/index.html
	cd docs; tar czvpf ../docs.tar.gz .

pdfdoc: TEST_html2ps
	install -d pdfdoc
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/installindex_noform.html > pdfdoc/installindex.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/reconfig.html | \
	perl -nle 's/\[EXAMPLE\]/\[EXAMPLE \(at end of document\)\]/g;print' \
	> pdfdoc/reconfig.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/install.html > pdfdoc/install.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/upgrade.html > pdfdoc/upgrade.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/faq.html > pdfdoc/faq.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/download.html > pdfdoc/download.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/contact.html > pdfdoc/contact.ps
	/usr/local/html2ps/bin/html2ps -D \
	$(SOURCE)/doc/build/license.html > pdfdoc/license.ps
#       This creates a bad confexamples.ps... so take the long way around
#	cd $(SOURCE)/doc/build/confexamples; \
#	mpage -P- -1 -H [^C]* > ../../../loncom/build/pdfdoc/confexamples.ps
	install -d pdfdoc/confexamples
	cd $(SOURCE)/doc/build/confexamples; \
	find . -type f | cut -b3- | grep -v '^C' | grep -v 'keyword' | \
	perl -nle \
	'`mpage -P- -1 -H $$_ > ../../../loncom/build/pdfdoc/confexamples/$$_.ps`;'
	echo '' > pdfdoc/contents.txt
	echo '' >> pdfdoc/contents.txt
	echo '          The Learning Online Network' >> pdfdoc/contents.txt
	echo '                    with the' >> pdfdoc/contents.txt
	echo '     Computer-Assisted Personalized Approach' >> \
	pdfdoc/contents.txt
	echo '' >> pdfdoc/contents.txt
	echo '' >> pdfdoc/contents.txt
	echo 'CONTENTS' >> pdfdoc/contents.txt
	echo '--------' >> pdfdoc/contents.txt
	echo 'Opening' >> pdfdoc/contents.txt
	echo 'Configuration' >> pdfdoc/contents.txt
	echo 'Installation' >> pdfdoc/contents.txt
	echo 'Upgrading a LON-CAPA Server' >> pdfdoc/contents.txt
	echo 'FAQ' >> pdfdoc/contents.txt
	echo 'Download' >> pdfdoc/contents.txt
	echo 'Contact Information' >> pdfdoc/contents.txt
	echo 'License Information' >> pdfdoc/contents.txt
	echo 'Configuration Examples' >> pdfdoc/contents.txt
	mpage -P- -1 \
	pdfdoc/contents.txt \
	pdfdoc/installindex.ps \
	pdfdoc/reconfig.ps \
	pdfdoc/install.ps \
	pdfdoc/upgrade.ps \
	pdfdoc/faq.ps \
	pdfdoc/download.ps \
	pdfdoc/contact.ps \
	pdfdoc/license.ps \
	pdfdoc/confexamples/*.ps \
	> pdfdoc/installation_manual.ps
	ps2pdf pdfdoc/installation_manual.ps pdfdoc/installation_manual.pdf
	mv -vf pdfdoc/installation_manual.pdf .

# ================================================ *** KEEPING THINGS CLEAN ***

clean:
	rm -f buildflag
	rm -Rf HTML
	rm -f installation_manual.pdf
	rm -f Makefile.build
	rm -f Makefile.install
	rm -f Makefile.configinstall
	rm -Rf BinaryRoot
	rm -Rf SetupBinaryRoot
	rm -Rf LON-CAPA-base
	rm -f base_rpm_file_list.txt
	rm -f base_customizerpm.xml
	rm -f setup_rpm_file_list.txt
	rm -f docs.tar.gz
	rm -Rf docs
	rm -Rf pdfdoc
	rm -f program.pl*
	rm -Rf lpmladm.*
	rm -f WARNINGS
	rm -f CPAN_STATUS_REPORT
	rm -f $(SOURCE)/loncom/build/hosts.tab

reallyclean:
	rm -f buildflag
	rm -f $(SOURCE)/README
	rm -f $(SOURCE)/UPDATE
	rm -f $(SOURCE)/TEST
	rm -f $(SOURCE)/MANIFEST
	rm -f $(SOURCE)/MANIFEST_loncapa
	rm -f $(SOURCE)/loncapa
	rm -f $(SOURCE)/loncom/build/hosts.tab
	rm -f $(SOURCE)/loncapa.tar.gz
	rm -Rf HTML
	rm -f installation_manual.pdf
	rm -f Makefile.build
	rm -f Makefile.install
	rm -f Makefile.configinstall
	rm -Rf BinaryRoot
	rm -Rf SetupBinaryRoot
	rm -Rf LON-CAPA-base
	rm -f base_rpm_file_list.txt
	rm -f base_customizerpm.xml
	rm -f setup_rpm_file_list.txt
	rm -f docs.tar.gz
	rm -Rf docs
	rm -Rf pdfdoc
	rm -f program.pl*
	rm -Rf lpmladm.*
	make -f Makefile.cvs clean
	rm -f WARNINGS

uninstall:
	rm -f UNINSTALL_SHELL_COMMANDS
	cat $(SOURCE)/doc/loncapafiles/loncapafiles.lpml | \
	perl lpml_parse.pl uninstall_shell_commands $(CATEGORY) $(DIST) \
	"$(SOURCE)" "$(TARGET)" > UNINSTALL_SHELL_COMMANDS
	@echo -n "**** NOTE **** A file \"UNINSTALL_SHELL_COMMANDS\" has been "
	@echo "generated."
	@echo "First, you should view the contents of this file."
	@echo "If you are happy with the 'rm -Rf'! commands (or at least"
	@echo "have another job lined up in case of catastrophe), then you "
	@echo "can execute the following: sh ./UNINSTALL_SHELL_COMMANDS"

backup:
	@echo "Not yet implemented"

restore:
	@echo "Not yet implemented"

# ===================================================== *** AUXILIARY TESTS ***
localauth:
	@if (test -e $(LOCALAUTHPATH)/localauth.pm) && \
             !(diff $(LOCALAUTHPATH)/localauth-std.pm \
              $(LOCALAUTHPATH)/localauth.pm > /dev/null); then \
		echo "**** WARNING **** $(LOCALAUTHPATH)/localauth.pm is different than the $(LOCALAUTHPATH)/localauth-std.pm; if you have not customized localauth.pm, then please manually overwrite localauth.pm (rm $(LOCALAUTHPATH)/localauth.pm; ln -s $(LOCALAUTHPATH)/localauth-std.pm $(LOCALAUTHPATH)/localauth.pm); if you have customized localauth.pm, then please double-check to see that your customized localauth.pm is compatible with any localauth-std.pm changes for this version of LON-CAPA"| tee -a WARNINGS; \
	elif (test -e $(LOCALAUTHPATH)/localauth.pm) && \
              (diff $(LOCALAUTHPATH)/localauth-std.pm \
              $(LOCALAUTHPATH)/localauth.pm > /dev/null); then \
		echo "**** NOTE **** LOCAL AUTH IS IDENTICAL WITH STANDARD TEMPLATE"| tee -a WARNINGS; \
	elif !(test -e $(LOCALAUTHPATH)/localauth.pm) && \
	      (test -e $(LOCALAUTHPATH)/localauth-std.pm); then \
		ln -s $(LOCALAUTHPATH)/localauth-std.pm $(LOCALAUTHPATH)/localauth.pm; \
	fi

# ================================================ *** A HELPFUL DEPENDENCY ***
alwaysrun:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>