Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a makefile have a directory as a target?

Tags:

I am trying to say "the download of the git repository will only work if the directory yank/ exists. If the directory yank/ does not exist then make it"

yank/gist.el/gist.el : yank     cd yank ; git clone http://github.com/defunkt/gist.el.git   yank:     mkdir yank 

I am using makepp - http://makepp.sf.net and am getting the error:

[metaperl@andLinux ~/edan/pkg/gist.el] makepp makepp: Loading makefile `/home/metaperl/edan/pkg/gist.el/Makeppfile' makepp: Entering directory `/home/metaperl/edan/pkg/gist.el' mkdir yank mkdir: cannot create directory `yank': File exists makepp: error: Failed to build target `/home/metaperl/edan/pkg/gist.el/yank' [1] makepp: 0 files updated, 0 phony targets built and 1 target failed [metaperl@andLinux ~/edan/pkg/gist.el]  

But why would it try to make the yank directory if it exists? The "source" has already ben created...

like image 588
Terrence Brannon Avatar asked Jul 18 '10 12:07

Terrence Brannon


People also ask

What is the target in a makefile?

A simple makefile consists of "rules" with the following shape: target ... : dependencies ... command ... ... A target is usually the name of a file that is generated by a program; examples of targets are executable or object files.

How do I create a folder in makefile?

Solution 1: build the directory when the Makefile is parsed Before any targets are created or commands run the Makefile is read and parsed. If you put $(shell mkdir -p $(OUT)) somewhere in the Makefile then GNU Make will run the mkdir every time the Makefile is loaded.

What is a target directory?

The destination directory/folder to which files are sent.


1 Answers

Yes, a Makefile can have a directory as target.

Your problem could be that the cd doesn't do what you want: it does cd and the git clone is carried out in the original directory (the one you cded from, not the one you cded to). This is because for every command in the Makefile an extra shell is created. A workaround is to run cd and clone as one command with the shell's &&.

This should work:

bla/f: dir     cd dir && touch f  dir:     mkdir dir 
like image 82
Benjamin Bannier Avatar answered Sep 18 '22 13:09

Benjamin Bannier