How to make configurable makefile and optional configuration for certain files? -


i've made makefile makes printable version of presentations.

how works:

  1. makes tiles each presentation
  2. concatenates presentations 1 big file
  3. not done yet: add numbers pages

the makefile:

slides_base_name := presentation-prefix-  files := $(shell ls $(slides_base_name)*.pdf)  out_dir := generated slides_dir := $(out_dir)/slides slides := $(addprefix $(slides_dir)/, $(files)) slides_concat := $(out_dir)/slides-oneside-print.pdf  cfg_file := config.env  trim := 0 0.36cm 0 0 # todo: read global config  $(slides_dir)/%.pdf : %.pdf     @echo generating: $< "->" $@     @# todo: read optional local config - "$<.cfg"     @pdfjam --nup 2x4 $< --outfile $@ --delta "0.1cm 0.1cm" --a4paper --frame true --trim "$(trim)" --clip true --width '9.45cm';   all: $(slides_concat)  $(slides_concat): $(slides)     @echo generating: $@ $^     @pdfjam $(slides) -o $@  $(slides): | $(slides_dir)  $(slides_dir):     mkdir -p $(slides_dir)  clean:     rm -rf $(out_dir) 

i make configurable. see "todo" in makefile.

how can add global config file:

  • reads property trim (more properties come, can't use trim := $(shell cat ...) ).
  • when global config file changes, , run make, gets remade.

some professors have inconsistent style of presentations, so: how can add optional config each file:

  • properties overridden config
  • not required, if present , changed - causes rebuild of presentation

i've been thinking changind rule: $(slides_dir)/%.pdf : %.pdf depend on global cfg, , optionaly depend on optional config file current presentation, wrap contents of rule own script , pass filenames script.

however, don't know proper way that. :)

here's started along way. configuration file have be written of course in make language.

so you'd start out using "include". you'll see can set include names variables or filename patterns gives way local filename optional or conditionally used.

you'll need pay attention include occurs relation things controls. , you'll have switch using := (expand in macro) = (expand when variable used)

as making sure things change when configuration file changes, that's having configuration files dependency of things have run when changes. put in variable below don't have list of configuration files, local, global, , on.

in autoconf system, example, config.status , config.h such configuration files; see how works in autoconf system looking @ 1 of makefiles configure generates.


here small example started. let of these files in same directory. create global configuration makefile called global-config.mk this:

 trim = 0 0.72cm 0 0 

and optional local configuration file called local-config.mk this:

 local_used=yep 

now in main makefile have among other things structure:

trim = 0 0.36cm 0 0  # used if not in config file local_used=nope  local_config=$(wildcard local-config.mk) # optional config config_files=global-config.mk $(local_config) include global-config.mk $(config_files)  slides: $(config_files)  # , other dependencies here     @echo trim $(trim)     @echo local used $(local_used) 

now try running make slides. get:

$ make slides trim 0 0.72cm 0 0 local used yep 

they try after commenting out line in global-config.mk:

# trim = 0 0.72cm 0 0 

i get:

$ make slides trim 0 0.36cm 0 0 local used yep 

finally remove local-config.mk. get:

$ make slides trim 0 0.36cm 0 0 local used nope 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -