tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: make: creating a file's parent directory



On Jul 16, 2015, at 8:24 AM, Christos Zoulas wrote:
> In article <20150714171819.GN576%trav.math.uni-bonn.de@localhost>,
> Edgar Fuß  <ef%math.uni-bonn.de@localhost> wrote:
>> There must be an easier way doing what I want.
>> 
>> I have a rule generating dir/file and I need to make sure dir exists before 
>> that rule is run.
>> Now it's tempting to write
>> 
>> dir:
>> 	test -d ${.TARGET} || ${INSTALL} -d ... ${.TARGET}
>> 
>> dir/file: dir ...
>> 	... >${.TARGET}
>> 
>> but that causes dir/file's rule to be re-run if you touch dir/another_file, 
>> thus updating dir's time stamp.
>> 
>> I don't want to repeat the rule creating dir over several dir/file*'s rules.
>> 
>> I don't want to create dir unless some dir/file* actually needs to be created.
>> 
>> The best I came to think of was turning the dir rule into a .USEBEFORE and 
>> adding that to the dir/file* dependencies.
>> 
>> What one would need is a dependency operator insuring the sources do exist 
>> but not that the target is up-to-date relatively to them, which (I guess) 
>> doesn't exist.
>> 
>> There's an easier way, right?
> 
> You can always use the .BEGIN target instead…

I'm pretty sure that mkdir -p doesn't touch the directory if it already exists.  Thus, you should be able to use rules like

dir:
	mkdir -p ${.TARGET}

dir/file: dir
	do_stuff

Cheers,
Brook



Home | Main Index | Thread Index | Old Index