makefilegnu-make

Can I obtain just the second prerequisite in GNU make?


I am using GNU make, and I'm using automatic variables such at $<, $^ etc. I know that $< is just the first prerequisite, and $^ is all the prerequisites. Is there a way to obtain just the second prerequisite?


Solution

  • Assuming your prerequisites are regular tokens,

    echo $(word 2,$^)
    

    I often find myself giving the first argument a special position, and accessing the remaining prerequisites with

    echo $(filter-out $<,$^)
    

    *Though sometimes with the upper solution you might find repeating elements.