Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Makefile to execute script before building targets

I am using Makefiles.

However, there is a command (zsh script) I want executed before any targets is executed. How do I do this?

Thanks!

like image 235
anon Avatar asked Jan 23 '10 08:01

anon


People also ask

How do you force to recompile?

Use the command `make' to recompile the source files that really need recompilation. Make the changes in the header files. Use the command `make -t' to mark all the object files as up to date. The next time you run make, the changes in the header files do not cause any recompilation.

What is $@ makefile?

From make manpage: $@ is: The file name of the target of the rule. If the target is an archive member, then '$@' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), '$@' is the name of whichever target caused the rule's recipe to be run.

What does .phony do in makefile?

The special rule . PHONY is used to specify that the target is not a file. Common uses are clean and all . This way it won't conflict if you have files named clean or all .

Is makefile executed sequentially?

Make will follow dependancies in order. Getting your head around the sequence a makefile will follow can be tricky but it is actually quite simple enough so well worth while working on understanding it.


1 Answers

There are several techniques to have code executed before targets are built. Which one you should choose depends a little on exactly what you want to do, and why you want to do it. (What does the zsh script do? Why do you have to execute it?)

You can either do like @John suggests; placing the zsh script as the first dependency. You should then mark the zsh target as .PHONY unless it actually generates a file named zsh.

Another solution (in GNU make, at least) is to invoke the $(shell ...) function as part of a variable assignment:

ZSH_RESULT:=$(shell zsh myscript.zsh) 

This will execute the script as soon as the makefile is parsed, and before any targets are executed. It will also execute the script if you invoke the makefile recursively.

like image 55
JesperE Avatar answered Oct 06 '22 03:10

JesperE