Issue with foreach statement

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with foreach statement

zxuiji
I don't know whether this is because of the way I used foreach or whether
it is because of the way I used gcc so I'm going to start with the snippet
involving my foreach statement:

CODIT_SRC:=$(sort $(notdir $(wildcard $(CODIT__SRC_DIR)*.c)))

> CODIT_OBJ:=$(CODIT_SRC:.c=.o)
> CODIT_DEP:=$(CODIT_SRC:.c=.d)
> CODIT_OUT:=$(CODIT_TARGETS:=.out)
> CODIT_VMK:=$(CODIT_TARGETS:=.vmk)
>
> # Ensure dependencies are up to date
> define CODIT_GEN_DEP
>     $(eval TMP_SRC=$(CODIT__SRC_DIR)$(subst .d,.c,$(1)))
>     $(eval TMP_DEP=$(CODIT__DEP_DIR)$(1))
>     $(eval TMP_OBJ=$(subst .d,.o,$(1)))
>     $(eval TMP_CFLAGS=$(CODIT_T_CFLAGS) $(CODIT_T_LFLAGS))
>     $(call CC_GEN_DEP,$(TMP_SRC),$(TMP_DEP),$(TMP_OBJ),$(TMP_CFLAGS))
> endef
>
> ifeq ("$(wildcard $(CODIT_DEP_DIR))","")
> $(shell mkdir $(CODIT_DEP_DIR))
> endif
>

$(foreach dependency,$(CODIT_DEP),$(call CODIT_GEN_DEP,$(dependency)))
>

The top half of this snippet was provided only for clarity, it's the last
line that I'm unsure if there is an issue with, if there's not then I will
try at the GCC mailing list. If you need it then here's the breakdown of
the CC_GEN_DEP

MGW64:=C:/tools/mingw64
> MGW64_PREFIX:=x86_64-w64-mingw32
>
... (Ommitted)

> MGW64_BIN_DIR:=$(MGW64)/bin
>
...

> MGW64_CC:="$(MGW64_BIN_DIR)/$(MGW64_PREFIX)-gcc.exe"
> define MGW64_GEN_DEP
>     $(info $(MGW64_CC) $(4) $(1) -MF $(2) -MT $(3) -MM)
>     $(shell $(MGW64_CC) $(4) $(1) -MF $(2) -MT $(3) -MM)
> endef
>
...

> CC_PREFIX=MGW$(HOST_SYS_BIT)
>
...

> # $(call CC_GEN_DEP,$(SRC),$(DEP),$(OBJ),$(CFLAGS))
> define CC_GEN_DEP
>     #(info $(0)=$(CC_PREFIX)_GEN_DEP,$(1),$(2),$(3),$(4))
>     $(call $(CC_PREFIX)_GEN_DEP,$(1),$(2),$(3),$(4))
> endef
>

And then the output:

> "C:/tools/mingw64/bin/x86_64-w64-mingw32-gcc.exe"  src/Codit-BasicMem.c
> -MF src/Codit-BasicMem.d -MT Codit-BasicMem.o -MM
>
... (Omitted)

> "C:/tools/mingw64/bin/x86_64-w64-mingw32-gcc.exe"  src/codit_test.c -MF
> src/codit_test.d -MT codit_test.o -MM
> GNUmakefile:46: *** missing separator.  Stop.
> > ERROR: Command `%make% test` exited with status code 2.
>
The last 2 lines are why I'm trying here first​

--
We will die a permanent death unless we trust in Jesus Christ our saviour
and repent our sinful ways
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Issue with foreach statement

Paul Smith-20
On Mon, 2016-07-25 at 18:47 +0100, Lee Shallis wrote:
> I don't know whether this is because of the way I used foreach or
> whether it is because of the way I used gcc so I'm going to start
> with the snippet involving my foreach statement:

> GNUmakefile:46: *** missing separator.  Stop.
> ERROR: Command `%make% test` exited with status code 2.

> The last 2 lines are why I'm trying here first

Well, the best thing is to look at the content of the GNUmakefile line
46 and see what's there, since that's what the error is.

Certainly there's not much help we can give you with what you've
provided to us: you don't show the values of any of the variables
you're using, you don't show which lines make is actually complaining
about.  You didn't even tell us which version of GNU make you're using
or what operating system you're using.  I can infer it's Windows based
on the drive letters in your path names, but in that case we'd need to
know how you built GNU make (it it from cygwin?  MinGW32?  DOS?
Prebuilt from Eli's repository?  Special options?  etc.)

If you provide that detail, and a small, self-contained reproduce case
or at least show exactly which lines of the makefile generate the error
and what the value of the variables used in that line are, then we
might be able to help more.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Issue with foreach statement

Brian Vandenberg-2
In reply to this post by zxuiji
​Fortunately this is rather easy to reproduce without foreach:

>     $ cat /tmp/makefile
>
>     define TEST_MACRO =
>     $(eval a=b)
>     $(eval a=b)
>     endef
>
>     $(call TEST_MACRO)
>
>     $ make -f /tmp/makefile
>     /tmp/makefile:8: *** missing separator.  Stop.

The issue is that the evaluation of TEST_MACRO produced a non-empty string
consisting of whitespace.  Once make begins evaluating a line as in my
example it assumes you're going to do something on that line, but what it
gets back is something it cannot interpret as a valid makefile directive.

You can resolve this problem by wrapping the foreach in a $(strip):

>     $(strip $(foreach ...))

-brian
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Issue with foreach statement

Paul Smith-20
On Wed, 2016-07-27 at 11:26 -0600, Brian Vandenberg wrote:

> Fortunately this is rather easy to reproduce without foreach:
>
> >
> >     $ cat /tmp/makefile
> >
> >     define TEST_MACRO =
> >     $(eval a=b)
> >     $(eval a=b)
> >     endef
> >
> >     $(call TEST_MACRO)
> >
> >     $ make -f /tmp/makefile
> >     /tmp/makefile:8: *** missing separator.  Stop.
> The issue is that the evaluation of TEST_MACRO produced a non-empty
> string consisting of whitespace.

Ah.  It's even simpler to reproduce:

  define TEST_MACRO


  endef

  $(call TEST_MACRO)

(note that's two blank lines in the define)

It's not whitespace per se, it's the newline.  Just using spaces alone
won't cause a problem.  This probably SHOULD be considered a bug in
make; it should be able to ignore blank lines in this context just like
whitespace.

> You can resolve this problem by wrapping the foreach in a $(strip):
>
> >
> >     $(strip $(foreach ...))

Yes, and also you can just write:

  TEST_MACRO = $(eval a=a) $(eval b=b)

(you don't need define/endef for this) which also ensures there are no
newlines in the content of TEST_MACRO.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Issue with foreach statement

zxuiji
You all realise I already posted that I fixed the issue with a eval wrapper
right? As for which version of make I'm using if you look at the output
you'll notice the path mentions mingw64, that's what I'm using at the
moment though I'll test with cygwin later.
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make