Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/bin/sh: 1: Syntax error: word unexpected (expecting ")")

I have this Makefile:

TMP_DIR := tmp
RUN_OR_NOT := $(shell date '+%y%m%d%H%M')

all: version

version:
    ifeq ($(shell test -d ${TMP_DIR} && echo -n "yes";),yes)
        $(shell echo ${TMP_DIR} already exists ...)
    else
        $(shell mkdir -p ${TMP_DIR})
    endif

I want to first check, if the directory tmp exists or not, and create it only, if it does not exist. This works, but with a strange error:

 ifeq (yes,yes)
 /bin/sh: 1: Syntax error: word unexpected (expecting ")")
 Makefile:7: die Regel für Ziel „version“ scheiterte
 make: *** [version] Fehler 2

Why is there this strange /bin/sh: 1: Syntax error: word unexpected (expecting ")") error? And how to solve this?

like image 530
devopsfun Avatar asked Mar 26 '26 19:03

devopsfun


1 Answers

In a makefile, the recipe is a shell script. You are trying to put make constructs like ifeq into your recipe. Make will pass those to the shell and the shell throws this error because it doesn't understand makefile syntax.

You should write your recipe using shell scripting, not makefile syntax:

version:
        if test -d ${TMP_DIR}; then \
            echo ${TMP_DIR} already exists ...; \
        else \
            mkdir -p ${TMP_DIR}; \
        fi

Although why you care if the directory exists already I don't know; I would personally just use:

version:
        mkdir -p ${TMP_DIR}
like image 142
MadScientist Avatar answered Mar 28 '26 18:03

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!