help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically building (temp) include file - how to delete on exit?


From: gnu_make0
Subject: Re: dynamically building (temp) include file - how to delete on exit?
Date: Sun, 17 Jun 2012 15:30:59 -0500

On Sun 6/17/12 13:50 CDT address@hidden wrote:
> On Sat 6/16/12 14:23 EDT ogronom wrote:
> > From info make
> > 
> > The only processing `make' does on the result
> > is to convert each newline (or carriage-return / newline pair) to a
> > single space.  If there is a trailing (carriage-return and) newline it
> > will simply be removed.
> > 
> > So it looks like, that you can not change this behaviour. Workaround
> > depends on what your script actually does. For example suggested below
> > you can do something like this
> > 
> > vars_to_define=foo bam
> > foo_script=echo 123
> > bam_script=echo hi
> > 
> > $(foreach v,$(vars_to_define),$(eval $(v)=$(shell $($(v)_script))))
> > 
> > .PHONEY: bar
> > bar:
> >     @echo foo: $(foo)
> >     @echo
> >     @echo bam: $(bam)
> 
> Inspired by your hints, this approach ( no include file, but should allow
> dynamic macro definition ) is looking promising:

This uses mktemp.  The 'cat' w/in the makefile is only there (temporarily)
to show what the macro defs are.

  $ cat makefile 
  TMPF=$(shell tmpf=$$(mktemp /tmp/ddefs.XXXXXXXXX);_29r_dirdefs-make > 
$$tmpf;echo $$tmpf)

  $(foreach v,$(shell set -- $$(wc -l $(TMPF)); seq $$1),$(eval $(shell sed -ne 
$(v)p $(TMPF))))

  $(shell set -x;cat $(TMPF) >&2; :;rm -f $(TMPF))

  .PHONEY: bar
  bar:
          @echo _29C: $(_29C)
          @echo _29lib: $(_29lib)
  $ make bar 
  + cat /tmp/ddefs.ybJa29425
  _29C = /usr/local/7Rq/commands/cur
  _29c = /usr/local/7Rq/scommands/cur
  _29eloc = /etc/local
  _29lg = /var/local/team/mke/log
  _29lib = /usr/local/7Rq/lib/cur
  _29r = /usr/local/7Rq
  _29rev = cur
  _29team = /etc/local/team/mke
  _29pkg = /usr/local/7Rq/package/cur
  + :
  + rm -f /tmp/ddefs.PdKt29433
  _29C: /usr/local/7Rq/commands/cur
  _29lib: /usr/local/7Rq/lib/cur
  $ ls /tmp/ddefs.PdKt29433
  ls: /tmp/ddefs.PdKt29433: No such file or directory
  $ 

Above forks a shell and a sed for each line in the macro file,
so it's inefficient, but I may go ahead and use it.

--
Tom



reply via email to

[Prev in Thread] Current Thread [Next in Thread]