resultsway
resultsway

Reputation: 13300

Makefile base target and its dependent

I have a make structure like :

base : 
      build.sh base.output

//# if base.output is newer than sub-base.output by 1 minute then build the below -- How do i do this ?
sub-base : 
      build.sh sub-base.output

basically if a base folder/target changes all the dependent folders/targets need to be built.

I was thinking of writing a shell script to check the timestamp but makefile provide better way to do this?

Upvotes: 0

Views: 283

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80921

This is what makefiles do. This is their purpose.

Just use the following as your makefile.

base.output:
      build.sh base.output

sub-base.output: base.output
      build.sh sub-base.output

Then running make base.output will run that recipe and make sub-base.output will run build.sh sub-base.output but only when sub-base.output is older than base.output.

You should list any prerequisites of base.output on its target line as well to get make to handle that correctly.

Or, if there aren't any, then you need to use a force target.

FORCE: ;

base.output: FORCE
        build.sh base.output

to force make to build base.output even when it already exists.

If you want to keep the ability to say make base or make sub-base then you need phony targets for those as well.

.PHONY: base sub-base
base: base.output
sub-base: sub-base.output

Upvotes: 1

Related Questions