# -*- Makefile -*- # $Id: lgrind.mk.in.in,v 1.7 2010/09/21 12:14:58 dan Exp $ # # Makefile fragment for processing lgrind files to produce postscript # # Copyright (c) 2005, 2010 Dan McMahill # # Copyright (c) 2005 Peter Bex # All rights reserved. # # This code is derived from software written by Dan McMahill # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Dan McMahill # 4. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # ####################################### # # TODO: # - Add a way to deal with specifying the language on a per-file # or maybe per-directory basis. Maybe per-directory is a good # start. # # - Add support for files with no extension. Need to make sure # we don't have problems with CVS/ directories. In fact, we # need to make sure we don't have issues with foo.bar directories. # # - Add support for inline lgrind sources using the %(...)% notation # # README: # # To use this makefile fragment, set the variable: # LGRINDSRCS = the source files to process # in your top level Makefile. You can also specify # LGRINDDIRS which is a list of directories containing # source files. All source files in the specified directories # are added to LGRINDSRCS # # The following variables may be overridden in your top level Makefile # # LGRIND = the lgrind executable # LGRIND_FLAGS = flags passed to lgrind for exporting to tex # ####################################### # how to call lgrind to convert source files to TeX LGRIND?= @LGRIND@ LGRIND_FLAGS?= -i ####################################### # # Process LGRINDDIRS, adding to LGRINDSRCS # ####################################### # pick out $(LGRINDDIRS)/*.* except for *.tex for each # specified directory. This is how we will # deal with basically any source code file type. The # exception will be things like Makefiles which do not # have an extension usually. # While we're processing these directories, check for a directory # specific LGRIND_FLAGS (i.e. mydir_LGRIND_FLAGS). If it is defined # then assign it to the file specific lgrind flags for each source # file if the source file does not already have its own file specific # flags BMK:.if defined(LGRINDDIRS) BMK:.for __tmp__ in ${LGRINDDIRS} BMK:.if exists(${__tmp__}) BMK:_LGRIND_ADDALL_${__tmp__}!= ls ${__tmp__}/*.* BMK:_LGRIND_ADD_${__tmp__}= ${_LGRIND_ADDALL_${__tmp__}:C/.*.tex$//g} BMK:LGRINDSRCS+= ${_LGRIND_ADD_${__tmp__}} BMK:. if defined(${__tmp__}_LGRIND_FLAGS) BMK:. for __tmp2__ in ${_LGRIND_ADD_${__tmp__}} BMK:${__tmp2__}_LGRIND_FLAGS?= ${${__tmp__}_LGRIND_FLAGS} BMK:. endfor BMK:. endif BMK:.endif BMK:.endfor BMK:.endif GMK:define lgrinddir_flag_template GMK:$(1)_LGRIND_FLAGS?= $($(2)_LGRIND_FLAGS) GMK:endef GMK:define lgrindsrcs_add_template GMK:LGRINDSRCS+= ${_LGRIND_ADD_$(1)} GMK:ifdef $(1)_LGRIND_FLAGS GMK:$(foreach __tmp2__,$(_LGRIND_ADD_$(1)),$(eval $(call lgrinddir_flag_template,$(__tmp2__),$(1)))) GMK:endif GMK:endef GMK:define lgrinddirs_template GMK:_LGRIND_ADD_$(1)= $(filter-out %.tex,$(wildcard $(1)/*.*)) GMK:endef GMK:$(foreach __tmp__,$(LGRINDDIRS),$(eval $(call lgrinddirs_template,$(__tmp__)))) GMK:$(foreach __tmp__,$(LGRINDDIRS),$(eval $(call lgrindsrcs_add_template,$(__tmp__)))) ####################################### # # Process proj_LGRINDDIRS, adding to proj_LGRINDSRCS # ####################################### BMK:.for __name__ in ${NAME} BMK:.if defined(${__name__}_LGRINDDIRS) BMK:.for __tmp__ in ${${__name__}_LGRINDDIRS} BMK:.if exists(${__tmp__}) BMK:_LGRIND_ADDALL2_${__tmp__}!=ls ${__tmp__}/*.* BMK:_LGRIND_ADD2_${__tmp__}= ${_LGRIND_ADDALL2_${__tmp__}:C/.*.tex$//g} BMK:${__name__}_LGRINDSRCS+= ${_LGRIND_ADD2_${__tmp__}} BMK:. if defined(${__tmp__}_LGRIND_FLAGS) BMK:. for __tmp2__ in ${_LGRIND_ADD2_${__tmp__}} BMK:${__tmp2__}_LGRIND_FLAGS?= ${${__tmp__}_LGRIND_FLAGS} BMK:. endfor BMK:. endif BMK:.endif BMK:.endfor BMK:.endif BMK:${__name__}_DIST+= ${${__name__}_LGRINDSRCS} ${LGRINDSRCS} BMK:.endfor GMK:define proj_lgrindsrcs_add_template GMK:$(2)_LGRINDSRCS+= ${_LGRIND_ADD2_$(1)} GMK:ifdef $(1)_LGRIND_FLAGS GMK:$(foreach __tmp2__,$(_LGRIND_ADD2_$(1)),$(eval $(call lgrinddir_flag_template,$(__tmp2__),$(1)))) GMK:endif GMK:endef GMK:define proj_lgrinddirs_template GMK:_LGRIND_ADD2_$(1)= $(filter-out %.tex,$(wildcard $(1)/*.*)) GMK:endef GMK:define proj_lgrind_template GMK:ifdef $(1)_LGRINDDIRS GMK:$(foreach __tmp2__,$($(1)_LGRINDDIRS),$(eval $(call proj_lgrinddirs_template,$(__tmp2__)))) GMK:$(foreach __tmp2__,$($(1)_LGRINDDIRS),$(eval $(call proj_lgrindsrcs_add_template,$(__tmp2__),$(1)))) GMK:endif GMK:$(1)_DIST+= $($(1)_LGRINDSRCS) $(LGRINDSRCS) GMK:endef GMK:$(foreach __tmp__,$(NAME),$(eval $(call proj_lgrind_template,$(__tmp__)))) ####################################### # # Process proj_LGRINDSRCS to add to # prog_OTHER dependencies # ####################################### LGRINDOBJS?= $(LGRINDSRCS:=.tex) ALLLGRINDOBJS+= $(LGRINDOBJS) BMK:.for __tmp__ in ${NAME} BMK:.if defined(${__tmp__}_LGRINDSRCS) BMK:${__tmp__}_LGRINDOBJS?= ${${__tmp__}_LGRINDSRCS:=.tex} BMK:${__tmp__}_OTHER+= ${${__tmp__}_LGRINDOBJS} BMK:ALLLGRINDOBJS+= ${${__tmp__}_LGRINDOBJS} BMK:.endif BMK:.endfor GMK:# note, this had to be done in two steps (create proj_LGRINDOBJS, GMK:# and then add to proj_OTHER and ALLLGRINDOBJS) with GNU make 3.80 GMK:# don't really know why. GMK:define lgrindobjs_template GMK:ifdef $(1)_LGRINDSRCS GMK:$(1)_LGRINDOBJS?= ${$(1)_LGRINDSRCS:=.tex} GMK:endif GMK:endef GMK:$(foreach __tmp__,$(NAME),$(eval $(call lgrindobjs_template,$(__tmp__)))) GMK:define lgrinddeps_template GMK:ifdef $(1)_LGRINDSRCS GMK:$(1)_OTHER+= ${$(1)_LGRINDOBJS} GMK:ALLLGRINDOBJS+= ${$(1)_LGRINDOBJS} GMK:endif GMK:endef GMK:$(foreach __tmp__,$(NAME),$(eval $(call lgrinddeps_template,$(__tmp__)))) ####################################### # # Add the dependencies # ####################################### OTHER+= $(LGRINDOBJS) all:: $(ALLLGRINDOBJS) clean:: BMK:.for __tmp__ in $(ALLLGRINDOBJS) BMK: $(RM) -f $(__tmp__:Q) BMK:.endfor GMK: $(RM) -f $(ALLLGRINDOBJS) ####################################### # # And add the build rules. # # Note that we do this as a loop with explicit # rules for each file rather than a suffix # rule because we want to work on any input # file that lgrind can deal with # ####################################### BMK:.for __tmp__ in ${ALLLGRINDOBJS} BMK:${__tmp__}: ${__tmp__:.tex=} BMK: $(LGRIND:Q) $(LGRIND_FLAGS) ${${__tmp__:.tex=}_LGRIND_FLAGS} \ BMK: -o $@ ${__tmp__:.tex=} BMK:.endfor GMK:define lgrindrun_template GMK:$(1): $(1:.tex=) GMK: $(LGRIND) $(LGRIND_FLAGS) $($(1:.tex=)_LGRIND_FLAGS) -o $(1) $(1:.tex=) GMK:endef GMK:$(foreach __tmp__,$(ALLLGRINDOBJS),$(eval $(call lgrindrun_template,$(__tmp__))))