# websrc/pictools/Makevars # this file defines make variables for use in MakeTargets and UploadPix # this file and ./MakeTargets are a tool for # building files from PICSRC/THISDIR into PICSTAGE/THISDIR # and then uploading them to PICSERVER:PICSDIR/THISDIR # where the PIC... variables are set in the environment # and THISDIR is the path from PICSRC to the current directory # # Build and upload directories are created automatically. # # A Makefile is typically two or three lines: # SUBDIRS = subdirectories-if-any # include ${PICTOOLS}/MakeVars # # set additional variables (or add make targets) # include ${PICTOOLS}/MakeTargets # # Local targets. These operate only on the current directory: # build: transfer local files to PICSTAGE/THISDIR # upload: transfer files from stage area to server # clean: remove $(JUNKFILES) # MakeTargets, UploadPix, and similar include-able Makefiles # must define targets for build and upload. # # Recursive targets. Operate on this dir and all SUBDIRS. # The value of SUBDIRS may be set on the command line: # make SUBDIRS=2007 upload # It is not passed recursively, so the named sub-directories # and all their descendants are processed. # all: same as buildall # buildall: does build in this directory and then SUBDIRS # uploadall: does buildall, uploadall in the SUBDIRS, # and then upload # cleanall: do clean locally and recursively # Environment Variables # It is assumed that there are three directory trees having # the same subdirectories with the same names: # a source tree, a staging area, and the directories on the server # The following environment variables define these directories. # These values are used in a cygwin environment and so should # be relative to /cygdrive. None of the values should end with a slash. # PICTOOLS # must contain the path to this pictools directory # example value: /cygdrive/c/websrc/pictools # PICSRC # the path to the tree of directories holding the source # example value: /cygdrive/c/websrc # PICTURESROOT # the root of the tree of source pictures # example value: /cygdrive/c/pictures/ChosenOnes # PICSTAGE # the path to the tree of directories holding the staging area # example value: /cygdrive/c/physpics.com # PICSERVER # user name and host name of server # example value: physpics@physpics.com # PICSDIR # a directory suffix to PICSERVER. Example: httpdocs # the value may be a simple dot: . # PICSCP = scp # may be set to fakescp to use ftp instead of scp # PICPASS # if using fakescp, the ftp password must be supplied # if the variable is not set, a value is prompted for at runtime # # PICTOOLSDEBUG # If 1, some pictools append entries to /tmp/pictoolsdebug.log # Larger values may give more information. # (at present the tools are MakeTargets, gensite, gendirs) # # By the above, the server tree resides at ${PICSERVER}:${PICSDIR} # for example: physpics@physpics.com:httpdocs # # VARIABLES # # These variables are set by MakeVars and may be used by the client Makefile # THISDIR = path from $(PICSRC) to $(CURDIR) # something like: pictools/halo # DEST = ${PICSTAGE}/${THISDIR} # 'build' places files in this directory # SERVER = $(PICSERVER):$(PICSDIR)/$(THISDIR) # 'upload' runs 'scp' to copy from DEST to SERVER # SRC = the initial current directory # (some rules change to other directories) # # The following variables may be set by the client Makefile to direct the build # SUBDIRS = dir1 dir2 ... # subdirectories for buildall, updateall, and cleanall # COPYFILES = file1 file2 file3 ... # if needed, these files are built locally by 'build' # 'build' then copies these files to DEST # and 'upload' copies them from there to SERVER # UPLOADFILES = $(DEST)/file1 ... # these files are built into $(DEST) and later uploaded # BUILDFILES = files to be generated locally for the 'build' target # DIGESTDIR = name of pictures digest directory # This directory contains .jpg and other image files # that are to be viewed from the website. # They are all uploaded. An empty captions file can be # generated with 'make newcaps'. See CAPTIONS, below. # DEFINES = symbol defines for genhtml. Form: -Dsymbol=value # Typically used to fill in fields in templates. # example: DEFINES = -DtripTitle="Florida, Spring, 2007" # LOCALJUNK = list of files or wild cards: eg, *.o foo* # # The following variables are given tentative values in MakeVars # If the client wants some other value, it can reset them # # HTMLFILES = *.html # IMAGEFILES = *.png *.PNG *.jpg *.JPG *.gif *.GIF *.bmp *.BMP # JSFILES = *.js # CSSFILES = *.css # These are set in MakeVars to a list of the # files in the current directory. # These files are copied to DEST and uploaded to SERVER. # The list can be modified in the Makefile. # Note that only single case names are recognized. # # HINFILES = *.hin # List of .hin files. They are sources for .html files # The files are created in the staging tree, not locally. # HINFILES is initially $(wildcard *.hin), but can be # changed in the Makefile. # File xyz.html is generated from xyz.hin by running # genhtml -o $(DEST)/$(THISDIR)/xyz.html xyz.hin # so genhtml $ expansions may appear in .hin files. # CAPTIONS = *.cap # is set by MakeVars to *.cap. May be set by the # client to some other value. These files are all # processed through gendirs to create image viewing pages. # For each xxx.cap file, MakeTargets generates # a file called xxx-titles.txt. This has HTML code # for the elements of a list and should be $included in # one of the .hin files. That is, the HTML source should # have something like: # # JUNKFILES = *~ $(LOCALJUNK) # list of files to be removed for `make clean' # # If DIGESTDIR has been set, then a number of other variables will be set # They can be changed after the inclusion of MakeVars. # PICTURESDIR = directory containing pictures to be uploaded # PICTURES = $(PICTURESDIR)/*.{jpg,gif,png,JPG,GIF,PNG} # the names of the image files in PICTURESDIR. # (If there is a DIGESTDIR, its value is used as PICTURESDIR.) # extensions must be all caps or all lower # The files listed will be uploaded # INDEXTPL = $(SRC)/template.tpl # PICFILETPL = $(SRC)/frame.tpl # PICCELLTPL = $(SRC)/pictd.tpl # templates to use for gendirs. # To use different templates for different .hin files, # do them in two different directories. # If there is no local .tpl file, use the one in ${PICTOOLS} # THUMBCOLS = 3 # how many columns of thumb images to generate from gendirs # IMAGESCALE = xxx # rescaling parameter for ImageMagick # examples: 33% 768x768> 576x576> # THUMBSCALE = xxx # like SCALE, but for thumbs PICSCP ?= scp # get environment -include /etc/pictools.ini -include ${HOME}/.pictools.ini -include ${PICTOOLS}/.pictools.ini -include ${PICSRC}/.pictools.ini -include .pictools.ini PICTOOLSNOINI = 1 export PICTOOLSNOINI # check PICSRC ifeq "${PICSRC}" "" $(error PICSRC is undefined in the environment. Set it to the root of the tree of web page sources.) endif ifeq "${PICSRC}" "$(dir ${PICSRC})" $(error Value of PICSRC shold not end in a slash, \ but it does (${PICSRC})) endif ifneq "/" "$(patsubst /%,/,${PICSRC})" $(error PICSRC (${PICSRC}) does not begin with a slash, but must) endif ifeq "" "$(findstring ${PICSRC},$(CURDIR))" $(error This directory ($(CURDIR)) \ is not a descendent of PICSRC (${PICSRC})) endif ifeq '${PICSCP}' 'fakescp' ifndef PICPASS PICPASS := $(shell /bin/bash -c \ 'read -s -p "password for ${PICSERVER}: " foo; echo $$foo') _DISCARDVALUE := $(shell echo > /dev/tty) endif endif export PICSCP PICPASS PICTURESROOT PICSTAGE # capture curdir value for use in rules that change directory SRC := $(CURDIR) # set THISDIR to the path from .../websrc/ to this directory # (use CURDIR, but delete its initial string PICSRC) THISDIR := .$(subst ${PICSRC},,$(CURDIR)) # set destination in physpics.com on this machine DEST ?= ${PICSTAGE}/$(THISDIR) #set destination on server SERVER ?= ${PICSERVER}:${PICSDIR}/$(THISDIR) # make a list of local image, .js, and .css files to install IMAGEFILES ?= $(wildcard *.png *.PNG *.jpg *.JPG *.gif *.GIF) # javascript and CSS files are auromatically uploaded JSFILES ?= $(wildcard *.js) CSSFILES ?= $(wildcard *.css) # .hin files are automatically genhtml'ed to .html files and uploaded HINFILES ?= $(wildcard *.hin) # .html and .htm files are copied to staging area and uploaded to server HTMLFILES ?= $(wildcard *.html) $(wildcard *.htm) # .cap files are processed with gendirs and the results are uploaded CAPTIONS ?= $(wildcard *.cap) # JUNKFILES are deleted for `make clean' JUNKFILES ?= *~ $(LOCALJUNK) # set up picturesdir ifneq '$(DIGESTDIR)' '' PICTURESDIR ?= $(DIGESTDIR) else ifndef PICTURESROOT PICTURESDIR ?= . else ifeq "${PICTURESROOT}" "" $(error PICTURESROOT is undefined in the environment. \ Set it to the root of the tree of web page picture sources.) endif ifeq "${PICTURESROOT}" "$(dir ${PICTURESROOT})" $(error Value of PICTURESROOT shold not end in a slash, \ but it does (${PICTURESROOT})) endif ifneq "/" "$(patsubst /%,/,${PICTURESROOT})" $(error PICTURESROOT (${PICTURESROOT}) lacks inital slash) endif # set THISDIR as it will be set in MakeVars THISDIR := .$(subst ${PICSRC},,$(CURDIR)) ifeq "OKAY" "$(patsubst ./pictures%,OKAY,${THISDIR})" # set directory for source pictures PICTURESDIR ?= ${PICTURESROOT}/$(subst /pictures,,$(THISDIR)) endif # if path from PICSRC to THISDIR does not begin "/pictures" # we do not set PICTURESDIR at all endif # list pictures to be installed from DIGESTDIR or the local pictures tree ifneq '$(PICTURESDIR)' '' PICTURES ?= $(wildcard \ $(PICTURESDIR)/*.JPG $(PICTURESDIR)/*.jpg \ $(PICTURESDIR)/*.GIF $(PICTURESDIR)/*.gif \ $(PICTURESDIR)/*.PNG $(PICTURESDIR)/*.png) endif ################## # parameters for gendirs # templates INDEXTPL ?= $(SRC)/template.tpl PICFILETPL ?= $(SRC)/frame.tpl PICCELLTPL ?= $(SRC)/pictd.tpl ifeq "$(wildcard $(INDEXTPL))" "" INDEXTPL = $(PICTOOLS)/template.tpl endif ifeq "$(wildcard $(PICFILETPL))" "" PICFILETPL = $(PICTOOLS)/frame.tpl endif ifeq "$(wildcard $(PICCELLTPL))" "" PICCELLTPL = $(PICTOOLS)/pictd.tpl endif # how many columns of images THUMBCOLS ?= 3 # maximum dimension for full-sized and thumb images, respectively IMAGESCALE ?= 576x576> THUMBSCALE ?= 144x144> ################# # general targets #if SUBDIRS is specified on command line, do not pass it to $(MAKE) MAKEOVERRIDES := $(subst SUBDIRS=$(SUBDIRS),,$(MAKEOVERRIDES)) # and do not pass the local SUBDIRS to a child make unexport SUBDIRS # to get directory D created to store file D/F, # append a dependency to the rule as as 'order-only' prerequisite # D/F: file-prerequisites | D/. # The final slash and dot are essential. # the default action is buildall .PHONY: all build buildall upload uploadall all buildall: build @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir buildall; \ done uploadall: buildall uploadsubdirs upload uploadsubdirs: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir uploadall; \ done # rule to build directories %/.: mkdir -p $@ .PRECIOUS: %/. .PHONY: clean cleansubdirs cleanall clean: rm -rf $(JUNKFILES) cleanall: cleansubdirs clean cleansubdirs: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir cleanall; \ done # putting ${PICSTAGE}/.../directory/serverdir as a prerequisite # will invoke this rule to create the directory on the host # and to put the tag serverdir into STAGE ifeq '${PICSCP}' 'fakescp' %/serverdir: | %/. picmkdir ${PICSERVER}:$(@:$(PICSTAGE)/%/serverdir=$(PICSDIR)/%) touch $@ else %/serverdir: | %/. ssh ${PICSERVER} mkdir -p $(@:$(PICSTAGE)/%/serverdir=$(PICSDIR)/%) touch $@ endif # copy all prerequisites to the server directory of the first # (so all prerequisites will go to same directory) define run-scp @if [ -n "$?" ] ; then \ echo cd $(dir $<)\; ${PICSCP} $(notdir $?) \ $(PICSERVER):$(subst $(PICSTAGE),$(PICSDIR),$(dir $<)) ;\ cd $(dir $<); \ ${PICSCP} $(notdir $?) \ $(PICSERVER):$(subst $(PICSTAGE),$(PICSDIR),$(dir $<)) ;\ fi touch $@ endef make-thumb = convert $< -scale "$(THUMBSCALE)" $@ ifdef PICTOOLSDEBUG ifndef DEBUGMESSAGE __DISCARDVAR := $(shell echo `test $${PICTOOLSDEBUG:-0} -gt 0` $$?) ifeq ($(__DISCARDVAR),0) else ifeq ($(__DISCARDVAR),1) else $(error PICTOOLSDEBUG is ${PICTOOLSDEBUG}, \ but should be a small non-negative integer) endif DEBUGMESSAGE := $(shell if [ $${PICTOOLSDEBUG:-0} -gt 0 ] ; then echo DEBUG level $${PICTOOLSDEBUG}; fi ) export DEBUGMESSAGE $(warning $(DEBUGMESSAGE)) __DISCARDVAR := $(shell if [ $${PICTOOLSDEBUG:-0} -gt 0 ] ; then \ echo >> /tmp/pictoolsdebug.log ; \ echo '__________________________________________________________' >> /tmp/pictoolsdebug.log ; \ echo `date` $(DEBUGMESSAGE) $(CURDIR) >> /tmp/pictoolsdebug.log; \ echo PICTOOLS = '$(PICTOOLS)' >> /tmp/pictoolsdebug.log; \ echo PICSRC = '$(PICSRC)' >> /tmp/pictoolsdebug.log; \ echo PICTURESROOT = '$(PICTURESROOT)' >> /tmp/pictoolsdebug.log; \ echo PICSTAGE = '$(PICSTAGE)' >> /tmp/pictoolsdebug.log; \ echo PICSERVER = '$(PICSERVER)' >> /tmp/pictoolsdebug.log; \ echo PICSDIR = '$(PICSDIR)' >> /tmp/pictoolsdebug.log; \ echo PICTOOLSDEBUG = '$(PICTOOLSDEBUG)' >> /tmp/pictoolsdebug.log; \ echo THISDIR = '$(THISDIR)' >> /tmp/pictoolsdebug.log; \ echo DEST = '$(DEST)' >> /tmp/pictoolsdebug.log; \ echo SERVER = '$(SERVER)' >> /tmp/pictoolsdebug.log; \ echo SRC = '$(SRC)' >> /tmp/pictoolsdebug.log; \ echo SUBDIRS = '$(SUBDIRS)' >> /tmp/pictoolsdebug.log; \ echo COPYFILES = '$(COPYFILES)' >> /tmp/pictoolsdebug.log; \ echo UPLOADFILES = '$(UPLOADFILES)' >> /tmp/pictoolsdebug.log; \ echo BUILDFILES = '$(BUILDFILES)' >> /tmp/pictoolsdebug.log; \ echo DIGESTDIR = '$(DIGESTDIR)' >> /tmp/pictoolsdebug.log; \ echo DEFINES = '$(DEFINES)' >> /tmp/pictoolsdebug.log; \ echo LOCALJUNK = '$(LOCALJUNK)' >> /tmp/pictoolsdebug.log; \ echo IMAGEFILES = '$(IMAGEFILES)' >> /tmp/pictoolsdebug.log; \ echo JSFILES = '$(JSFILES)' >> /tmp/pictoolsdebug.log; \ echo CSSFILES = '$(CSSFILES)' >> /tmp/pictoolsdebug.log; \ echo HINFILES = '$(HINFILES)' >> /tmp/pictoolsdebug.log; \ echo CAPTIONS = '$(CAPTIONS)' >> /tmp/pictoolsdebug.log; \ echo JUNKFILES = '$(JUNKFILES)' >> /tmp/pictoolsdebug.log; \ echo PICTURES = '$(PICTURES)' >> /tmp/pictoolsdebug.log; \ echo INDEXTPL = '$(INDEXTPL)' >> /tmp/pictoolsdebug.log; \ echo PICFILETPL = '$(PICFILETPL)' >> /tmp/pictoolsdebug.log; \ echo PICCELLTPL = '$(PICCELLTPL)' >> /tmp/pictoolsdebug.log; \ echo THUMBCOLS = '$(THUMBCOLS)' >> /tmp/pictoolsdebug.log; \ echo IMAGESCALE = '$(IMAGESCALE)' >> /tmp/pictoolsdebug.log; \ echo THUMBSCALE = '$(THUMBSCALE)' >> /tmp/pictoolsdebug.log; \ echo PICTOOLSNOINI = '$(PICTOOLSNOINI)' >> /tmp/pictoolsdebug.log; \ echo PICPASS = '$(PICPASS)' >> /tmp/pictoolsdebug.log; \ echo PICSCP = '$(PICSCP)' >> /tmp/pictoolsdebug.log; \ echo HTMLFILES = '$(HTMLFILES )' >> /tmp/pictoolsdebug.log; \ echo PICTURESDIR = '$(PICTURESDIR)' >> /tmp/pictoolsdebug.log; \ fi) endif endif