Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a bash script into a makefile

Tags:

bash

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?

like image 556
dudi Avatar asked Oct 16 '25 13:10

dudi


2 Answers

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
like image 63
Wiimm Avatar answered Oct 18 '25 08:10

Wiimm


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'.

like image 21
danrodlor Avatar answered Oct 18 '25 07:10

danrodlor



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!