0

Am trying to match specific string after doing subst on a variable ; substitution is ok but while trying to match make returns error 127.

Does anyone know what's going on here ? why make should return error ?

$> make -f strsearch.mk

CODE : BBROY_OF_GREAT_BRITAIN_HAD_A_GREAT_WIFE

MORSE = BBROY OF GREAT BRITAIN HAD A GREAT WIFE

**make: MORSE: Command not found

make: * [search_new] Error 127

Here is the snippet of makefile:

VAR1 := BBROY_OF_GREAT_BRITAIN_HAD_A_GREAT_WIFE

search_new: @echo CODE : $(VAR1) MORSE = $(subst _, , $(VAR1)) @echo word count : ($words $(MORSE)) @echo After substitution Britain matches: $(filter %BRITAIN%, $(MORSE))

Ramu
  • 3
  • 1
  • 5

1 Answers1

1

Your variable declaration is in the wrong place or form:

The form you use is for global assignment and cannot be inside a target block.

  • Either make it a global variable outside a target block
  • Or use the shell and eval to set the variable value. See the accepted answer for how to approach this issue: Define make variable at rule execution time
  • A 3rd option is to define the variable as a sort-of prerequisite which is then assigned at the time the dependencies are evaluated.
Community
  • 1
  • 1
planetmaker
  • 5,884
  • 3
  • 28
  • 37
  • Thanks @planetmaker, eval option worked ; was able to overcome the error reported by make. – Ramu Nov 07 '15 at 07:23