Using 'make' from the ARM DS-5 5.22 release on Cygwin, I am processing a makefile containing the lines:
if [[ ! -d "$(OBJ_DIR)" ]]; \
then $(MD) "$(OBJ_DIR)"; fi
This evaluates to:
if [[ ! -d "../../output/obj" ]]; \
then mkdir -p "../../output/obj"; fi
When making, I get an error:
make -C ./src/modules
make[1]: Entering directory `C:/Users/me/Documents/proj/src/modules'
if [[ ! -d "../../output/obj" ]]; \
then mkdir -p "../../output/obj"; fi
! was unexpected at this time.
make[1]: *** [setenv] Error 255
make[1]: Leaving directory `C:/Users/me/Documents/proj/src/modules'
make: *** [drivers] Error 2
When explicitly running the mkdir command from the command line, it works as expected and the output/obj directory is created with no problems.
This script works fine on other computers.
What does the ! was unexpected at this time. error mean, and how to fix that?
UPDATE: The make command is invoked from the following shell script:
#!/bin/bash
set -e
export PATH='./:/usr/bin/:/cygdrive/c/Program Files/ARMCompiler6.6/bin/'
export ARM_PRODUCT_PATH='c:/DS-5_v5.22/sw/mappings'
export USEARMCOMPILER6=1
export DS5VER=DS-5_5.22
/cygdrive/c/DS-5_v5.22/bin/make "$#"
Related
I have the following target in my makefile
omp: main_omp.c omp_impl.o
if [[ ! -e ../bin/ ]]; then mkdir ../bin/ fi
gcc $(CFLAGS) ... # compilation et cetera
On executing make omp in the same directory causes make to terminate with the following error
if [[ ! -e ../bin ]]; then mkdir ../bin fi
/bin/sh: 1: Syntax error: end of file unexpected (expecting "fi")
make: *** [makefile:10: omp] Error 2
Executing the if ... fi statement in the terminal works as intended. I tried different combinations of double quotes, splitting into different lines etc and nothing works.
How do I fix this problem? Why is make running into an EOF over here?
You state:
Executing the if ... fi statement in the terminal works as intended.
I doubt that. If I cut-and-paste your example, I get a continuation prompt from the shell:
if [[ ! -e ../bin/ ]]; then mkdir ../bin/ fi
>
And that is logical. Your shell (either via the prompt or via make) sees that you want to execute mkdir with two arguments ../bin and fi. The solution is of course to make sure that the shell sees the fi as the next "command". To do that, you need to add a ; before the fi.
Can't make directory with the following bash script:
##! /bin/bash
PROJ=~/myname
for i in aa bb cc
do
TMPDIR=${PROJ}/${i}
test ! -e ${TMPDIR} && mkdir ${TMPDIR}
OUTDIR=${PROJ}/${i}/subfolder
test ! -e ${OUTDIR} && mkdir ${OUTDIR}
/bin/cp -f ./file.out ${OUTDIR}/
done
It turns out the OUTDIR dose not exist!
What's wrong, and how do I make directory with two bash variable?
thanks in advance.
And you did not get any error message, that a directory can not be created? After all, your script would fail if the the directory $HOME/home does not exist.
You could simplify the creation process to
PROJ="$HOME/home"
for i in aa bb cc
do
OUTDIR="$PROJ/$i/subfolder"
mkdir -p "$OUTDIR" && cp -f ./file.out "$OUTDIR" && echo "File copied to $OUTDIR"
done
I have the following Makefile:
build: clean
${GOPATH}/bin/dep ensure
env GOOS=linux go build -o ./bin/status ./lib/status/main.go
elm-app build
init:
${GOPATH}/bin/dep init -v
test:
env GOOS=linux go test -v ./lib/status
strip:
strip ./bin/status
clean:
if [ -f ./bin/status ]; then
rm -f ./bin/status
fi
but I get
if [ -f ./bin/status ]; then
/bin/sh: 1: Syntax error: end of file unexpected
Makefile:16: recipe for target 'clean' failed
make: *** [clean] Error 2
what am i missing?
any advice is much appreciated
Each line of a makefile is run in a separate shell. This means your rule here:
clean:
if [ -f ./bin/status ]; then
rm -f ./bin/status
fi
actually runs the following commands:
/bin/sh -c "if [ -f ./bin/status ]; then"
/bin/sh -c "rm -f ./bin/status"
/bin/sh -c "fi"
You can see why you get this message. To ensure that all lines are send into a single shell you need to use backslashes to continue the lines like this:
clean:
if [ -f ./bin/status ]; then \
rm -f ./bin/status; \
fi
Note this means you also need a semicolon after the rm command so separate it from the ending fi.
Now you get a shell invocation like this:
/bin/sh -c "if [ -f ./bin/status ]; then \
rm -f ./bin/status; \
fi"
I tried to install Protobuf 2.6.0 on Windows, with Mingw.
The command ./configure worked, it provided me a Makefile, but when I use the command mingw32-make to run the Makefile I have this error:
C:\Users\taka\gz-ws\protobuf-2.6.0> mingw32-make
! était inattendu. //translation: "! was not expected"
Makefile:558: recipe for target 'config.h' failed
mingw32-make: *** [config.h] Error 255
The line 558 of the Makefile:
config.h: stamp-h1
#if test ! -f $#; then rm -f stamp-h1; else :; fi
#if test ! -f $#; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi`
I don't know what to do here.
I found the solution. You need to use Msys and not MinGW, be cause MinGW doesn't have access to all Unix Bash. (run make and not mingw32-make)
So it cannot recognize the line 558 but Msys can read it correctly.
I googled for this, but I can't figure out why Bash complains with the following code to check if a directory exists:
test.mk
#!/bin/bash
MYDIR="dl"
all:
if [ ! -d $MYDIR ]; then
#if [ ! -d "${MYDIR}" ]; then
#if [ ! -d ${MYDIR} ]; then
#Here
fi
make -f test.mk
if [ ! -d YDIR ]; then
/bin/sh: Syntax error: end of file unexpected
make: *** [all] Error 2
Does someone know why it fails? And why does it call /bin/sh instead of /bin/bash? Thank you.
Edit: unlike Bash, make doesn't support multi-line block. Here's working code:
MYDIR="dl"
all:
if [ ! -d ${MYDIR} ]; then\
echo "Here";\
else\
echo "There";\
fi
The #!/bin/bash shebang that you inserted at top is useless, and it is treated by make as a comment.
make sends by default commands to /bin/sh. To specify a different shell, use the macro SHELL = /bin/bash.
Moreover, you need to escape your variable:
if [ ! -d ${MYDIR} ]
I'm not sure if make can handle multi-line statements, so try to put all the if block in a line.
if [ ! -d ${MYDIR} ]; then DO_SOMETHING; DO_SOMETHING_ELSE; fi
You're feeding test.mk to make, not to bash. Then make sends individual lines to the shell, not whole blocks.
make uses its SHELL macro to determine which shell to use. You can override it to make it use bash.
The reason why you're getting YDIR is that make has silly rules about variable interpolation. Write $(MYDIR), not $MYDIR.
try bracing your variable:
${MYDIR}