[英]/bin/sh: Syntax Error: end of file unexpected
I am getting an error when running the following makefile with make -f makefile2 install
(apart install the rest is working): 使用make -f makefile2 install
运行以下makefile时出错(另外安装其余的工作正常):
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'm 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 white space/tabulation/non unix character problem in the last lines of the makefile (after install:). 根据我的理解,它是makefile的最后几行中的空白/制表/非unix字符问题(安装后:)。 But even trying to delete all spaces and replacing with tabulation I didn't manage to run the makefile properly. 但即使尝试删除所有空格并替换为制表符,我也无法正确运行makefile。 The code comes directly from a programming book I'm reading and is an example. 代码直接来自我正在阅读的编程书,并且是一个例子。 Any help appreciated! 任何帮助赞赏!
You're missing a trailing slash on your else under the install rule. 根据安装规则,您在其他地方缺少尾部斜杠。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.