Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I execute a command in sub folder in makefile

Tags:

c

makefile

My project folders look like this

Makefile
/src
  /flash
    build.xml
  /blabla
    ...

I wrote a Makefile like this

flash: src/flash/bin-debug/App.swf

src/flash/bin-debug/App.swf:
    cd src/flash
    ant

When I execute make flash, I get the following message:

cd src/flash/
ant
Buildfile: build.xml does not exist!
Build failed
make: *** [src/flash/bin-debug/App.swf] Error 1

How can I execute ant in src/flash

like image 585
guilin 桂林 Avatar asked Feb 27 '12 11:02

guilin 桂林


People also ask

Can you change directory in Makefile?

In a Makefile, each line is run in a different shell. If you want to run something in a different directory, you need to cd /dir && something .

What does $() mean in Makefile?

The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file. For example: hello.o: hello.c hello.h gcc -c $< -o $@ Here, hello.o is the output file.

How do I open a file in a different directory in Linux?

The cd (change directory) command moves you into a different directory. To move out of that directory, use cd along with the path to some other location, or use double dots to backtrack, or return home to navigate from there. Navigating a Linux computer is like navigating the internet.


1 Answers

make creates a new subshell for each line. Try:

src/flash/bin-debug/App.swf:
    cd src/flash; ant

Otherwise the two commands are executed in two separate subshells. The effect of the cd is lost when the first subshell terminates.

like image 128
NPE Avatar answered Sep 21 '22 20:09

NPE