1*e2eeea75SSimon J. Gerraty# $NetBSD: directive-ifmake.mk,v 1.8 2020/11/15 20:20:58 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for the .ifmake directive, which provides a shortcut for asking 42c3632d1SSimon J. Gerraty# whether a certain target is requested to be made from the command line. 5*e2eeea75SSimon J. Gerraty# 6*e2eeea75SSimon J. Gerraty# TODO: Describe why the shortcut may be useful (if it's useful at all), 7*e2eeea75SSimon J. Gerraty# instead of sticking to the simple '.if' only. 8*e2eeea75SSimon J. Gerraty 9*e2eeea75SSimon J. Gerraty# The targets 'first' and 'second' are passed in on the command line. 102c3632d1SSimon J. Gerraty 112c3632d1SSimon J. Gerraty# This is the most basic form. 122c3632d1SSimon J. Gerraty.ifmake first 132c3632d1SSimon J. Gerraty. info ok: positive condition works 142c3632d1SSimon J. Gerraty.else 152c3632d1SSimon J. Gerraty. warning positive condition fails 162c3632d1SSimon J. Gerraty.endif 172c3632d1SSimon J. Gerraty 182c3632d1SSimon J. Gerraty# The not operator works as expected. 192c3632d1SSimon J. Gerraty# An alternative interpretation were that this condition is asking whether 202c3632d1SSimon J. Gerraty# the target "!first" was requested. To distinguish this, see the next test. 212c3632d1SSimon J. Gerraty.ifmake !first 222c3632d1SSimon J. Gerraty. warning unexpected 232c3632d1SSimon J. Gerraty.else 242c3632d1SSimon J. Gerraty. info ok: negation works 252c3632d1SSimon J. Gerraty.endif 262c3632d1SSimon J. Gerraty 272c3632d1SSimon J. Gerraty# See if the exclamation mark really means "not", or if it is just part of 28*e2eeea75SSimon J. Gerraty# the target name. Since it means 'not', the two exclamation marks are 29*e2eeea75SSimon J. Gerraty# effectively ignored, and 'first' is indeed a requested target. If the 30*e2eeea75SSimon J. Gerraty# exclamation mark were part of the name instead, the name would be '!!first', 31*e2eeea75SSimon J. Gerraty# and such a target was not requested to be made. 322c3632d1SSimon J. Gerraty.ifmake !!first 332c3632d1SSimon J. Gerraty. info ok: double negation works 342c3632d1SSimon J. Gerraty.else 352c3632d1SSimon J. Gerraty. warning double negation fails 362c3632d1SSimon J. Gerraty.endif 372c3632d1SSimon J. Gerraty 382c3632d1SSimon J. Gerraty# Multiple targets can be combined using the && and || operators. 392c3632d1SSimon J. Gerraty.ifmake first && second 402c3632d1SSimon J. Gerraty. info ok: both mentioned 412c3632d1SSimon J. Gerraty.else 422c3632d1SSimon J. Gerraty. warning && does not work as expected 432c3632d1SSimon J. Gerraty.endif 442c3632d1SSimon J. Gerraty 452c3632d1SSimon J. Gerraty# Negation also works in complex conditions. 462c3632d1SSimon J. Gerraty.ifmake first && !unmentioned 472c3632d1SSimon J. Gerraty. info ok: only those mentioned 482c3632d1SSimon J. Gerraty.else 492c3632d1SSimon J. Gerraty. warning && with ! does not work as expected 502c3632d1SSimon J. Gerraty.endif 512c3632d1SSimon J. Gerraty 522c3632d1SSimon J. Gerraty# Using the .MAKEFLAGS special dependency target, arbitrary command 532c3632d1SSimon J. Gerraty# line options can be added at parse time. This means that it is 542c3632d1SSimon J. Gerraty# possible to extend the targets to be made. 552c3632d1SSimon J. Gerraty.MAKEFLAGS: late-target 562c3632d1SSimon J. Gerraty.ifmake late-target 572c3632d1SSimon J. Gerraty. info Targets can even be added at parse time. 582c3632d1SSimon J. Gerraty.else 592c3632d1SSimon J. Gerraty. info No, targets cannot be added at parse time anymore. 602c3632d1SSimon J. Gerraty.endif 612c3632d1SSimon J. Gerraty 62*e2eeea75SSimon J. Gerraty# Numbers are interpreted as numbers, no matter whether the directive is 63*e2eeea75SSimon J. Gerraty# a plain .if or an .ifmake. 64*e2eeea75SSimon J. Gerraty.ifmake 0 65*e2eeea75SSimon J. Gerraty. error 66*e2eeea75SSimon J. Gerraty.endif 67*e2eeea75SSimon J. Gerraty.ifmake 1 68*e2eeea75SSimon J. Gerraty.else 69*e2eeea75SSimon J. Gerraty. error 70*e2eeea75SSimon J. Gerraty.endif 71*e2eeea75SSimon J. Gerraty 72*e2eeea75SSimon J. Gerraty# A condition that consists of a variable expression only (without any 73*e2eeea75SSimon J. Gerraty# comparison operator) can be used with .if and the other .ifxxx directives. 74*e2eeea75SSimon J. Gerraty.ifmake ${:Ufirst} 75*e2eeea75SSimon J. Gerraty. info ok 76*e2eeea75SSimon J. Gerraty.else 77*e2eeea75SSimon J. Gerraty. error 78*e2eeea75SSimon J. Gerraty.endif 79*e2eeea75SSimon J. Gerraty 80*e2eeea75SSimon J. Gerraty 812c3632d1SSimon J. Gerratyfirst second unmentioned late-target: 822c3632d1SSimon J. Gerraty : $@ 83