Makefile: ignore prerequisite if does not exist
Asked Answered
B

2

7

Is there any way to say that if prerequisite for the given target doesn't exist then ignore that target?

For instance, I have the following set of folders

chrome_src_folders  := $(chrome_src_folder)/content/*  \
                $(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/* 

This is where I use it

$(jar_path): $(chrome_src_folders)
    zip -urq $(jar_path) $(chrome_src_folders)    

Basically skin or locale may very well not be there, which will give me a nice error. How to avoid that error and make the chrome_src_folders mandatory? or should I filter somehow chrome_src_folders and leave only those which exist?

Blancheblanchette answered 7/5, 2010 at 13:11 Comment(0)
C
1

Two thoughts; Since the skin and locale folders are optional, do you need to call them about as dependencies? Let the build commands take care of them if they need to. So something like:

chrome_content_folder := $(chrome_src_folder)/content/*
chrome_content_optional := $(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/* 

$(jar_path): $(chrome_content_folder)
    zip -urq $(jar_path) $(chrome_content_folder) $(chrome_content_optional)

If you have to have the right folders on the dependency line, so you catch errors, I would write some macros that define when and how you require them. Then update your targets accordingly to only require those directories when you know they are required.

Chorizo answered 7/5, 2010 at 14:8 Comment(0)
T
5

There's more than one way to do this; the simplest is to filter the list using wildcard

chrome_src_folders  := $(wildcard $(chrome_src_folder)/content/*  \
    $(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/*)
Thompkins answered 7/5, 2010 at 14:20 Comment(0)
C
1

Two thoughts; Since the skin and locale folders are optional, do you need to call them about as dependencies? Let the build commands take care of them if they need to. So something like:

chrome_content_folder := $(chrome_src_folder)/content/*
chrome_content_optional := $(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/* 

$(jar_path): $(chrome_content_folder)
    zip -urq $(jar_path) $(chrome_content_folder) $(chrome_content_optional)

If you have to have the right folders on the dependency line, so you catch errors, I would write some macros that define when and how you require them. Then update your targets accordingly to only require those directories when you know they are required.

Chorizo answered 7/5, 2010 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.