Harish Tadikamalla
Harish Tadikamalla

Reputation: 47

Make : Unexpected token error

I am hitting following error while building my code.

/bin/sh: -c: line 0: syntax error near unexpected token `testk,x86_64'
/bin/sh: -c: line 0: `ifeq (testk,x86_64)'

Code:

define temp
    mkdir -p $(@D)
ifeq ($(MACH),x86_64)
            env PERLLIB=/usr/lib/perl5/site_perl/5.10.0 --test $< 
else
            env PERLLIB=/usr/ex-lib/perl5/site_perl/5.10.0 --test $<
endif 
endef

I found we need to remove indentation before 'if' statement in make files. I did the same and still facing the issue. Can you please correct me if I am doing anything wrong.

I am using 'temp' in following way.

$(TGT64)/$(SETUP): $(TGT64)/$(GEN_K)_gen
     $(temp)

Here I am trying to check the platform and set the environment accordingly. in 'define temp' I am check MACH variable content which has platform information.

I play around code and make following changes.

define temp
mkdir -p $(@D)
@ifeq ($(MACH),x86_64); then env PERLLIB=/usr/lib/perl5/site_perl/5.10.0 $<; \
@else \ 
@env PERLLIB=/usr/ex-lib/perl5/site_perl/5.10.0 $<; \
@fi
endef

This time I am facing.
/bin/sh: -c: line 1: syntax error: unexpected end of file issue.

Upvotes: 0

Views: 897

Answers (1)

MadScientist
MadScientist

Reputation: 100781

Before we can help you have to show us how you're using this variable temp you've defined. Just showing the contents of the variable won't help.

I expect that you're trying to use the variable inside a recipe, like this:

foo:
        $(temp)

You can't do that: the contents of a recipe have to be a shell script; recipes are passed to the shell to be executed. The contents of temp as you've defined it contain makefile constructs which the shell doesn't know anything about, hence your syntax error from the shell.

Also, every line in a recipe is passed to a separate shell, so your line env FOO = bar has no effect: once that line has been invoked the shell exits and all changes to its environment are lost.

Your example here is not sufficient for us to recommend a workable strategy: you haven't told us what you want to accomplish.

ETA My answer above is still true. It looks like you tried to convert your variable to contain shell script syntax for an if-statement, but did not complete the job: ifeq is makefile syntax not shell syntax. In the shell, you have to use if. Like this:

@if [ '$(MACH)' = x86_64 ]; then ...

However, please re-read my comment above about setting an environment variable... the recipe you've shown here will have no effect at all, even once it no longer has syntax errors.

Upvotes: 1

Related Questions