Pergunta

Here is the command I run

make -d -f dump.makefile

A the error I got:

Reading makefile `dump.makefile'...
dump.makefile:31: *** commands commence before first target.  Stop.

Source

ifneq (,)
This makefile requires GNU Make.
endif

# force use of Bash
SHELL := /bin/bash


# function
today=$(shell date '+%Y-%m:%b-%d')
update-latest=$(shell ln -nf {$(call today),latest}.cfdict-"$(1)".localhot.sql)

# variables
credentials="$$HOME/.my.cfdict.cnf"

default: data-only structure-only csv-only all

data-only: what=data
    argList=( --defaults-file="${credentials}" --no-create-db --no-create-info ) \
    mysqldump "$${argList[@]}" cfdict > $(call today).cfdict-"${what}".localhot.sql
    $(call update-latest,${what})

The line that trigger the error is $(call update-latest,${what}) with call the update-latest function.

Full gist available on github.

Question

I check for tabs/space, it seems correct. Did I misuse the call or badly declare update-latest ?

Foi útil?

Solução

The problem that causes the error you report is that you do not separate the target-specific variable definitions from the definitions of the rules. You currently have rules of this form:

data-only: what=data
        ... commands ...

You might be expecting that the data-only: what=data line defines the target-specific variable and the rule, but it does not.

What you need is to have one line for the variable declaration and then repeat the name of the target for the rule. Like this:

data-only: what=data
data-only:
        ... commands ...

So data-only, to take just one example, would become:

data-only: what=data
data-only:
    argList=( --defaults-file="${credentials}" --no-create-db --no-create-info ) \
    mysqldump "$${argList[@]}" cfdict > $(call today).cfdict-"${what}".localhot.sql
    $(call update-latest,${what})

I see that you declare argList as a shell variable so it does not need to be changed.

You'll have to update similarly all targets that have target-specific variables in your Makefile.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top