Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the second dependency file using Automatic Variables in a Makefile?

I need to get the nth dependency file from a rule, something similar to $n in bash. I need this because I'd like to feed in individual dependency files as options to the build program.

Here's an example:

dep.o: dep.src config1.cfg config2.cfg     parse -cfg1 $2 -cfg2 $3 -o $@ $< 

Is it possible?

like image 301
Yu Zhou Avatar asked Jul 11 '12 01:07

Yu Zhou


People also ask

What is automatic variable in makefile?

makefile Variables Automatic Variables Within the context of an individual rule, Make automatically defines a number of special variables. These variables can have a different value for each rule in a makefile and are designed to make writing rules simpler.

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What is Patsubst in makefile?

$(patsubst PATTERN,REPLACEMENT,TEXT) Finds whitespace-separated words in TEXT that match PATTERN and replaces them with REPLACEMENT. Here PATTERN may contain a % which acts as a wildcard, matching any number of any characters within a word.


1 Answers

dep.o: dep.src config1.cfg config2.cfg     @echo the second preq is $(word 2,$^), the third is $(word 3,$^) 
like image 88
Beta Avatar answered Sep 20 '22 21:09

Beta