S
S
Sergei E.2017-09-24 10:54:55
linux
Sergei E., 2017-09-24 10:54:55

How to execute a command for each element in a Makefile array?

I can't find a pretty way to execute a command (which only allows one argument) for each folder in the THEMES.

PREFIX ?= /usr
THEMES ?= ThemeOne ThemeTwo ThemeThree

all:

install:
  mkdir -p $(DESTDIR)$(PREFIX)/share/icons
  cp -R $(THEMES) $(DESTDIR)$(PREFIX)/share/icons

post-install:
  -gtk-update-icon-cache -q $(DESTDIR)$(PREFIX)/share/icons/ThemeOne
  -gtk-update-icon-cache -q $(DESTDIR)$(PREFIX)/share/icons/ThemeTwo
  -gtk-update-icon-cache -q $(DESTDIR)$(PREFIX)/share/icons/ThemeThree

uninstall:
  -rm -rf $(foreach theme,$(THEMES),$(DESTDIR)$(PREFIX)/share/icons/$(theme))

The example shows that for the purposes installand uninstallsuch a problem does not arise, but with post-installthis method it will not work, because.
gtk-update-icon-cache -q $(foreach theme,$(THEMES),$(DESTDIR)$(PREFIX)/share/icons/$(theme))

will build cache only for $(DESTDIR)$(PREFIX)/share/icons/ThemeOne.
I also know about the way:
.PHONY: $(THEMES)
$(THEMES):
  -gtk-update-icon-cache -q $(DESTDIR)$(PREFIX)/share/icons/[email protected]

post-install: $(THEMES)

but it will not allow other commands to be executed for the same directories if needed.
Interested primarily in pure make.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2017-09-24
@SmartFinn

Sergei E., Look at the eval example, it can be applied to your question: https
://www.gnu.org/software/make/manual/html_node...
as in the example. Actually, eval itself can not be used. There is more here - an example of using foreach.
But if you need to execute a complex sequence, then you can wrap it in eval with the definition of your functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question