tags:

views:

299

answers:

2

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!

+4  A: 

Just make that a dependancy of one of the other targets

foo.obj : zsh foo.c 
   rule for compileing foo.c

zsh: 
   rule for running zsh script.

or alternatively, make your first target depend on it

goal: zsh foo.exe
John Knoeller
+5  A: 

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.

JesperE