Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: ignore prerequisite if does not exist

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?

like image 348
Pablo Avatar asked May 07 '10 13:05

Pablo


2 Answers

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/*)
like image 58
Beta Avatar answered Oct 07 '22 23:10

Beta


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.

like image 45
AlG Avatar answered Oct 07 '22 21:10

AlG