varmod-mtime.mk revision 1.6
1# $NetBSD: varmod-mtime.mk,v 1.6 2023/11/19 11:37:44 rillig Exp $ 2# 3# Tests for the ':mtime' variable modifier, which maps each word of the 4# expression to that file's modification time. 5 6# Note: strftime() uses mktime() for %s and mktime() assumes localtime 7# so this should match time() 8start:= ${%s:L:localtime} # see varmod-gmtime.mk, keyword '%s' 9 10 11# Ensure that this makefile exists and has a modification time. If the file 12# didn't exist, the ':mtime' modifier would return the current time. 13.if ${MAKEFILE:mtime} >= ${start} 14. error 15.endif 16 17 18# For a file that doesn't exist, the ':mtime' modifier returns the current 19# time, without an error or warning message. The returned timestamp differs 20# from the 'now' that is used when updating the timestamps in archives or for 21# touching files using the '-t' option, which is taken once when make is 22# started. 23not_found_mtime:= ${no/such/file:L:mtime} 24.if ${not_found_mtime} < ${start} 25. error 26.endif 27 28 29# The ':mtime' modifier accepts a timestamp in seconds as an optional 30# argument. This timestamp is used as a fallback in case the file's time 31# cannot be determined, without any error or warning message. 32.if ${no/such/file:L:mtime=0} != "0" 33. error 34.endif 35 36 37# The fallback timestamp must start with a digit, and it is interpreted as a 38# decimal integer. 39.if ${no/such/file:L:mtime=00042} != "42" 40. error 41.endif 42 43 44# The fallback timestamp must only be an integer, without trailing characters. 45# expect+2: Unknown modifier "x" 46# expect+1: Malformed conditional (${no/such/file:L:mtime=123x}) 47.if ${no/such/file:L:mtime=123x} 48. error 49.else 50. error 51.endif 52 53 54# The timestamp of a newly created file must be at least as great as the 55# timestamp when parsing of this makefile started. 56COOKIE= ${TMPDIR:U/tmp}/varmod-mtime.cookie 57_!= touch ${COOKIE} 58.if ${COOKIE:mtime=0} < ${start} 59. error ${COOKIE:mtime=0} < ${start} 60.endif 61_!= rm -f ${COOKIE} 62 63 64# If the optional argument of the ':mtime' modifier is the word 'error', the 65# modifier fails with an error message, once for each affected file. 66# 67# expect+3: Cannot determine mtime for 'no/such/file1': <ENOENT> 68# expect+2: Cannot determine mtime for 'no/such/file2': <ENOENT> 69# expect+1: Malformed conditional (${no/such/file1 no/such/file2:L:mtime=error}) 70.if ${no/such/file1 no/such/file2:L:mtime=error} 71. error 72.else 73. error 74.endif 75 76 77# Only the word 'error' is a special argument to the ':mtime' modifier, all 78# other words result in a parse error. 79# expect+2: Invalid argument 'errorhandler-no' for modifier ':mtime' 80# expect+1: Malformed conditional (${MAKEFILE:mtime=errorhandler-no} > 0) 81.if ${MAKEFILE:mtime=errorhandler-no} > 0 82.else 83. error 84.endif 85 86 87# Ensure that the fallback for a missing modification time is indeed the 88# current time, and not any later time. 89end:= ${%s:L:gmtime} 90.if ${not_found_mtime} > ${end} 91. error 92.endif 93