dudi
dudi

Reputation: 5743

How to execute a bash script into a makefile

I have a simple bash script, that install and zip a NodeJS application. It's worked great local. Now I want to execute this script from a Makefile. So I wrote this code

.FOO: install_and_zip
    install_and_zip: ./install_and_zip_foo.sh

So if I run this Makefile with make foo I'm getting this error message:

make: *** No rule to make target `foo'.  Stop.

Makefile and bash script are in the same directory.

What I'm doing wrong? Can you help me to fix this Makefile?

Upvotes: 4

Views: 10786

Answers (2)

danrodlor
danrodlor

Reputation: 1459

You should write "make .FOO" as you have defined it to be that way. However, you have to properly write your Makefile (tab identations and so on). If you do, you can just write 'make' and the tool will identify "install_and_zip" as the main target, thus executing your script.

PD: targets with a leading '.' (and without slashes) will be ignored by make when trying to identify the main goal (i.e. they won't run just executing 'make'). So, unless you know what you are doing, just rename your target to 'foo'.

Upvotes: 1

Wiimm
Wiimm

Reputation: 3615

Different errors. This will work:

foo:    install_and_zip
install_and_zip:
# next line must start with a real TAB (ASCII 9)
    ./install_and_zip_foo.sh
  • If you want to make foo, then call the rule foo, but not FOO or .FOO.
  • Code goes always below the rule. All command lines must start with a real TAB (ASCII 9, but not a series of spaces).

Rule foo calls rule install_and_zip. Is this your whish? Otherwise this will do it too:

foo:
# next line must start with a real TAB (ASCII 9)
    ./install_and_zip_foo.sh

Upvotes: 8

Related Questions