diff options
author | Ron Yorston <rmy@pobox.com> | 2025-01-16 09:18:47 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2025-01-16 09:18:47 +0000 |
commit | 91b6c18d4aa435073e3a6f62dd011b9787103157 (patch) | |
tree | 1dfe0f171815815289b47dfdeb0d2e40b8783288 | |
parent | 85bbce87d6428fbc6a8bf7126988c4458a033727 (diff) | |
download | busybox-w32-91b6c18d4aa435073e3a6f62dd011b9787103157.tar.gz busybox-w32-91b6c18d4aa435073e3a6f62dd011b9787103157.tar.bz2 busybox-w32-91b6c18d4aa435073e3a6f62dd011b9787103157.zip |
make: minor tweaks
Move the code to remove the suffix from a target into a separate
function.
There's no need to test for non-NULL 'makefile' in newcmd().
Cosmetic changes.
Saves 0-16 bytes.
-rw-r--r-- | miscutils/make.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/miscutils/make.c b/miscutils/make.c index 01fc18822..333f8bf12 100644 --- a/miscutils/make.c +++ b/miscutils/make.c | |||
@@ -471,8 +471,7 @@ newcmd(struct cmd **cphead, char *str) | |||
471 | /*(*cphead)->c_next = NULL; - xzalloc did it */ | 471 | /*(*cphead)->c_next = NULL; - xzalloc did it */ |
472 | (*cphead)->c_cmd = xstrdup(str); | 472 | (*cphead)->c_cmd = xstrdup(str); |
473 | /*(*cphead)->c_refcnt = 0; */ | 473 | /*(*cphead)->c_refcnt = 0; */ |
474 | if (makefile) | 474 | (*cphead)->c_makefile = xstrdup(makefile); |
475 | (*cphead)->c_makefile = xstrdup(makefile); | ||
476 | (*cphead)->c_dispno = dispno; | 475 | (*cphead)->c_dispno = dispno; |
477 | } | 476 | } |
478 | 477 | ||
@@ -1117,8 +1116,7 @@ dyndep(struct name *np, struct rule *infrule, const char **ptsuff) | |||
1117 | } | 1116 | } |
1118 | } | 1117 | } |
1119 | 1118 | ||
1120 | } else | 1119 | } else { |
1121 | { | ||
1122 | tsuff = xstrdup(suffix(name)); | 1120 | tsuff = xstrdup(suffix(name)); |
1123 | base = member ? member : name; | 1121 | base = member ? member : name; |
1124 | *suffix(base) = '\0'; | 1122 | *suffix(base) = '\0'; |
@@ -1954,8 +1952,7 @@ target_type(char *s) | |||
1954 | if (is_suffix(s) || is_inference_target(s)) { | 1952 | if (is_suffix(s) || is_inference_target(s)) { |
1955 | ret = T_INFERENCE | T_NOPREREQ | T_COMMAND; | 1953 | ret = T_INFERENCE | T_NOPREREQ | T_COMMAND; |
1956 | } | 1954 | } |
1957 | } else | 1955 | } else { |
1958 | { | ||
1959 | // In POSIX inference rule targets must contain one or two dots | 1956 | // In POSIX inference rule targets must contain one or two dots |
1960 | char *sfx = suffix(s); | 1957 | char *sfx = suffix(s); |
1961 | if (*s == '.' && is_suffix(sfx)) { | 1958 | if (*s == '.' && is_suffix(sfx)) { |
@@ -2679,6 +2676,31 @@ docmds(struct name *np, struct cmd *cp) | |||
2679 | return estat; | 2676 | return estat; |
2680 | } | 2677 | } |
2681 | 2678 | ||
2679 | /* | ||
2680 | * Remove the suffix from a name, either the one provided in 'tsuff' | ||
2681 | * or, if 'tsuff' is NULL, one of the known suffixes. | ||
2682 | */ | ||
2683 | static char * | ||
2684 | remove_suffix(const char *name, const char *tsuff) | ||
2685 | { | ||
2686 | char *base = NULL; | ||
2687 | |||
2688 | if (tsuff != NULL) { | ||
2689 | base = has_suffix(name, tsuff); | ||
2690 | } else { | ||
2691 | struct name *xp = newname(".SUFFIXES"); | ||
2692 | for (struct rule *rp = xp->n_rule; rp; rp = rp->r_next) { | ||
2693 | for (struct depend *dp = rp->r_dep; dp; dp = dp->d_next) { | ||
2694 | base = has_suffix(name, dp->d_name->n_name); | ||
2695 | if (base) { | ||
2696 | return base; | ||
2697 | } | ||
2698 | } | ||
2699 | } | ||
2700 | } | ||
2701 | return base; | ||
2702 | } | ||
2703 | |||
2682 | static int | 2704 | static int |
2683 | make1(struct name *np, struct cmd *cp, char *oodate, char *allsrc, | 2705 | make1(struct name *np, struct cmd *cp, char *oodate, char *allsrc, |
2684 | char *dedup, struct name *implicit, const char *tsuff) | 2706 | char *dedup, struct name *implicit, const char *tsuff) |
@@ -2709,30 +2731,15 @@ make1(struct name *np, struct cmd *cp, char *oodate, char *allsrc, | |||
2709 | prereq = implicit->n_name; | 2731 | prereq = implicit->n_name; |
2710 | 2732 | ||
2711 | if (!posix && member == NULL) { | 2733 | if (!posix && member == NULL) { |
2712 | // As an extension remove the suffix from a target, either | 2734 | // As an extension remove a suffix that doesn't necessarily |
2713 | // that obtained by an inference rule or one of the known | 2735 | // start with a period from a target, but not for targets |
2714 | // suffixes. Not for targets of the form lib.a(member.o). | 2736 | // of the form lib.a(member.o). |
2715 | if (tsuff != NULL) { | 2737 | base = remove_suffix(name, tsuff); |
2716 | base = has_suffix(name, tsuff); | 2738 | if (base) { |
2717 | if (base) { | 2739 | free(name); |
2718 | free(name); | 2740 | name = base; |
2719 | name = base; | ||
2720 | } | ||
2721 | } else { | ||
2722 | struct name *xp = newname(".SUFFIXES"); | ||
2723 | for (struct rule *rp = xp->n_rule; rp; rp = rp->r_next) { | ||
2724 | for (struct depend *dp = rp->r_dep; dp; dp = dp->d_next) { | ||
2725 | base = has_suffix(name, dp->d_name->n_name); | ||
2726 | if (base) { | ||
2727 | free(name); | ||
2728 | name = base; | ||
2729 | goto done; | ||
2730 | } | ||
2731 | } | ||
2732 | } | ||
2733 | } | 2741 | } |
2734 | } else | 2742 | } else { |
2735 | { | ||
2736 | base = member ? member : name; | 2743 | base = member ? member : name; |
2737 | s = suffix(base); | 2744 | s = suffix(base); |
2738 | // As an extension, if we're not dealing with an implicit | 2745 | // As an extension, if we're not dealing with an implicit |
@@ -2744,7 +2751,6 @@ make1(struct name *np, struct cmd *cp, char *oodate, char *allsrc, | |||
2744 | *s = '\0'; | 2751 | *s = '\0'; |
2745 | } | 2752 | } |
2746 | } | 2753 | } |
2747 | done: | ||
2748 | setmacro("<", prereq, 0 | M_VALID); | 2754 | setmacro("<", prereq, 0 | M_VALID); |
2749 | setmacro("*", base, 0 | M_VALID); | 2755 | setmacro("*", base, 0 | M_VALID); |
2750 | free(name); | 2756 | free(name); |
@@ -2830,8 +2836,7 @@ make(struct name *np, int level) | |||
2830 | } | 2836 | } |
2831 | impdep = np; | 2837 | impdep = np; |
2832 | } | 2838 | } |
2833 | } | 2839 | } else { |
2834 | else { | ||
2835 | // If any double-colon rule has no commands we need | 2840 | // If any double-colon rule has no commands we need |
2836 | // an inference rule (but, as an extension, not for phony targets) | 2841 | // an inference rule (but, as an extension, not for phony targets) |
2837 | for (rp = np->n_rule; rp; rp = rp->r_next) { | 2842 | for (rp = np->n_rule; rp; rp = rp->r_next) { |