aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-05-25 12:42:36 +0100
committerRon Yorston <rmy@pobox.com>2024-05-25 12:42:36 +0100
commitbb999afb2f049f1168526142a1b0f5168b864f5d (patch)
treec8f16d159ec91132cee562f4a6fa9b2117e8ca38
parent8c847995faf850c9dab590d7c4d1600f4d1406cf (diff)
downloadbusybox-w32-bb999afb2f049f1168526142a1b0f5168b864f5d.tar.gz
busybox-w32-bb999afb2f049f1168526142a1b0f5168b864f5d.tar.bz2
busybox-w32-bb999afb2f049f1168526142a1b0f5168b864f5d.zip
make: add posix_2017 pragma
The pragma 'posix_202x' causes the 202X POSIX standard to be enforced in POSIX mode. Add an equivalent 'posix_2017' for the 2017 standard. There's now a DEFAULT_POSIX_LEVEL preprocessor symbol to configure the default standard. This is hardcoded to the 2017 standard but it can also be set to 202X. Adds 48 bytes.
-rw-r--r--miscutils/make.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/miscutils/make.c b/miscutils/make.c
index 063d0662d..45cdac400 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -70,7 +70,15 @@
70#include "common_bufsiz.h" 70#include "common_bufsiz.h"
71#include <glob.h> 71#include <glob.h>
72 72
73#define POSIX_2017 (posix && !(pragma & P_POSIX_202X)) 73// Supported POSIX levels
74#define STD_POSIX_2017 0
75#define STD_POSIX_202X 1
76
77#define POSIX_2017 (posix && posix_level == STD_POSIX_2017)
78
79#ifndef DEFAULT_POSIX_LEVEL
80# define DEFAULT_POSIX_LEVEL STD_POSIX_2017
81#endif
74 82
75#define OPTSTR1 "eij:+knqrsSt" 83#define OPTSTR1 "eij:+knqrsSt"
76#if ENABLE_FEATURE_MAKE_POSIX 84#if ENABLE_FEATURE_MAKE_POSIX
@@ -198,14 +206,25 @@ struct macro {
198#define M_VALID 16 // assert macro name is valid 206#define M_VALID 16 // assert macro name is valid
199 207
200// Constants for PRAGMA. Order must match strings in set_pragma(). 208// Constants for PRAGMA. Order must match strings in set_pragma().
201#define P_MACRO_NAME 0x01 209enum {
202#define P_TARGET_NAME 0x02 210 BIT_MACRO_NAME = 0,
203#define P_COMMAND_COMMENT 0x04 211 BIT_TARGET_NAME,
204#define P_EMPTY_SUFFIX 0x08 212 BIT_COMMAND_COMMENT,
205#define P_POSIX_202X 0x10 213 BIT_EMPTY_SUFFIX,
214#if ENABLE_PLATFORM_MINGW32
215 BIT_WINDOWS,
216#endif
217 BIT_POSIX_2017,
218 BIT_POSIX_202X,
219
220 P_MACRO_NAME = (1 << BIT_MACRO_NAME),
221 P_TARGET_NAME = (1 << BIT_TARGET_NAME),
222 P_COMMAND_COMMENT = (1 << BIT_COMMAND_COMMENT),
223 P_EMPTY_SUFFIX = (1 << BIT_EMPTY_SUFFIX),
206#if ENABLE_PLATFORM_MINGW32 224#if ENABLE_PLATFORM_MINGW32
207# define P_WINDOWS 0x20 225 P_WINDOWS = (1 << BIT_WINDOWS)
208#endif 226#endif
227};
209 228
210// Status of make() 229// Status of make()
211#define MAKE_FAILURE 0x01 230#define MAKE_FAILURE 0x01
@@ -235,6 +254,7 @@ struct globals {
235 bool seen_first; 254 bool seen_first;
236 llist_t *pragmas; 255 llist_t *pragmas;
237 unsigned char pragma; 256 unsigned char pragma;
257 unsigned char posix_level;
238#endif 258#endif
239} FIX_ALIASING; 259} FIX_ALIASING;
240 260
@@ -263,9 +283,11 @@ struct globals {
263#define seen_first (G.seen_first) 283#define seen_first (G.seen_first)
264#define pragmas (G.pragmas) 284#define pragmas (G.pragmas)
265#define pragma (G.pragma) 285#define pragma (G.pragma)
286#define posix_level (G.posix_level)
266#else 287#else
267#define posix 0 288#define posix 0
268#define pragma 0 289#define pragma 0
290#define posix_level DEFAULT_POSIX_LEVEL
269#endif 291#endif
270 292
271static int make(struct name *np, int level); 293static int make(struct name *np, int level);
@@ -591,20 +613,28 @@ static void
591set_pragma(const char *name) 613set_pragma(const char *name)
592{ 614{
593 // Order must match constants above. 615 // Order must match constants above.
616 // POSIX levels must be last and in increasing order
594 static const char *p_name = 617 static const char *p_name =
595 "macro_name\0" 618 "macro_name\0"
596 "target_name\0" 619 "target_name\0"
597 "command_comment\0" 620 "command_comment\0"
598 "empty_suffix\0" 621 "empty_suffix\0"
599 "posix_202x\0"
600#if ENABLE_PLATFORM_MINGW32 622#if ENABLE_PLATFORM_MINGW32
601 "windows\0" 623 "windows\0"
602#endif 624#endif
625 "posix_2017\0"
626 "posix_202x\0"
603 ; 627 ;
604 int idx = index_in_strings(p_name, name); 628 int idx = index_in_strings(p_name, name);
605 629
606 if (idx != -1) { 630 if (idx != -1) {
607 pragma |= 1 << idx; 631 if (idx >= BIT_POSIX_2017) {
632 // POSIX level is stored in a separate variable.
633 // No bits in 'pragma' are used.
634 posix_level = idx - BIT_POSIX_2017;
635 } else {
636 pragma |= 1 << idx;
637 }
608 return; 638 return;
609 } 639 }
610 warning("invalid pragma '%s'", name); 640 warning("invalid pragma '%s'", name);
@@ -2968,6 +2998,7 @@ int make_main(int argc UNUSED_PARAM, char **argv)
2968 } else { 2998 } else {
2969 posix = getenv("PDPMAKE_POSIXLY_CORRECT") != NULL; 2999 posix = getenv("PDPMAKE_POSIXLY_CORRECT") != NULL;
2970 } 3000 }
3001 posix_level = DEFAULT_POSIX_LEVEL;
2971#endif 3002#endif
2972 3003
2973 if (!POSIX_2017) { 3004 if (!POSIX_2017) {