0
votes

I'm picking up some old code that is out of my norm and running into some issues over something that is hopefully very simple to explain.

I'm working on a makefile that runs a number of SQL files then generates .done files to track the progress. After one specific SQL file, I need to be able to run a shell script to do some additional processing.

# this is the rule the describes how to execute a SQL script
%.done: %.sql
    @echo "+==============================================================================+"
    @echo "building $@"
    @echo "...from $<"
    @echo "building $<"
    @$(PSQL_WRAPPER) -f $<
    @ifeq ($(@),mysqlfile.done)
        @echo "Executing Shell Script"
        @../path/to/script/myscript.sh
    endif

I added the ifeq portion, everything else was there before and works as expected.

Here's the output I'm getting. I'm really stuck and have been trying different little syntax tweaks, but there's clearly something else I'm just not understanding.

+==============================================================================+
building mysqlfile.done
...from ../..//path/to/file/mysqlfile.sql
building ../..//path/to/file/mysqlfile.sql
/bin/bash: -c: line 0: syntax error near unexpected token `mysqlfile.done,mysqlfile.done'
/bin/bash: -c: line 0: `ifeq (mysqlfile.done,mysqlfile.done)'
make: *** [mysqlfile.done] Error 1
Command exited with non-zero status 2

From the error message, it looks like I have two equal values. I'm really not sure what the unexpected token would be.

1

1 Answers

3
votes

ifeq is a GNU Make directive, for conditionally including or excluding a part of a parsed makefile. It is not a shell command. You are using it in one of the lines of the %.done: %.sql recipe. All lines of a recipe must be shell commands. Just use shell:

%.done: %.sql
    @echo "+==============================================================================+"
    @echo "building $@"
    @echo "...from $<"
    @echo "building $<"
    @$(PSQL_WRAPPER) -f $<
    @if [ "$@" = "mysqlfile.done" ]; then \
        echo "Executing Shell Script"; \
        ../path/to/script/myscript.sh; \
    fi

You cannot conditionally exclude the special-case processing from the recipe itself, like:

%.done: %.sql
    @echo "+==============================================================================+"
    @echo "building $@"
    @echo "...from $<"
    @echo "building $<"
    @$(PSQL_WRAPPER) -f $<
ifeq ($(@),mysqlfile.done)
    @echo "Executing Shell Script"
    @../path/to/script/myscript.sh
endif

because the target $(@) of the rule is only defined within the recipe.