0

I am getting syntax error: unexpected end of file when I run make clean.

I was successful of getting rid of that error when I removed the brackets around the variable that was causing the error.

I want to know why does this happen.

I am using:

  • Windows XP SP2 64 bit
  • CYGWIN
  • KSH R48

My variable is called TARGET and is like this but way longer:

./ShowEnumContentsPrefAPI.o ./ShowEnumsPrefAPI.o

The line where the error happens was:

rm -f $(TARGET)

When I removed the brackets the error was gone and it worked:

rm -f $TARGET

Another line as well was:

if [ "$(TARGET)" != "" ]; then \

When I removed the brackets the error was gone and it worked:

if [ "$TARGET" != "" ]; then \

==============================================================

  • What is happening here?
  • How can I prevent this from happening without changing every line that is causing the error (I have more than 1000 line in this makefile)?
  • How did this work on mks 5.2 sh.exe and will not work on cygwin ksh?

==============================================================

UPDATE:

This is the actual code:

clean:
    if [ "$TARGET" != "" ]; then \
        rm -rf $(TARGET); \
    fi

This is what produced the error syntax error: unexpected end of file:

clean:
    if [ "$(TARGET)" != "" ]; then \
        rm -rf $(TARGET); \
    fi

The only difference is the brackets around target.


Doing the

echo "T:$T"; \
echo "TARGET:$TARGET"; \

Produced

T:
TARGET:ARGET

echo "(TARGET):$(TARGET)";\ produced the syntax error: unexpected end of file again.


Today I tried cutting off some of the TARGET variable. Making it shorter by hand intentionally and the rm -f $(TARGET) worked fine. I suspect it's a problem with cygwin's rm, [ exes. I will try upgrading to cygwin's latest version and see if the problem persists.

Ayman Salah
  • 1,039
  • 14
  • 35

1 Answers1

1

It looks like you assigned a value to $T instead of $(TARGET)

Unlike bash, in make the $ only applies to the next character or bracketted expression. Thus '$TARGET' resolves to the expansion of '$T' plus the literal 'ARGET'... To illustrate, consider the following:

X := _X_
XX := _YY_
$(info - $XX -)
$(info - $(XX) -)

you get:

- _X_X -
- _YY_ -

Hope that helps.

John
  • 3,400
  • 3
  • 31
  • 47
  • I get what you are saying. But what happens to me is the opposite I guess. And what makes it weirder is that I use $() elsewhere in the file and it works fine. Thanks a lot tho. – Ayman Salah Dec 04 '16 at 07:27
  • 2
    You'll have to post a more complete code -- specifically how TARGET is set, and some more context around where it is referenced (I'm assuming it's in a recipe. If it's in a shell script called outside of the Makefile, however, then it's a totally different issue). – John Dec 05 '16 at 14:44
  • Yes it is in a recipe. I am sorry, I will be updating the question as soon as I can. Thanks for help. – Ayman Salah Dec 05 '16 at 15:07
  • 1
    You may also want to try adding the line: `echo "T:$T TARGET:$TARGET (TARGET):$(TARGET)"` into your recipe to see what it's expanding to. – John Dec 05 '16 at 23:27
  • You still didn't put the code where you set $(TARGET)'; However, if `$(TARGET)` includes a mismatched quote, then you would get the behavior you're describing (except the rm line would cause an issue in that case...). Do an `$(info $(TARGET))` in your makefile, which will output `$(TARGET)`, including the quotes. – John Dec 06 '16 at 14:46
  • I tried some modifications today. Check my last edit! – Ayman Salah Jan 12 '17 at 14:34