# websrc/pictools/MakeTargets # for instructions, see ${PICTOOLS}/MakeVars #$(info Start reading MakeTargets $(shell date +%S.%N)) #################################################### # CAPFILE # # generate dependencies on CAPFILE # (MakeVars accepts only one .cap file) # # a .cap file is segmented by header lines like: # file: segmentname description # for each segment, gendirs generates subdirectory ./segmentname/ # and within it an index.php and a localcaptions.cap # where the latter is just the caption lines for that segment ifneq '$(CAPFILE)' '' # these dependencies drive the build # depend on CAPFILE # $(STAGE)/segmentname/index.php # $(STAGE)/segmentname/localcaptions.cap # $(STAGE)/(CAPFILE without extension)-titles.txt # the first also depends on INDEXTPL # the first two have order-only dependence on # $(STAGE)/segmentname/. # list all segments named in CAPFILE _SEGMENTS = $(shell gawk '/file: / {print $$2;}' $(CAPFILE)) # SEGTITLESFILE is a single file with list entries for each segment _SEGTITLESFILE = $(STAGE)/$(CAPFILE:%.cap=%-titles.txt) # list of all generated index.php and localcaptions.cap files _SEGFILES = $(_SEGMENTS:%=$(STAGE)/%/index.$(GENDIRS_INDEXEXT)) \ $(_SEGMENTS:%=$(STAGE)/%/localcaptions.cap) # a signal file to record when segment files were uploaded _SEGSUPLOAD = $(STAGE)/segdirsuploaded # list of picturesdir: directories, after removing initial "/pictures" # (sort removes duplicate values) picdirs = $(sort $(shell gawk '/picturesdir: / {print gensub(/\/$$/, "", 1, $$2);}' $(CAPFILE))) _PICDIRSLIST = $(picdirs:$(PICTREESUBPATH)%=%) capinfo: @echo _SEGMENTS: $(_SEGMENTS) @echo _SEGFILES: $(_SEGFILES) @echo _PICDIRSLIST: $(_PICDIRSLIST) ############################################## End of rules for .cap files else _SEGSUPLOAD = _PICDIRSLIST = capinfo: @echo ############## There is no .cap file ################### endif ################# # general targets .PHONY: build buildall upload uploadall buildall: build @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir buildall; \ done uploadall: upload uploadsubdirs uploadsubdirs: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir uploadall; \ done .PHONY: clean cleansubdirs cleanall clean: rm -rf $(JUNKFILES) cleanall: cleansubdirs clean cleansubdirs: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir cleanall; \ done # the server balks at rapid ssh, so we avoid parallel execution .NOTPARALLEL : # this is the oldversion with $(PICSCP) # ${PICSCP} $(notdir $?) \ # $(SSHDEST):$(subst $(STAGINGAREA),$(PICSDIR),$(dir $<)) ;\ # ssh $(SSHDEST) /bin/sh -c "'cd $(subst $(STAGINGAREA),$(PICSDIR),$(dir $<)); \ # chmod a+r $(notdir $?);'"; \ ################################### # build - copy / generate files to STAGE directory # # BUILDONLY, _COPYTWICE, gendirs, BUILDTOSTAGE, segfiles, DirSrc.tgz _BUILDLIST = prebuild $(BUILDONLY) $(_COPYTWICEONSTAGE) \ $(_BUILDONTOSTAGE) $(_SEGTITLESFILE) DirSrc.tgz $(FINISH_BUILD) build: $(_BUILDLIST) prebuild: ; @echo -e "\n \#\#\# BUILD/COPY to STAGE from $(CURDIR) \n" # cause reconstruction to STAGE and upload of all files # (does NOT remove any files from server) rebuild: rmSTAGE upload rmSTAGE: ; rm -rf $(STAGE) # ensure stage directory is created before we try to write to it $(_BUILDLIST) : | $(STAGE)/. DirSrc.tgz: ${wildcard $(SRCTAR_FILES)} tar -c -z $(_TAR_EXCLUDES) $^ -f $(STAGE)/DirSrc.tgz _GENDIRS_ARGS = -d $(SRC) ${DEFINES} -n $(THUMBCOLS) $(CAPFILE) # this rule generates files directly to $STAGE/segmentname* $(_SEGTITLESFILE) $(_SEGFILES): $(CAPFILE) | $(STAGE)/. @echo @echo \#\#\# CREATE on STAGE the content due to CAPFILE $(SRC)/$(CAPFILE) @echo @echo for $(CAPFILE) in $(STAGE) run gendirs.csh $(_GENDIRS_ARGS) ifdef PICTOOLSDEBUG @echo "MakeTargets: cd $(STAGE) AND eval gendirs.csh \ $(_GENDIRS_ARGS)" >> /tmp/pictoolsdebug.log; endif @cd $(STAGE) && eval $(PICTOOLS)/gendirs.csh $(_GENDIRS_ARGS) ################################### # copy to stage # # _COPYTWICE # $(_COPYTWICEONSTAGE): $(STAGE)/%: % | $(STAGE)/. cp -R $? $(STAGE) ################################### # upload # # _COPYTWICE BUILDTOSTAGE _SEGMENTS UPLOADPIX # # create directories on server for # thisdir # this00dir/segmentname, for each segment # upload from stage # files copied to stage for _COPYTWICE # files built to stage for BUILDTOSTAGE # xxx-titles.txt, from the CAPFILE, xxx.cap # index.php and localcaptions.cap, for each segment # each STAGE directory (other than for SEGMENTS) will have two flag files, # serverdir for when the directory has been made on the server # uploadtime for when it was uploaded # make directory on server (& remember by creating 'serverdir' $(STAGE)/serverdir: | $(STAGE)/. ifeq '${PICSCP}' 'fakescp' picmkdir ${SERVER) else ssh ${SSHDEST} "mkdir -p $(PICSDIR)$(_SITEPATH)" $(AFTERSSH) endif touch $@ # the upload target itself; scp from STAGE to server upload: $(_BUILDLIST) $(STAGE)/serverdir $(_SEGSUPLOAD) uploadpix \ ${FINISH_UPLOAD} # upload files from STAGE/. itself # need to name the files listed in _BUILDLIST (todo why two lists?) #_UPLOAD_PREREQS = $(_COPYTWICE:%=$(STAGE)/%) \ # $(BUILDTOSTAGE:%=$(STAGE)/%) \ # $(CAPFILE:%.cap=$(STAGE)/%-titles.txt) \ # $(STAGE)/DirSrc.tgz #$(info _UPLOAD_PREREQS are $(_UPLOAD_PREREQS)) #$(info ### UPLOADTIME $(shell ls -l $(STAGE)/uploadtime 2>&1 )) export SSHDEST PICSDIR _SITEPATH AFTERSSH doupload: $(MAKE) -f $(PICTOOLS)/StageMake -C $(STAGE) uploadtime ## copy all prerequisites to the server directory of the first prerequisite ## (so all will go to same directory) #TOSTAGE = $(filter-out %/uploadtime %/serverdir, $(wildcard $(STAGE)/*)) #$(info TOSTAGE $(TOSTAGE #$(STAGE)/uploadtime:: $(TOSTAGE) # @echo # @echo \#\#\# UPLOAD from STAGE to $(SSHDEST)/$(PICSDIR)$(_SITEPATH): # @echo \ \ \ $(notdir $?) # @echo # @if [ -n "$?" ] ; then \ # chmod a+rx $(dir $<); \ # cd $(dir $<); \ # chmod a+r $(notdir $?) ; \ # tar -c -z -f - $(notdir $?) \ # | (ssh $(SSHDEST) tar --warning=no-timestamp \ # -C $(PICSDIR)$(_SITEPATH) -x -z -f -) ; \ # fi # touch $@ # $(AFTERSSH) # upload all subdirs generated for segments in caps file # (exercised _SEGSUPLOAD has this target instead of empty) $(STAGE)/segdirsuploaded : \ $(_SEGMENTS:%=$(STAGE)/%/index.$(GENDIRS_INDEXEXT)) \ $(_SEGMENTS:%=$(STAGE)/%/localcaptions.cap) @echo @echo \#\#\# UPLOAD from STAGE to $(SSHDEST)/$(PICSDIR)$(_SITEPATH) FOR $(CAPFILE) @echo chmod a+rx $(_SEGMENTS:%=$(STAGE)/%) chmod a+r $^ tar -C $(STAGE) -c -z ${_TAR_EXCLUDES} -f - $(_SEGMENTS) \ | (ssh $(SSHDEST) tar -C $(PICSDIR)$(_SITEPATH) -x -z \ --warning=no-timestamp -f -) touch $@ $(AFTERSSH) .PRECIOUS: $(STAGE)/. $(STAGE)/serverdir $(_PICDIRSLIST:%=$(PIXSTAGE)/%/.) # many complexities arose when I tried to build pictures separately # it is far easier to just build and upload all together .PHONY: uploadpix $(_PICDIRSLIST) uploadpix: $(_PICDIRSLIST) $(_PICDIRSLIST): $(MAKE) -C $(PICTURESROOT)$@ -f $(PICTOOLS)/MakeServerPix upload #$(info Finished reading MakeTargets $(shell date +%S.%N))