diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-07-12 15:08:48 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-07-12 15:08:48 +0100 |
| commit | 684dabdb8452b3d33d5d6265f3d7ef32c10f5307 (patch) | |
| tree | 19cea9545ff938d8162a61290b87f98825b44a4b /miscutils | |
| parent | 2dc17b7c80c803119dd2214bce4406b252ae2e9f (diff) | |
| download | busybox-w32-684dabdb8452b3d33d5d6265f3d7ef32c10f5307.tar.gz busybox-w32-684dabdb8452b3d33d5d6265f3d7ef32c10f5307.tar.bz2 busybox-w32-684dabdb8452b3d33d5d6265f3d7ef32c10f5307.zip | |
make: allow pragmas to apply recursively
Pragmas set when pdpmake is run are exported to the environment
variable PDPMAKE_PRAGMAS as a space-separated list of pragma names.
This environment variable is read when pdpmake starts and any
pragmas it contains are applied.
Thus pragmas are passed to recursive invocations of pdpmake.
PDPMAKE_PRAGMAS can also be set by the user.
Adds 240-288 bytes.
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/make.c | 69 |
1 files changed, 55 insertions, 14 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index 07e83166b..c65d32e78 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
| @@ -637,23 +637,23 @@ inc_ref(void *vp) | |||
| 637 | } | 637 | } |
| 638 | 638 | ||
| 639 | #if ENABLE_FEATURE_MAKE_POSIX | 639 | #if ENABLE_FEATURE_MAKE_POSIX |
| 640 | // Order must match constants above. | ||
| 641 | // POSIX levels must be last and in increasing order | ||
| 642 | static const char *p_name = | ||
| 643 | "macro_name\0" | ||
| 644 | "target_name\0" | ||
| 645 | "command_comment\0" | ||
| 646 | "empty_suffix\0" | ||
| 647 | #if ENABLE_PLATFORM_MINGW32 | ||
| 648 | "windows\0" | ||
| 649 | #endif | ||
| 650 | "posix_2017\0" | ||
| 651 | "posix_2024\0" | ||
| 652 | "posix_202x\0"; | ||
| 653 | |||
| 640 | static void | 654 | static void |
| 641 | set_pragma(const char *name) | 655 | set_pragma(const char *name) |
| 642 | { | 656 | { |
| 643 | // Order must match constants above. | ||
| 644 | // POSIX levels must be last and in increasing order | ||
| 645 | static const char *p_name = | ||
| 646 | "macro_name\0" | ||
| 647 | "target_name\0" | ||
| 648 | "command_comment\0" | ||
| 649 | "empty_suffix\0" | ||
| 650 | #if ENABLE_PLATFORM_MINGW32 | ||
| 651 | "windows\0" | ||
| 652 | #endif | ||
| 653 | "posix_2017\0" | ||
| 654 | "posix_2024\0" | ||
| 655 | "posix_202x\0" | ||
| 656 | ; | ||
| 657 | int idx = index_in_strings(p_name, name); | 657 | int idx = index_in_strings(p_name, name); |
| 658 | 658 | ||
| 659 | if (idx != -1) { | 659 | if (idx != -1) { |
| @@ -673,6 +673,27 @@ set_pragma(const char *name) | |||
| 673 | } | 673 | } |
| 674 | warning("invalid pragma '%s'", name); | 674 | warning("invalid pragma '%s'", name); |
| 675 | } | 675 | } |
| 676 | |||
| 677 | static void | ||
| 678 | pragmas_to_env(void) | ||
| 679 | { | ||
| 680 | int i; | ||
| 681 | char *val = NULL; | ||
| 682 | |||
| 683 | for (i = 0; i < BIT_POSIX_2017; ++i) { | ||
| 684 | if ((pragma & (1 << i))) | ||
| 685 | val = xappendword(val, nth_string(p_name, i)); | ||
| 686 | } | ||
| 687 | |||
| 688 | if (posix_level != DEFAULT_POSIX_LEVEL) | ||
| 689 | val = xappendword(val, | ||
| 690 | nth_string(p_name, BIT_POSIX_2017 + posix_level)); | ||
| 691 | |||
| 692 | if (val) { | ||
| 693 | setenv("PDPMAKE_PRAGMAS", val, 1); | ||
| 694 | free(val); | ||
| 695 | } | ||
| 696 | } | ||
| 676 | #endif | 697 | #endif |
| 677 | 698 | ||
| 678 | /* | 699 | /* |
| @@ -734,6 +755,7 @@ addrule(struct name *np, struct depend *dp, struct cmd *cp, int flag) | |||
| 734 | for (; dp; dp = dp->d_next) { | 755 | for (; dp; dp = dp->d_next) { |
| 735 | set_pragma(dp->d_name->n_name); | 756 | set_pragma(dp->d_name->n_name); |
| 736 | } | 757 | } |
| 758 | pragmas_to_env(); | ||
| 737 | } | 759 | } |
| 738 | #endif | 760 | #endif |
| 739 | } | 761 | } |
| @@ -1982,6 +2004,23 @@ wildcard(char *p, glob_t *gd) | |||
| 1982 | return 1; | 2004 | return 1; |
| 1983 | } | 2005 | } |
| 1984 | 2006 | ||
| 2007 | #if ENABLE_FEATURE_MAKE_POSIX | ||
| 2008 | static void | ||
| 2009 | pragmas_from_env(void) | ||
| 2010 | { | ||
| 2011 | char *p, *q, *var; | ||
| 2012 | const char *env = getenv("PDPMAKE_PRAGMAS"); | ||
| 2013 | |||
| 2014 | if (env == NULL) | ||
| 2015 | return; | ||
| 2016 | |||
| 2017 | q = var = xstrdup(env); | ||
| 2018 | while ((p = gettok(&q)) != NULL) | ||
| 2019 | set_pragma(p); | ||
| 2020 | free(var); | ||
| 2021 | } | ||
| 2022 | #endif | ||
| 2023 | |||
| 1985 | /* | 2024 | /* |
| 1986 | * Parse input from the makefile and construct a tree structure of it. | 2025 | * Parse input from the makefile and construct a tree structure of it. |
| 1987 | */ | 2026 | */ |
| @@ -3084,6 +3123,7 @@ int make_main(int argc UNUSED_PARAM, char **argv) | |||
| 3084 | posix = getenv("PDPMAKE_POSIXLY_CORRECT") != NULL; | 3123 | posix = getenv("PDPMAKE_POSIXLY_CORRECT") != NULL; |
| 3085 | } | 3124 | } |
| 3086 | posix_level = DEFAULT_POSIX_LEVEL; | 3125 | posix_level = DEFAULT_POSIX_LEVEL; |
| 3126 | pragmas_from_env(); | ||
| 3087 | #endif | 3127 | #endif |
| 3088 | 3128 | ||
| 3089 | if (!POSIX_2017) { | 3129 | if (!POSIX_2017) { |
| @@ -3137,6 +3177,7 @@ int make_main(int argc UNUSED_PARAM, char **argv) | |||
| 3137 | #if ENABLE_FEATURE_MAKE_POSIX | 3177 | #if ENABLE_FEATURE_MAKE_POSIX |
| 3138 | while ((prag = llist_pop(&pragmas))) | 3178 | while ((prag = llist_pop(&pragmas))) |
| 3139 | set_pragma(prag); | 3179 | set_pragma(prag); |
| 3180 | pragmas_to_env(); | ||
| 3140 | #endif | 3181 | #endif |
| 3141 | 3182 | ||
| 3142 | #if !ENABLE_PLATFORM_MINGW32 | 3183 | #if !ENABLE_PLATFORM_MINGW32 |
