0

Based upon How do I make multiple targets from a set of templates for the source?, I would now like to implement a simple-ish templating engine.

I'm quite happy with using sed for straight replacements, but I'd also like conditionals.

So, for example, if a template looked like this:

This is the file for engine:#if version != 'latest'##version#-#endif#alpine

Output for different versions (7.0 and latest for example).

This is the file for engine:7.0-alpine
This is the file for engine:alpine

Writing that in sed, whilst possible, does mean I'm having to reinvent the wheel somewhat.

What recommendations for simple templating available for a unix environment?

Richard A Quadling
  • 3,769
  • 30
  • 40

1 Answers1

0

GNUmake is a full but pretty awkward functional programming language. The upside of this is that you are rather free to code however you like because a) there is no "church of GNUmake" that would look down on your coding style and b) its ging to look ugly anyway. That said, a little help from a source library which is hiding away much of the strangenesses is not a bad advice.

With gmtt your example could look like this:

include gmtt.mk

version = latest

VERSION_STR = $(if $(call str-eq,$(version),latest),,$(version))
$(info This is the file for engine: $(VERSION_STR)alpine)
Vroomfondel
  • 2,704
  • 1
  • 15
  • 29