make -B and the order-only prerequisites

View: New views
3 Messages — Rating Filter:   Alert me  

make -B and the order-only prerequisites

by John Gamboa :: Rate this Message:

| View Threaded | Show Only this Message

Hello makers...

I'm having problems with the "make -B" option and the order-only
prerequisites. I've created a simple Makefile to exemplify the problem.
Please consider the following file:

-------------
# just "calls" the other prerequisite
all: bin/pseh

# makes the "mkdir" targets phony (cause they don't create any file)
.PHONY: obj bin
obj:
        mkdir obj
bin:
        mkdir bin

# rules to create the files
bin/pseh: obj/foo | bin
        touch bin/pseh

obj/foo: | obj
        touch obj/foo

-------------
 When I run this make file for the first time, it works perfectly: before
creating the bin/pseh file, it calls the "bin" rule (i.e., creates the bin
directory); and before creating the obj/foo file, it calls the "obj" rule
(and creates the obj directory). The problem is: when I run "make -B", make
tries to call "obj" and "bin", and mkdir returns and error, that causes
make to stop.

I'd like to know if there is a proper way (and what should be this way) to
write a Makefile that does what I want, i.e., creates my folders only if
they aren't there (that is the idea of using order-only prerequisites,
AFAICT) *and* works when I decide to "remake" everything.

For now, as a pseudo-solution, I'm using a rule called "clean" that deletes
everything so I can recreate the folders again without the complaints of
mkdir.

Thanks in advance...

--
John Gamboa
rabanetescebolas.blogspot.com
_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

Re: make -B and the order-only prerequisites

by Philip Guenther-2 :: Rate this Message:

| View Threaded | Show Only this Message

On Mon, Apr 30, 2012 at 3:27 PM, John Gamboa <vaulttech@...> wrote:
> obj:
>        mkdir obj
> bin:
>        mkdir bin
...
>  When I run this make file for the first time, it works perfectly: before
> creating the bin/pseh file, it calls the "bin" rule (i.e., creates the bin
> directory); and before creating the obj/foo file, it calls the "obj" rule
> (and creates the obj directory). The problem is: when I run "make -B", make
> tries to call "obj" and "bin", and mkdir returns and error, that causes
> make to stop.

Is this a trick question?  How about having the command in the rule
only create the directory if it doesn't exist?

DIRS = obj bin
$(DIRS):
        test -d $@ || mkdir $@


Philip Guenther

_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make

Re: make -B and the order-only prerequisites

by Rhys Ulerich-2 :: Rate this Message:

| View Threaded | Show Only this Message

> How about having the command in the rule
> only create the directory if it doesn't exist?
>
> DIRS = obj bin
> $(DIRS):
>        test -d $@ || mkdir $@

'mkdir -p' also comes to mind.

- Rhys

_______________________________________________
Help-make mailing list
Help-make@...
https://lists.gnu.org/mailman/listinfo/help-make