-2

I’ve the following code which run on make gnu file

apps := $(shell tbd run apps)
apps := $(subst ],,$(subst [,,$(app)))

Now I want to print the app value and I tried with

@echo $(app)

And I got error

Makefile:12: *** commands commence before first target. Stop.

update:

currently my code is like

apps := $(shell tbd run apps)
apps := $(subst ],,$(subst [,,$(apps)))


build:
    @for app in $(apps) ; do \
     bsd start $$app ; \
    done

And if I try it like this I got error

start: 
   apps := $(shell tbd run apps)
   apps := $(subst ],,$(subst [,,$(apps)))

build:
    @for app in $(apps) ; do \
        bsd start $$app ; \
    done
  • 1
    Possible duplicate of [GNU make yields "commands commence before first target" error](https://stackoverflow.com/questions/4713663/gnu-make-yields-commands-commence-before-first-target-error) – tripleee Oct 15 '18 at 11:40
  • @tripleee - not the same, I try with `$app` (as in the post answer) without success same error, any idea? –  Oct 15 '18 at 11:45
  • Not the accepted answer; the other one. – tripleee Oct 15 '18 at 11:45
  • @tripleee - try it now also , I dont get erorr but still I dont see the value –  Oct 15 '18 at 11:48
  • @tripleee - done I've update but the problem is when I put it in recipe I got anohter error, lets put it like this if I want to user the app value inside other recipe how should I do it ? –  Oct 15 '18 at 12:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181881/discussion-between-rayn-d-and-tripleee). –  Oct 15 '18 at 12:14

2 Answers2

0

If you just want to print something regardless of any rule then use the info function...

$(info $(app))
G.M.
  • 12,232
  • 2
  • 15
  • 18
  • btw I dont see the error but I dont see the value either what do you think is still can be missing? –  Oct 15 '18 at 11:49
  • That suggests the output of `$(shell tbd run apps)` is an empty string. – G.M. Oct 15 '18 at 11:49
  • No it isnt :) should I check it mabye like this `@echo $(info $(app))` –  Oct 15 '18 at 11:51
  • 1
    How do you know it isn't empty? Try putting `$(info app='$(app)')` on a line immediately after `app := $(shell tbd run apps)` in your makefile. Do you see any output? – G.M. Oct 15 '18 at 11:54
  • No, you cannot run a shell command in the middle of your `Makefile`, it needs to be part of a recipe; that's what the error message means and that's what the nominated duplicate is telling you. – tripleee Oct 15 '18 at 11:54
0

You cannot meaningfully put a Makefile function call inside of a shell invocation. I guess you are really just looking for

build:
    tbd run apps \
    | sed 's/\[//;s/\]//' \
    | xargs -n 1 bsd start
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks : ) what I need is getting list of apps and running in loop on them and this works, except I want print the values –  Oct 15 '18 at 12:19
  • sorry I dont understand how this should work can you provide the complite code ? does this replace all the code in my update ? –  Oct 15 '18 at 12:27
  • 1+ for your help :) –  Oct 15 '18 at 12:27
  • This is a complete Makefile to replace the code you have in your question, yes. – tripleee Oct 15 '18 at 12:29
  • Sorry, what is `bsd start` ? can it be simplified ? –  Oct 15 '18 at 12:40
  • I have simply refactored the code you posted. I have no idea what the commands `tbd run` and `bsd start` from your question actually do. – tripleee Oct 15 '18 at 12:42
  • Sorry for asking this , but is there is option to make the code In my last update to print the value to the screen ? –  Oct 15 '18 at 12:45
  • I replied to that earlier. https://stackoverflow.com/questions/52815860/error-while-trying-to-get-value-from-command-in-gnu-make/52816615?noredirect=1#comment92550585_52816615 – tripleee Oct 15 '18 at 12:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181883/discussion-between-rayn-d-and-tripleee). –  Oct 15 '18 at 12:50
  • Can we please chat shortly ? –  Oct 15 '18 at 12:51