/ bin / sh: Syntax Error: end of file unexpectedly

I get an error when running the following makefile with make -f makefile2 install

(apart from installing the rest):

all:myapp

#which compiler
CC = gcc

#Where to install
INSTDIR = /usr/local/bin

#where are include files kept
INCLUDE = .

#Options for development
CFLAGS = -g -Wall -ansi

#Options for release
# CFLAGS = -O -Wall -ansi

myapp: main.o 2.o 3.o
    $(CC) -o myapp main.o 2.o 3.o

main.o: main.c a.h
    $(CC) -I$(INCLUDE) $(CFLAGS) -c main.c

2.o: 2.c a.h b.h
    $(CC) -I$(INCLUDE) $(CFLAGS) -c 2.c

3.o: 3.c b.h c.h
    $(CC) -I$(INCLUDE) $(CFLAGS) -c 3.c         

clean:
    -rm main.o 2.o 3.o

install: myapp
    @if [ -d $(INSTDIR) ]; \
      then \
      cp myapp $(INSTDIR);\
      chmod a+x $(INSTDIR)/myapp;\
      chmod og-w $(INSTDIR)/myapp;\
      echo "Installed in $(INSTDIR)";\
    else
      echo "Sorry, $(INSTDIR) does not exist";\
    fi

      

I am getting the following error:

error /bin/sh: 7: Syntax error: end of file unexpected
make: *** [install] Error 2

      

From what I understand it is a space / table / non-unix character issue in the last lines of the makefile (after installation :). But even trying to remove all spaces and replace with a table, I was unable to run the makefile correctly. The code comes directly from a programming book I am reading and is an example. Any help is appreciated!

+3


source to share


1 answer


As per the setting rule, you are missing the trailing slash. It should be:



install: myapp
    @if [ -d $(INSTDIR) ]; \
      then \
      cp myapp $(INSTDIR);\
      chmod a+x $(INSTDIR)/myapp;\
      chmod og-w $(INSTDIR)/myapp;\
      echo "Installed in $(INSTDIR)";\
    else\
      echo "Sorry, $(INSTDIR) does not exist";\
    fi

      

+9


source







All Articles