directive-if.mk revision 1.11
11.11Srillig# $NetBSD: directive-if.mk,v 1.11 2022/01/23 21:48:59 rillig Exp $ 21.1Srillig# 31.2Srillig# Tests for the .if directive. 41.7Srillig# 51.7Srillig# See also: 61.7Srillig# cond-*.mk 71.1Srillig 81.1Srillig# TODO: Implementation 91.1Srillig 101.3Srillig.if 0 111.3Srillig. error 121.3Srillig.else 131.3Srillig. info 0 evaluates to false. 141.3Srillig.endif 151.3Srillig 161.3Srillig.if 1 171.3Srillig. info 1 evaluates to true. 181.3Srillig.else 191.3Srillig. error 201.3Srillig.endif 211.3Srillig 221.3Srillig# There is no '.ifx'. 231.3Srillig# 241.3Srillig# The commit from 2005-05-01 intended to detect this situation, but it failed 251.4Srillig# to do this since the call to is_token had its arguments switched. They were 261.4Srillig# expected as (str, token, token_len) but were actually passed as (token, str, 271.3Srillig# token_len). This made is_token return true even if the directive was 281.4Srillig# directly followed by alphanumerical characters, which was wrong. The 291.4Srillig# typical cases produced an error message such as "Malformed conditional 301.4Srillig# (x 123)", while the intended error message was "Unknown directive". 311.3Srillig# 321.3Srillig# Back at that time, the commits only modified the main code but did not add 331.3Srillig# the corresponding unit tests. This allowed the bug to hide for more than 341.3Srillig# 15 years. 351.4Srillig# 361.4Srillig# Since 2020-11-10, the correct error message is produced. The '.ifx' is no 371.4Srillig# longer interpreted as a variant of '.if', therefore the '.error' and '.else' 381.4Srillig# are interpreted as ordinary directives, producing the error messages 391.4Srillig# "if-less else" and "if-less endif". 401.11Srillig# expect+1: Unknown directive "ifx" 411.3Srillig.ifx 123 421.11Srillig# expect+1: This is not conditional. 431.9Srillig.info This is not conditional. 441.11Srillig# expect+1: if-less else 451.3Srillig.else 461.11Srillig# expect+1: This is not conditional. 471.9Srillig.info This is not conditional. 481.11Srillig# expect+1: if-less endif 491.3Srillig.endif 501.3Srillig 511.3Srillig# Missing condition. 521.11Srillig# expect+1: Malformed conditional () 531.3Srillig.if 541.3Srillig. error 551.3Srillig.else 561.3Srillig. error 571.3Srillig.endif 581.3Srillig 591.5Srillig# A plain word must not start with a '"'. It may contain a embedded quotes 601.5Srillig# though, which are kept. The quotes need not be balanced. The next space 611.5Srillig# ends the word, and the remaining " || 1" is parsed as "or true". 621.5Srillig.if ${:Uplain"""""} == plain""""" || 1 631.5Srillig. info Quotes in plain words are probably a mistake. 641.5Srillig# XXX: Accepting quotes in plain words is probably a mistake as well. 651.5Srillig.else 661.5Srillig. error 671.5Srillig.endif 681.5Srillig 691.6Srillig.if0 701.6Srillig. error 711.6Srillig.else 721.6Srillig. info Don't do this, always put a space after a directive. 731.6Srillig.endif 741.6Srillig 751.6Srillig.if${:U-3} 761.6Srillig. info Don't do this, always put a space after a directive. 771.6Srillig.else 781.6Srillig. error 791.6Srillig.endif 801.6Srillig 811.6Srillig.if${:U-3}>-4 821.6Srillig. info Don't do this, always put a space around comparison operators. 831.6Srillig.else 841.6Srillig. error 851.6Srillig.endif 861.6Srillig 871.8Srillig.if(1) 881.8Srillig. info Don't do this, always put a space after a directive. 891.8Srillig.endif 901.8Srillig 911.8Srillig.if!0 921.8Srillig. info Don't do this, always put a space after a directive. 931.8Srillig.endif 941.8Srillig 951.10Srillig 961.10Srillig# The directives '.ifdef' and '.ifmake' can be negated by inserting an 'n'. 971.10Srillig# This doesn't work for a plain '.if' though. 981.10Srillig# 991.10Srillig# expect+1: Unknown directive "ifn" 1001.10Srillig.ifn 0 101