views:

64

answers:

1

It does not print itself.

$ cat Makefile 
files := $(foreach dir,.,$(wildcard $(dir)/*))


all:
         cat $(files)
$ make
cat 
a
a
b
b
^C%
$ ls -lsa .
total 20
4 drwxr-xr-x  3 tester  tester  512 Oct 20 15:01 .
4 drwxr-xr-x  3 tester  tester  512 Oct 20 14:19 ..
4 -rw-r--r--  1 tester  tester   69 Oct 20 15:01 Makefile
$ cat ./*
files := $(foreach dir,.,$(wildcard $(dir)/*))


all:
         cat $(files)
+1  A: 

Why you would want to do this is beyond me but why not have your Makefile thus:

all:
    @cat Makefile

The code you have attempts to print every file in the directory, at least under GNU Make 3.81.

It appears, from your transcript, that your $(files) variable in the cat is expanding to nothing, which means you're just running cat on its own. I gather you typed in a and bb and they were echoed back by the cat before you broke out with CTRLC or equivalent.

I get the same effect when I change that first line to xfiles := ....

I would look into the documentation to ensure OBSD (your version) supports this foreach construct (and wildcard). If not, you'll have to find another way.

paxdiablo
works in OBSD and ubuntu (Gnu make 3.81).
HH
@paxdiablo: "make --version" outputs void but its version is OBSD make 1.61, you read the source here: http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/make/make.c?rev=1.61
HH
I dare say that `$(foreach)` is a GNU extension, so it's probably being misinterpreted as a variable expansion by OBSD make.
Jack Kelly