help-make
[Top][All Lists]
Advanced

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

How filter file/directories from list with built in GNU Make capabilitie


From: Oleksandr Gavenko
Subject: How filter file/directories from list with built in GNU Make capabilities?
Date: Fri, 20 Aug 2010 16:56:52 +0300
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6

Assume I have such hierarchy:

src/module1/mod1.c
src/module2/mod2.c
src/my.c

With $(wildcard src/*) I can get

  src/module1 src/module2 src/my.c

I need split this list into 2 list, one with directory only:

  src/module1 src/module2

and one with file only:

  src/my.c

I know solution with $(shell ...), but this require creating external process.

I know solution based on source files naming: they contain dot.
This can  not work on dirs with dot in names.

PS.

When I wrote this mail I found solution!

Between built in GNU Make functions only few
can communicate with reality (file system).
These are

  shell, wildcard, realpath

shell I dislike for performance.

wildcard get existing files by pattern.
realpath get existing files.

If $(dir) exist then $(dir)/. also exist.
If $(file) exist then $(file)/. does not exist. So

filter-dir = $(foreach item,$1,$(if $(realpath $(wildcard $(item)/.)),$(item))) filter-file = $(foreach item,$1,$(if $(realpath $(wildcard $(item)/.)),,$(item)))

var = $(wildcard src/*)

$(error $(call filter-dir,$(var)))  # this line for test
$(error $(call filter-file,$(var))) # this line for test

realpath you can replace with widlcard.

--
С уважением, Александр Гавенко.



reply via email to

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