#!/bin/csh -f ###################################################################### # # Usage: # # % buildsite htmldir [option] # # Collects a list of directories that contain Makefiles and makes 'em all. # # [option] is a string to pass to make. # For example, "buildsite htmldir kill" removes all the zip files. "buildsite" with # no option rebuilds them. # # This script may be invoked from any folder within a website and will run # the makefiles in that folder and all those in folders beneath it. # # The only tricky part of this code is figuring out (by parsing the output from # 'pwd') the directory path to the top level of the website. We need this # for error-checking (to make sure the script isn't run, say, from the root (/) # directory) and to pass some useful macros into 'make'. # ###################################################################### set me=$0:t # the name of this program goto Start ###################################################################### Usage: echo "$me htmldir [option]" echo "Collects a list of directories from the named html directory" echo "on down that contain makefiles, and makes 'em all." echo echo "htmldir -- determines the starting point of the build:" echo " ati top of accesstoinsight.org hierarchy" echo " not top of notdotorgnot.com hierarchy" echo " pwd the current directory" echo echo "option -- any string to pass to the makefiles (e.g., 'kill')" echo exit ###################################################################### Start: if (! ${?DATE_FORMAT_ATI_REV_DATE}) then echo ${me}: DATE_FORMAT_ATI_REV_DATE environment variable not set\! exit endif if ($# < 1) then goto Usage endif ###################################################################### # go to the desired directory # (Add other directories and their tags here, as needed) set theSite = $1 if ($theSite == "ati") then cd ~/Sites/ati else if ($theSite == "not") then cd ~/Sites/notdotorgnot else if ($theSite == "pwd") then ; else goto Usage endif shift ###################################################################### # Now make sure that we're really in a website dir (to prevent us from # doing something bad like # # % cd / ; buildsite pwd # # which would try to execute every single makefile on our filesystem). # # So we'll compare the name of the current dir with that of a dir in a website # folder. # --> N.B.: This is highly implementation-specific. In Mac OS X, website # folders are traditionally located in /Users/foo_user/Sites". # If you put your website folders somewhere else, you'll # have to change all this accordingly. Good luck. :) set pwd = `pwd` # get the current folder set whoami = `whoami` # get the user name set sitesRoot = "/Users/${whoami}/Sites/" echo $pwd | grep $sitesRoot > /dev/null # does pwd contain the expected path? # --> N.B.: this is a weak test. What if the path doesn't *start* with # the expected string, but only *contains* the string? if ($status) then # if grep failed to find the expected string, then quit. echo "${pwd}: Not a website folder. Build failed." goto bye endif ###################################################################### # Now get the path of pwd that is relative to the sitesRoot folder # (But first, we have to tweak the pathname so that sed won't choke; # e.g., turn "foo/bar/" into "foo\/bar\/".) set sitesRoot2 = `echo $sitesRoot | sed -e "s/\//\\\//g"` set relativeDir=`echo $pwd | sed -e "s/"$sitesRoot2"//"` ###################################################################### # Our Makefiles use a few macros that we need to define. # # First, get the path to the top level folder of this site # (But first, we have to tweak the pathname so that sed won't choke; # e.g., turn "foo/bar/" into "foo\/bar\/".) set homeFolder = `echo $relativeDir | sed -e "s/\/.*//"` set homeFolder = "${sitesRoot}${homeFolder}" set zipFolder = "${homeFolder}/zip" # where the zip files go set pdfFolder = "${homeFolder}/pdf" # where the pdf files go setenv buildsite_ZIP_DIR $zipFolder # set the name of our special-purpose makefiles that this script recognizes set theMakeFile = "Buildfile" echo "Building site '$homeFolder':" echo " starting at: $pwd" echo " zip folder: $zipFolder" echo " pdf folder: $pdfFolder" # make a note of this invocation logsite ${me} "[$relativeDir]: " $* # bring all the ati tech files up to date if ($theSite == "ati") then sync-scripts build_includes_index css-progress endif # Build a list of dirs that contain Makefiles echo -n Finding the ${theMakeFile}s... set dirs = `find . -follow -name $theMakeFile | sed "s/\/$theMakeFile//"` if (${#dirs} == 0) then echo " 0 ${theMakeFile}s found. Nothing to do." goto bye else echo " Found ${#dirs} folders containing ${theMakeFile}s. Processing..." endif # args to pass to 'make': # -s for silent operation set makeArgs="-s -f Buildfile " # # N.B.: If a casual user were to stumble into a directory and if, upon # seeing a curious makefile, he or she were to type 'make', badnesses # would happen, since the makefile didn't have the necessary macros. # For example, files might get written into /lib instead of into # /Users/home/Sites/lib. This would be bad. To avoid this casual disaster, # we just give makefiles a different name, and invoke 'make' with the -f flag. ###################################################################### # now loop through all the dirs foreach dir ($dirs) pushd $dir > /dev/null #push into the dir echo -n "${dir}:" make $makeArgs #run the makefile echo popd > /dev/null #pop out of the dir end # ###################################################################### echo Finished executing the ${theMakeFile}s. # After a bunch of installs (say, at the end of a busy day), run makebulk # to update the zip copy of the whole website echo echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* echo \*\*\* Don\'t forget to run \'makebulk\' \*\*\* echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* echo bye: echo $me done. exit