diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Kbuild.include | 6 | ||||
-rw-r--r-- | scripts/Makefile.build | 1 | ||||
-rw-r--r-- | scripts/Makefile.lib | 7 | ||||
-rw-r--r-- | scripts/Makefile.modbuiltin | 55 | ||||
-rw-r--r-- | scripts/basic/fixdep.c | 10 | ||||
-rw-r--r-- | scripts/genksyms/keywords.c_shipped | 191 | ||||
-rw-r--r-- | scripts/genksyms/keywords.gperf | 2 | ||||
-rwxr-xr-x | scripts/get_maintainer.pl | 499 | ||||
-rwxr-xr-x | scripts/headers.sh | 2 | ||||
-rw-r--r-- | scripts/kconfig/Makefile | 1 | ||||
-rw-r--r-- | scripts/kconfig/confdata.c | 24 | ||||
-rwxr-xr-x | scripts/mkcompile_h | 2 | ||||
-rw-r--r-- | scripts/mod/Makefile | 2 | ||||
-rw-r--r-- | scripts/mod/file2alias.c | 95 | ||||
-rw-r--r-- | scripts/mod/mk_elfconfig.c | 9 | ||||
-rw-r--r-- | scripts/mod/modpost.c | 177 | ||||
-rw-r--r-- | scripts/mod/modpost.h | 3 | ||||
-rw-r--r-- | scripts/package/Makefile | 20 | ||||
-rw-r--r-- | scripts/package/buildtar | 6 | ||||
-rwxr-xr-x | scripts/recordmcount.pl | 61 | ||||
-rwxr-xr-x | scripts/tags.sh | 8 | ||||
-rw-r--r-- | scripts/unifdef.c | 341 |
22 files changed, 957 insertions, 565 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index c67e73ecd5be..ed2773edfe71 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
@@ -149,6 +149,12 @@ ld-option = $(call try-run,\ | |||
149 | # $(Q)$(MAKE) $(build)=dir | 149 | # $(Q)$(MAKE) $(build)=dir |
150 | build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj | 150 | build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj |
151 | 151 | ||
152 | ### | ||
153 | # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= | ||
154 | # Usage: | ||
155 | # $(Q)$(MAKE) $(modbuiltin)=dir | ||
156 | modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj | ||
157 | |||
152 | # Prefix -I with $(srctree) if it is not an absolute path. | 158 | # Prefix -I with $(srctree) if it is not an absolute path. |
153 | # skip if -I has no parameter | 159 | # skip if -I has no parameter |
154 | addtree = $(if $(patsubst -I%,%,$(1)), \ | 160 | addtree = $(if $(patsubst -I%,%,$(1)), \ |
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 341b58902ffc..0b94d2fa3a88 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build | |||
@@ -207,6 +207,7 @@ endif | |||
207 | 207 | ||
208 | ifdef CONFIG_FTRACE_MCOUNT_RECORD | 208 | ifdef CONFIG_FTRACE_MCOUNT_RECORD |
209 | cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ | 209 | cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ |
210 | "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ | ||
210 | "$(if $(CONFIG_64BIT),64,32)" \ | 211 | "$(if $(CONFIG_64BIT),64,32)" \ |
211 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ | 212 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ |
212 | "$(if $(part-of-module),1,0)" "$(@)"; | 213 | "$(if $(part-of-module),1,0)" "$(@)"; |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ffdafb26f539..cd815ac2a50b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -127,6 +127,11 @@ _c_flags += $(if $(patsubst n%,, \ | |||
127 | $(CFLAGS_GCOV)) | 127 | $(CFLAGS_GCOV)) |
128 | endif | 128 | endif |
129 | 129 | ||
130 | ifdef CONFIG_SYMBOL_PREFIX | ||
131 | _cpp_flags += -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX)) | ||
132 | endif | ||
133 | |||
134 | |||
130 | # If building the kernel in a separate objtree expand all occurrences | 135 | # If building the kernel in a separate objtree expand all occurrences |
131 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). | 136 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). |
132 | 137 | ||
@@ -208,7 +213,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \ | |||
208 | 213 | ||
209 | # Bzip2 and LZMA do not include size in file... so we have to fake that; | 214 | # Bzip2 and LZMA do not include size in file... so we have to fake that; |
210 | # append the size as a 32-bit littleendian number as gzip does. | 215 | # append the size as a 32-bit littleendian number as gzip does. |
211 | size_append = /bin/echo -ne $(shell \ | 216 | size_append = printf $(shell \ |
212 | dec_size=0; \ | 217 | dec_size=0; \ |
213 | for F in $1; do \ | 218 | for F in $1; do \ |
214 | fsize=$$(stat -c "%s" $$F); \ | 219 | fsize=$$(stat -c "%s" $$F); \ |
diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin new file mode 100644 index 000000000000..102a276f6eea --- /dev/null +++ b/scripts/Makefile.modbuiltin | |||
@@ -0,0 +1,55 @@ | |||
1 | # ========================================================================== | ||
2 | # Generating modules.builtin | ||
3 | # ========================================================================== | ||
4 | |||
5 | src := $(obj) | ||
6 | |||
7 | PHONY := __modbuiltin | ||
8 | __modbuiltin: | ||
9 | |||
10 | -include include/config/auto.conf | ||
11 | # tristate.conf sets tristate variables to uppercase 'Y' or 'M' | ||
12 | # That way, we get the list of built-in modules in obj-Y | ||
13 | -include include/config/tristate.conf | ||
14 | |||
15 | include scripts/Kbuild.include | ||
16 | |||
17 | # The filename Kbuild has precedence over Makefile | ||
18 | kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) | ||
19 | kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) | ||
20 | include $(kbuild-file) | ||
21 | |||
22 | include scripts/Makefile.lib | ||
23 | __subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y))) | ||
24 | subdir-Y += $(__subdir-Y) | ||
25 | subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m)) | ||
26 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) | ||
27 | obj-Y := $(addprefix $(obj)/,$(obj-Y)) | ||
28 | |||
29 | modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym)) | ||
30 | modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko)) | ||
31 | modbuiltin-target := $(obj)/modules.builtin | ||
32 | |||
33 | __modbuiltin: $(modbuiltin-target) $(subdir-ym) | ||
34 | @: | ||
35 | |||
36 | $(modbuiltin-target): $(subdir-ym) FORCE | ||
37 | $(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done; \ | ||
38 | cat /dev/null $(modbuiltin-subdirs)) > $@ | ||
39 | |||
40 | PHONY += FORCE | ||
41 | |||
42 | FORCE: | ||
43 | |||
44 | # Descending | ||
45 | # --------------------------------------------------------------------------- | ||
46 | |||
47 | PHONY += $(subdir-ym) | ||
48 | $(subdir-ym): | ||
49 | $(Q)$(MAKE) $(modbuiltin)=$@ | ||
50 | |||
51 | |||
52 | # Declare the contents of the .PHONY variable as phony. We keep that | ||
53 | # information in a variable se we can use it in if_changed and friends. | ||
54 | |||
55 | .PHONY: $(PHONY) | ||
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 6bf21f83837d..ea26b23de082 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c | |||
@@ -16,15 +16,15 @@ | |||
16 | * tells make when to remake a file. | 16 | * tells make when to remake a file. |
17 | * | 17 | * |
18 | * To use this list as-is however has the drawback that virtually | 18 | * To use this list as-is however has the drawback that virtually |
19 | * every file in the kernel includes <linux/autoconf.h>. | 19 | * every file in the kernel includes autoconf.h. |
20 | * | 20 | * |
21 | * If the user re-runs make *config, linux/autoconf.h will be | 21 | * If the user re-runs make *config, autoconf.h will be |
22 | * regenerated. make notices that and will rebuild every file which | 22 | * regenerated. make notices that and will rebuild every file which |
23 | * includes autoconf.h, i.e. basically all files. This is extremely | 23 | * includes autoconf.h, i.e. basically all files. This is extremely |
24 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. | 24 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. |
25 | * | 25 | * |
26 | * So we play the same trick that "mkdep" played before. We replace | 26 | * So we play the same trick that "mkdep" played before. We replace |
27 | * the dependency on linux/autoconf.h by a dependency on every config | 27 | * the dependency on autoconf.h by a dependency on every config |
28 | * option which is mentioned in any of the listed prequisites. | 28 | * option which is mentioned in any of the listed prequisites. |
29 | * | 29 | * |
30 | * kconfig populates a tree in include/config/ with an empty file | 30 | * kconfig populates a tree in include/config/ with an empty file |
@@ -73,7 +73,7 @@ | |||
73 | * cmd_<target> = <cmdline> | 73 | * cmd_<target> = <cmdline> |
74 | * | 74 | * |
75 | * and then basically copies the .<target>.d file to stdout, in the | 75 | * and then basically copies the .<target>.d file to stdout, in the |
76 | * process filtering out the dependency on linux/autoconf.h and adding | 76 | * process filtering out the dependency on autoconf.h and adding |
77 | * dependencies on include/config/my/option.h for every | 77 | * dependencies on include/config/my/option.h for every |
78 | * CONFIG_MY_OPTION encountered in any of the prequisites. | 78 | * CONFIG_MY_OPTION encountered in any of the prequisites. |
79 | * | 79 | * |
@@ -324,7 +324,7 @@ static void parse_dep_file(void *map, size_t len) | |||
324 | p++; | 324 | p++; |
325 | } | 325 | } |
326 | memcpy(s, m, p-m); s[p-m] = 0; | 326 | memcpy(s, m, p-m); s[p-m] = 0; |
327 | if (strrcmp(s, "include/linux/autoconf.h") && | 327 | if (strrcmp(s, "include/generated/autoconf.h") && |
328 | strrcmp(s, "arch/um/include/uml-config.h") && | 328 | strrcmp(s, "arch/um/include/uml-config.h") && |
329 | strrcmp(s, ".ver")) { | 329 | strrcmp(s, ".ver")) { |
330 | printf(" %s \\\n", s); | 330 | printf(" %s \\\n", s); |
diff --git a/scripts/genksyms/keywords.c_shipped b/scripts/genksyms/keywords.c_shipped index 287467a2e8c7..8060e06798b3 100644 --- a/scripts/genksyms/keywords.c_shipped +++ b/scripts/genksyms/keywords.c_shipped | |||
@@ -1,4 +1,4 @@ | |||
1 | /* ANSI-C code produced by gperf version 3.0.3 */ | 1 | /* ANSI-C code produced by gperf version 3.0.4 */ |
2 | /* Command-line: gperf -L ANSI-C -a -C -E -g -H is_reserved_hash -k '1,3,$' -N is_reserved_word -p -t scripts/genksyms/keywords.gperf */ | 2 | /* Command-line: gperf -L ANSI-C -a -C -E -g -H is_reserved_hash -k '1,3,$' -N is_reserved_word -p -t scripts/genksyms/keywords.gperf */ |
3 | 3 | ||
4 | #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ | 4 | #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ |
@@ -34,7 +34,7 @@ struct resword; | |||
34 | static const struct resword *is_reserved_word(register const char *str, register unsigned int len); | 34 | static const struct resword *is_reserved_word(register const char *str, register unsigned int len); |
35 | #line 5 "scripts/genksyms/keywords.gperf" | 35 | #line 5 "scripts/genksyms/keywords.gperf" |
36 | struct resword { const char *name; int token; }; | 36 | struct resword { const char *name; int token; }; |
37 | /* maximum key range = 62, duplicates = 0 */ | 37 | /* maximum key range = 64, duplicates = 0 */ |
38 | 38 | ||
39 | #ifdef __GNUC__ | 39 | #ifdef __GNUC__ |
40 | __inline | 40 | __inline |
@@ -48,39 +48,39 @@ is_reserved_hash (register const char *str, register unsigned int len) | |||
48 | { | 48 | { |
49 | static const unsigned char asso_values[] = | 49 | static const unsigned char asso_values[] = |
50 | { | 50 | { |
51 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 51 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
52 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 52 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
53 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 53 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
54 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 54 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
55 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 55 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
56 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 56 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
57 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 5, | 57 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 0, |
58 | 65, 65, 65, 65, 65, 65, 35, 65, 65, 65, | 58 | 67, 67, 67, 67, 67, 67, 15, 67, 67, 67, |
59 | 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 59 | 0, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
60 | 65, 65, 65, 65, 65, 0, 65, 0, 65, 5, | 60 | 67, 67, 67, 67, 67, 0, 67, 0, 67, 5, |
61 | 20, 15, 10, 30, 65, 15, 65, 65, 20, 0, | 61 | 25, 20, 15, 30, 67, 15, 67, 67, 10, 0, |
62 | 10, 35, 20, 65, 10, 5, 0, 10, 5, 65, | 62 | 10, 40, 20, 67, 10, 5, 0, 10, 15, 67, |
63 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 63 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
64 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 64 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
65 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 65 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
66 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 66 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
67 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 67 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
68 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 68 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
69 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 69 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
70 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 70 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
71 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 71 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
72 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 72 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
73 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 73 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
74 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 74 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
75 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 75 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
76 | 65, 65, 65, 65, 65, 65 | 76 | 67, 67, 67, 67, 67, 67 |
77 | }; | 77 | }; |
78 | return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]] + asso_values[(unsigned char)str[len - 1]]; | 78 | return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]] + asso_values[(unsigned char)str[len - 1]]; |
79 | } | 79 | } |
80 | 80 | ||
81 | #ifdef __GNUC__ | 81 | #ifdef __GNUC__ |
82 | __inline | 82 | __inline |
83 | #ifdef __GNUC_STDC_INLINE__ | 83 | #if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ |
84 | __attribute__ ((__gnu_inline__)) | 84 | __attribute__ ((__gnu_inline__)) |
85 | #endif | 85 | #endif |
86 | #endif | 86 | #endif |
@@ -89,116 +89,119 @@ is_reserved_word (register const char *str, register unsigned int len) | |||
89 | { | 89 | { |
90 | enum | 90 | enum |
91 | { | 91 | { |
92 | TOTAL_KEYWORDS = 43, | 92 | TOTAL_KEYWORDS = 45, |
93 | MIN_WORD_LENGTH = 3, | 93 | MIN_WORD_LENGTH = 3, |
94 | MAX_WORD_LENGTH = 24, | 94 | MAX_WORD_LENGTH = 24, |
95 | MIN_HASH_VALUE = 3, | 95 | MIN_HASH_VALUE = 3, |
96 | MAX_HASH_VALUE = 64 | 96 | MAX_HASH_VALUE = 66 |
97 | }; | 97 | }; |
98 | 98 | ||
99 | static const struct resword wordlist[] = | 99 | static const struct resword wordlist[] = |
100 | { | 100 | { |
101 | {""}, {""}, {""}, | 101 | {""}, {""}, {""}, |
102 | #line 28 "scripts/genksyms/keywords.gperf" | 102 | #line 30 "scripts/genksyms/keywords.gperf" |
103 | {"asm", ASM_KEYW}, | 103 | {"asm", ASM_KEYW}, |
104 | {""}, | 104 | {""}, |
105 | #line 10 "scripts/genksyms/keywords.gperf" | 105 | #line 12 "scripts/genksyms/keywords.gperf" |
106 | {"__asm", ASM_KEYW}, | 106 | {"__asm", ASM_KEYW}, |
107 | {""}, | 107 | {""}, |
108 | #line 11 "scripts/genksyms/keywords.gperf" | 108 | #line 13 "scripts/genksyms/keywords.gperf" |
109 | {"__asm__", ASM_KEYW}, | 109 | {"__asm__", ASM_KEYW}, |
110 | {""}, {""}, | 110 | {""}, {""}, |
111 | #line 54 "scripts/genksyms/keywords.gperf" | 111 | #line 56 "scripts/genksyms/keywords.gperf" |
112 | {"__typeof__", TYPEOF_KEYW}, | 112 | {"__typeof__", TYPEOF_KEYW}, |
113 | {""}, | 113 | {""}, |
114 | #line 14 "scripts/genksyms/keywords.gperf" | 114 | #line 16 "scripts/genksyms/keywords.gperf" |
115 | {"__const", CONST_KEYW}, | 115 | {"__const", CONST_KEYW}, |
116 | #line 13 "scripts/genksyms/keywords.gperf" | ||
117 | {"__attribute__", ATTRIBUTE_KEYW}, | ||
118 | #line 15 "scripts/genksyms/keywords.gperf" | 116 | #line 15 "scripts/genksyms/keywords.gperf" |
117 | {"__attribute__", ATTRIBUTE_KEYW}, | ||
118 | #line 17 "scripts/genksyms/keywords.gperf" | ||
119 | {"__const__", CONST_KEYW}, | 119 | {"__const__", CONST_KEYW}, |
120 | #line 20 "scripts/genksyms/keywords.gperf" | 120 | #line 22 "scripts/genksyms/keywords.gperf" |
121 | {"__signed__", SIGNED_KEYW}, | 121 | {"__signed__", SIGNED_KEYW}, |
122 | #line 46 "scripts/genksyms/keywords.gperf" | 122 | #line 48 "scripts/genksyms/keywords.gperf" |
123 | {"static", STATIC_KEYW}, | 123 | {"static", STATIC_KEYW}, |
124 | #line 22 "scripts/genksyms/keywords.gperf" | 124 | {""}, |
125 | {"__volatile__", VOLATILE_KEYW}, | 125 | #line 43 "scripts/genksyms/keywords.gperf" |
126 | #line 41 "scripts/genksyms/keywords.gperf" | ||
127 | {"int", INT_KEYW}, | 126 | {"int", INT_KEYW}, |
128 | #line 34 "scripts/genksyms/keywords.gperf" | 127 | #line 36 "scripts/genksyms/keywords.gperf" |
129 | {"char", CHAR_KEYW}, | 128 | {"char", CHAR_KEYW}, |
130 | #line 35 "scripts/genksyms/keywords.gperf" | 129 | #line 37 "scripts/genksyms/keywords.gperf" |
131 | {"const", CONST_KEYW}, | 130 | {"const", CONST_KEYW}, |
132 | #line 47 "scripts/genksyms/keywords.gperf" | 131 | #line 49 "scripts/genksyms/keywords.gperf" |
133 | {"struct", STRUCT_KEYW}, | 132 | {"struct", STRUCT_KEYW}, |
134 | #line 26 "scripts/genksyms/keywords.gperf" | 133 | #line 28 "scripts/genksyms/keywords.gperf" |
135 | {"__restrict__", RESTRICT_KEYW}, | 134 | {"__restrict__", RESTRICT_KEYW}, |
136 | #line 27 "scripts/genksyms/keywords.gperf" | 135 | #line 29 "scripts/genksyms/keywords.gperf" |
137 | {"restrict", RESTRICT_KEYW}, | 136 | {"restrict", RESTRICT_KEYW}, |
138 | #line 25 "scripts/genksyms/keywords.gperf" | 137 | #line 9 "scripts/genksyms/keywords.gperf" |
139 | {"_restrict", RESTRICT_KEYW}, | 138 | {"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW}, |
140 | #line 18 "scripts/genksyms/keywords.gperf" | 139 | #line 20 "scripts/genksyms/keywords.gperf" |
141 | {"__inline__", INLINE_KEYW}, | 140 | {"__inline__", INLINE_KEYW}, |
142 | #line 12 "scripts/genksyms/keywords.gperf" | ||
143 | {"__attribute", ATTRIBUTE_KEYW}, | ||
144 | {""}, | 141 | {""}, |
145 | #line 16 "scripts/genksyms/keywords.gperf" | 142 | #line 24 "scripts/genksyms/keywords.gperf" |
143 | {"__volatile__", VOLATILE_KEYW}, | ||
144 | #line 7 "scripts/genksyms/keywords.gperf" | ||
145 | {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW}, | ||
146 | #line 27 "scripts/genksyms/keywords.gperf" | ||
147 | {"_restrict", RESTRICT_KEYW}, | ||
148 | {""}, | ||
149 | #line 14 "scripts/genksyms/keywords.gperf" | ||
150 | {"__attribute", ATTRIBUTE_KEYW}, | ||
151 | #line 8 "scripts/genksyms/keywords.gperf" | ||
152 | {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, | ||
153 | #line 18 "scripts/genksyms/keywords.gperf" | ||
146 | {"__extension__", EXTENSION_KEYW}, | 154 | {"__extension__", EXTENSION_KEYW}, |
147 | #line 37 "scripts/genksyms/keywords.gperf" | 155 | #line 39 "scripts/genksyms/keywords.gperf" |
148 | {"enum", ENUM_KEYW}, | 156 | {"enum", ENUM_KEYW}, |
149 | #line 21 "scripts/genksyms/keywords.gperf" | 157 | #line 10 "scripts/genksyms/keywords.gperf" |
150 | {"__volatile", VOLATILE_KEYW}, | 158 | {"EXPORT_UNUSED_SYMBOL", EXPORT_SYMBOL_KEYW}, |
151 | #line 38 "scripts/genksyms/keywords.gperf" | 159 | #line 40 "scripts/genksyms/keywords.gperf" |
152 | {"extern", EXTERN_KEYW}, | 160 | {"extern", EXTERN_KEYW}, |
153 | {""}, | 161 | {""}, |
154 | #line 19 "scripts/genksyms/keywords.gperf" | 162 | #line 21 "scripts/genksyms/keywords.gperf" |
155 | {"__signed", SIGNED_KEYW}, | 163 | {"__signed", SIGNED_KEYW}, |
156 | #line 9 "scripts/genksyms/keywords.gperf" | 164 | #line 11 "scripts/genksyms/keywords.gperf" |
157 | {"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW}, | 165 | {"EXPORT_UNUSED_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, |
158 | {""}, | 166 | #line 51 "scripts/genksyms/keywords.gperf" |
159 | #line 53 "scripts/genksyms/keywords.gperf" | 167 | {"union", UNION_KEYW}, |
168 | #line 55 "scripts/genksyms/keywords.gperf" | ||
160 | {"typeof", TYPEOF_KEYW}, | 169 | {"typeof", TYPEOF_KEYW}, |
161 | #line 48 "scripts/genksyms/keywords.gperf" | 170 | #line 50 "scripts/genksyms/keywords.gperf" |
162 | {"typedef", TYPEDEF_KEYW}, | 171 | {"typedef", TYPEDEF_KEYW}, |
163 | #line 17 "scripts/genksyms/keywords.gperf" | 172 | #line 19 "scripts/genksyms/keywords.gperf" |
164 | {"__inline", INLINE_KEYW}, | 173 | {"__inline", INLINE_KEYW}, |
165 | #line 33 "scripts/genksyms/keywords.gperf" | 174 | #line 35 "scripts/genksyms/keywords.gperf" |
166 | {"auto", AUTO_KEYW}, | 175 | {"auto", AUTO_KEYW}, |
167 | #line 49 "scripts/genksyms/keywords.gperf" | 176 | #line 23 "scripts/genksyms/keywords.gperf" |
168 | {"union", UNION_KEYW}, | 177 | {"__volatile", VOLATILE_KEYW}, |
169 | {""}, {""}, | ||
170 | #line 50 "scripts/genksyms/keywords.gperf" | ||
171 | {"unsigned", UNSIGNED_KEYW}, | ||
172 | #line 51 "scripts/genksyms/keywords.gperf" | ||
173 | {"void", VOID_KEYW}, | ||
174 | #line 44 "scripts/genksyms/keywords.gperf" | ||
175 | {"short", SHORT_KEYW}, | ||
176 | {""}, {""}, | 178 | {""}, {""}, |
177 | #line 52 "scripts/genksyms/keywords.gperf" | 179 | #line 52 "scripts/genksyms/keywords.gperf" |
178 | {"volatile", VOLATILE_KEYW}, | 180 | {"unsigned", UNSIGNED_KEYW}, |
179 | {""}, | ||
180 | #line 39 "scripts/genksyms/keywords.gperf" | ||
181 | {"float", FLOAT_KEYW}, | ||
182 | #line 36 "scripts/genksyms/keywords.gperf" | ||
183 | {"double", DOUBLE_KEYW}, | ||
184 | {""}, | 181 | {""}, |
185 | #line 7 "scripts/genksyms/keywords.gperf" | 182 | #line 46 "scripts/genksyms/keywords.gperf" |
186 | {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW}, | 183 | {"short", SHORT_KEYW}, |
187 | {""}, {""}, | 184 | #line 42 "scripts/genksyms/keywords.gperf" |
188 | #line 40 "scripts/genksyms/keywords.gperf" | ||
189 | {"inline", INLINE_KEYW}, | 185 | {"inline", INLINE_KEYW}, |
190 | #line 8 "scripts/genksyms/keywords.gperf" | ||
191 | {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, | ||
192 | #line 43 "scripts/genksyms/keywords.gperf" | ||
193 | {"register", REGISTER_KEYW}, | ||
194 | {""}, | 186 | {""}, |
195 | #line 24 "scripts/genksyms/keywords.gperf" | 187 | #line 54 "scripts/genksyms/keywords.gperf" |
188 | {"volatile", VOLATILE_KEYW}, | ||
189 | #line 44 "scripts/genksyms/keywords.gperf" | ||
190 | {"long", LONG_KEYW}, | ||
191 | #line 26 "scripts/genksyms/keywords.gperf" | ||
196 | {"_Bool", BOOL_KEYW}, | 192 | {"_Bool", BOOL_KEYW}, |
197 | #line 45 "scripts/genksyms/keywords.gperf" | ||
198 | {"signed", SIGNED_KEYW}, | ||
199 | {""}, {""}, | 193 | {""}, {""}, |
200 | #line 42 "scripts/genksyms/keywords.gperf" | 194 | #line 45 "scripts/genksyms/keywords.gperf" |
201 | {"long", LONG_KEYW} | 195 | {"register", REGISTER_KEYW}, |
196 | #line 53 "scripts/genksyms/keywords.gperf" | ||
197 | {"void", VOID_KEYW}, | ||
198 | #line 41 "scripts/genksyms/keywords.gperf" | ||
199 | {"float", FLOAT_KEYW}, | ||
200 | #line 38 "scripts/genksyms/keywords.gperf" | ||
201 | {"double", DOUBLE_KEYW}, | ||
202 | {""}, {""}, {""}, {""}, | ||
203 | #line 47 "scripts/genksyms/keywords.gperf" | ||
204 | {"signed", SIGNED_KEYW} | ||
202 | }; | 205 | }; |
203 | 206 | ||
204 | if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) | 207 | if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) |
diff --git a/scripts/genksyms/keywords.gperf b/scripts/genksyms/keywords.gperf index 8fe977a4d57b..e6349acb6f2f 100644 --- a/scripts/genksyms/keywords.gperf +++ b/scripts/genksyms/keywords.gperf | |||
@@ -7,6 +7,8 @@ struct resword { const char *name; int token; } | |||
7 | EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW | 7 | EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW |
8 | EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW | 8 | EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW |
9 | EXPORT_SYMBOL_GPL_FUTURE, EXPORT_SYMBOL_KEYW | 9 | EXPORT_SYMBOL_GPL_FUTURE, EXPORT_SYMBOL_KEYW |
10 | EXPORT_UNUSED_SYMBOL, EXPORT_SYMBOL_KEYW | ||
11 | EXPORT_UNUSED_SYMBOL_GPL, EXPORT_SYMBOL_KEYW | ||
10 | __asm, ASM_KEYW | 12 | __asm, ASM_KEYW |
11 | __asm__, ASM_KEYW | 13 | __asm__, ASM_KEYW |
12 | __attribute, ATTRIBUTE_KEYW | 14 | __attribute, ATTRIBUTE_KEYW |
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index 81a67a458e78..445e8845f0a4 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl | |||
@@ -13,7 +13,7 @@ | |||
13 | use strict; | 13 | use strict; |
14 | 14 | ||
15 | my $P = $0; | 15 | my $P = $0; |
16 | my $V = '0.21'; | 16 | my $V = '0.23'; |
17 | 17 | ||
18 | use Getopt::Long qw(:config no_auto_abbrev); | 18 | use Getopt::Long qw(:config no_auto_abbrev); |
19 | 19 | ||
@@ -23,16 +23,19 @@ my $email_usename = 1; | |||
23 | my $email_maintainer = 1; | 23 | my $email_maintainer = 1; |
24 | my $email_list = 1; | 24 | my $email_list = 1; |
25 | my $email_subscriber_list = 0; | 25 | my $email_subscriber_list = 0; |
26 | my $email_git = 1; | ||
27 | my $email_git_penguin_chiefs = 0; | 26 | my $email_git_penguin_chiefs = 0; |
27 | my $email_git = 1; | ||
28 | my $email_git_blame = 0; | ||
28 | my $email_git_min_signatures = 1; | 29 | my $email_git_min_signatures = 1; |
29 | my $email_git_max_maintainers = 5; | 30 | my $email_git_max_maintainers = 5; |
30 | my $email_git_min_percent = 5; | 31 | my $email_git_min_percent = 5; |
31 | my $email_git_since = "1-year-ago"; | 32 | my $email_git_since = "1-year-ago"; |
32 | my $email_git_blame = 0; | 33 | my $email_hg_since = "-365"; |
33 | my $email_remove_duplicates = 1; | 34 | my $email_remove_duplicates = 1; |
34 | my $output_multiline = 1; | 35 | my $output_multiline = 1; |
35 | my $output_separator = ", "; | 36 | my $output_separator = ", "; |
37 | my $output_roles = 0; | ||
38 | my $output_rolestats = 0; | ||
36 | my $scm = 0; | 39 | my $scm = 0; |
37 | my $web = 0; | 40 | my $web = 0; |
38 | my $subsystem = 0; | 41 | my $subsystem = 0; |
@@ -64,21 +67,52 @@ my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)"; | |||
64 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; | 67 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; |
65 | my $rfc822_char = '[\\000-\\377]'; | 68 | my $rfc822_char = '[\\000-\\377]'; |
66 | 69 | ||
70 | # VCS command support: class-like functions and strings | ||
71 | |||
72 | my %VCS_cmds; | ||
73 | |||
74 | my %VCS_cmds_git = ( | ||
75 | "execute_cmd" => \&git_execute_cmd, | ||
76 | "available" => '(which("git") ne "") && (-d ".git")', | ||
77 | "find_signers_cmd" => "git log --since=\$email_git_since -- \$file", | ||
78 | "find_commit_signers_cmd" => "git log -1 \$commit", | ||
79 | "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", | ||
80 | "blame_file_cmd" => "git blame -l \$file", | ||
81 | "commit_pattern" => "^commit [0-9a-f]{40,40}", | ||
82 | "blame_commit_pattern" => "^([0-9a-f]+) " | ||
83 | ); | ||
84 | |||
85 | my %VCS_cmds_hg = ( | ||
86 | "execute_cmd" => \&hg_execute_cmd, | ||
87 | "available" => '(which("hg") ne "") && (-d ".hg")', | ||
88 | "find_signers_cmd" => | ||
89 | "hg log --date=\$email_hg_since" . | ||
90 | " --template='commit {node}\\n{desc}\\n' -- \$file", | ||
91 | "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", | ||
92 | "blame_range_cmd" => "", # not supported | ||
93 | "blame_file_cmd" => "hg blame -c \$file", | ||
94 | "commit_pattern" => "^commit [0-9a-f]{40,40}", | ||
95 | "blame_commit_pattern" => "^([0-9a-f]+):" | ||
96 | ); | ||
97 | |||
67 | if (!GetOptions( | 98 | if (!GetOptions( |
68 | 'email!' => \$email, | 99 | 'email!' => \$email, |
69 | 'git!' => \$email_git, | 100 | 'git!' => \$email_git, |
101 | 'git-blame!' => \$email_git_blame, | ||
70 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, | 102 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, |
71 | 'git-min-signatures=i' => \$email_git_min_signatures, | 103 | 'git-min-signatures=i' => \$email_git_min_signatures, |
72 | 'git-max-maintainers=i' => \$email_git_max_maintainers, | 104 | 'git-max-maintainers=i' => \$email_git_max_maintainers, |
73 | 'git-min-percent=i' => \$email_git_min_percent, | 105 | 'git-min-percent=i' => \$email_git_min_percent, |
74 | 'git-since=s' => \$email_git_since, | 106 | 'git-since=s' => \$email_git_since, |
75 | 'git-blame!' => \$email_git_blame, | 107 | 'hg-since=s' => \$email_hg_since, |
76 | 'remove-duplicates!' => \$email_remove_duplicates, | 108 | 'remove-duplicates!' => \$email_remove_duplicates, |
77 | 'm!' => \$email_maintainer, | 109 | 'm!' => \$email_maintainer, |
78 | 'n!' => \$email_usename, | 110 | 'n!' => \$email_usename, |
79 | 'l!' => \$email_list, | 111 | 'l!' => \$email_list, |
80 | 's!' => \$email_subscriber_list, | 112 | 's!' => \$email_subscriber_list, |
81 | 'multiline!' => \$output_multiline, | 113 | 'multiline!' => \$output_multiline, |
114 | 'roles!' => \$output_roles, | ||
115 | 'rolestats!' => \$output_rolestats, | ||
82 | 'separator=s' => \$output_separator, | 116 | 'separator=s' => \$output_separator, |
83 | 'subsystem!' => \$subsystem, | 117 | 'subsystem!' => \$subsystem, |
84 | 'status!' => \$status, | 118 | 'status!' => \$status, |
@@ -90,8 +124,7 @@ if (!GetOptions( | |||
90 | 'v|version' => \$version, | 124 | 'v|version' => \$version, |
91 | 'h|help' => \$help, | 125 | 'h|help' => \$help, |
92 | )) { | 126 | )) { |
93 | usage(); | 127 | die "$P: invalid argument - use --help if necessary\n"; |
94 | die "$P: invalid argument\n"; | ||
95 | } | 128 | } |
96 | 129 | ||
97 | if ($help != 0) { | 130 | if ($help != 0) { |
@@ -113,6 +146,10 @@ if ($output_separator ne ", ") { | |||
113 | $output_multiline = 0; | 146 | $output_multiline = 0; |
114 | } | 147 | } |
115 | 148 | ||
149 | if ($output_rolestats) { | ||
150 | $output_roles = 1; | ||
151 | } | ||
152 | |||
116 | my $selections = $email + $scm + $status + $subsystem + $web; | 153 | my $selections = $email + $scm + $status + $subsystem + $web; |
117 | if ($selections == 0) { | 154 | if ($selections == 0) { |
118 | usage(); | 155 | usage(); |
@@ -175,7 +212,7 @@ if ($email_remove_duplicates) { | |||
175 | next if ($line =~ m/^\s*$/); | 212 | next if ($line =~ m/^\s*$/); |
176 | 213 | ||
177 | my ($name, $address) = parse_email($line); | 214 | my ($name, $address) = parse_email($line); |
178 | $line = format_email($name, $address); | 215 | $line = format_email($name, $address, $email_usename); |
179 | 216 | ||
180 | next if ($line =~ m/^\s*$/); | 217 | next if ($line =~ m/^\s*$/); |
181 | 218 | ||
@@ -207,12 +244,10 @@ foreach my $file (@ARGV) { | |||
207 | push(@files, $file); | 244 | push(@files, $file); |
208 | if (-f $file && $keywords) { | 245 | if (-f $file && $keywords) { |
209 | open(FILE, "<$file") or die "$P: Can't open ${file}\n"; | 246 | open(FILE, "<$file") or die "$P: Can't open ${file}\n"; |
210 | while (<FILE>) { | 247 | my $text = do { local($/) ; <FILE> }; |
211 | my $patch_line = $_; | 248 | foreach my $line (keys %keyword_hash) { |
212 | foreach my $line (keys %keyword_hash) { | 249 | if ($text =~ m/$keyword_hash{$line}/x) { |
213 | if ($patch_line =~ m/^.*$keyword_hash{$line}/x) { | 250 | push(@keyword_tvi, $line); |
214 | push(@keyword_tvi, $line); | ||
215 | } | ||
216 | } | 251 | } |
217 | } | 252 | } |
218 | close(FILE); | 253 | close(FILE); |
@@ -304,11 +339,11 @@ foreach my $file (@files) { | |||
304 | } | 339 | } |
305 | 340 | ||
306 | if ($email && $email_git) { | 341 | if ($email && $email_git) { |
307 | recent_git_signoffs($file); | 342 | vcs_file_signoffs($file); |
308 | } | 343 | } |
309 | 344 | ||
310 | if ($email && $email_git_blame) { | 345 | if ($email && $email_git_blame) { |
311 | git_assign_blame($file); | 346 | vcs_file_blame($file); |
312 | } | 347 | } |
313 | } | 348 | } |
314 | 349 | ||
@@ -324,11 +359,11 @@ if ($email) { | |||
324 | if ($chief =~ m/^(.*):(.*)/) { | 359 | if ($chief =~ m/^(.*):(.*)/) { |
325 | my $email_address; | 360 | my $email_address; |
326 | 361 | ||
327 | $email_address = format_email($1, $2); | 362 | $email_address = format_email($1, $2, $email_usename); |
328 | if ($email_git_penguin_chiefs) { | 363 | if ($email_git_penguin_chiefs) { |
329 | push(@email_to, $email_address); | 364 | push(@email_to, [$email_address, 'chief penguin']); |
330 | } else { | 365 | } else { |
331 | @email_to = grep(!/${email_address}/, @email_to); | 366 | @email_to = grep($_->[0] !~ /${email_address}/, @email_to); |
332 | } | 367 | } |
333 | } | 368 | } |
334 | } | 369 | } |
@@ -342,7 +377,7 @@ if ($email || $email_list) { | |||
342 | if ($email_list) { | 377 | if ($email_list) { |
343 | @to = (@to, @list_to); | 378 | @to = (@to, @list_to); |
344 | } | 379 | } |
345 | output(uniq(@to)); | 380 | output(merge_email(@to)); |
346 | } | 381 | } |
347 | 382 | ||
348 | if ($scm) { | 383 | if ($scm) { |
@@ -398,13 +433,16 @@ MAINTAINER field selection options: | |||
398 | --git-min-signatures => number of signatures required (default: 1) | 433 | --git-min-signatures => number of signatures required (default: 1) |
399 | --git-max-maintainers => maximum maintainers to add (default: 5) | 434 | --git-max-maintainers => maximum maintainers to add (default: 5) |
400 | --git-min-percent => minimum percentage of commits required (default: 5) | 435 | --git-min-percent => minimum percentage of commits required (default: 5) |
401 | --git-since => git history to use (default: 1-year-ago) | ||
402 | --git-blame => use git blame to find modified commits for patch or file | 436 | --git-blame => use git blame to find modified commits for patch or file |
437 | --git-since => git history to use (default: 1-year-ago) | ||
438 | --hg-since => hg history to use (default: -365) | ||
403 | --m => include maintainer(s) if any | 439 | --m => include maintainer(s) if any |
404 | --n => include name 'Full Name <addr\@domain.tld>' | 440 | --n => include name 'Full Name <addr\@domain.tld>' |
405 | --l => include list(s) if any | 441 | --l => include list(s) if any |
406 | --s => include subscriber only list(s) if any | 442 | --s => include subscriber only list(s) if any |
407 | --remove-duplicates => minimize duplicate email names/addresses | 443 | --remove-duplicates => minimize duplicate email names/addresses |
444 | --roles => show roles (status:subsystem, git-signer, list, etc...) | ||
445 | --rolestats => show roles and statistics (commits/total_commits, %) | ||
408 | --scm => print SCM tree(s) if any | 446 | --scm => print SCM tree(s) if any |
409 | --status => print status if any | 447 | --status => print status if any |
410 | --subsystem => print subsystem name if any | 448 | --subsystem => print subsystem name if any |
@@ -430,11 +468,24 @@ Notes: | |||
430 | directory are examined as git recurses directories. | 468 | directory are examined as git recurses directories. |
431 | Any specified X: (exclude) pattern matches are _not_ ignored. | 469 | Any specified X: (exclude) pattern matches are _not_ ignored. |
432 | Used with "--nogit", directory is used as a pattern match, | 470 | Used with "--nogit", directory is used as a pattern match, |
433 | no individual file within the directory or subdirectory | 471 | no individual file within the directory or subdirectory |
434 | is matched. | 472 | is matched. |
435 | Used with "--git-blame", does not iterate all files in directory | 473 | Used with "--git-blame", does not iterate all files in directory |
436 | Using "--git-blame" is slow and may add old committers and authors | 474 | Using "--git-blame" is slow and may add old committers and authors |
437 | that are no longer active maintainers to the output. | 475 | that are no longer active maintainers to the output. |
476 | Using "--roles" or "--rolestats" with git send-email --cc-cmd or any | ||
477 | other automated tools that expect only ["name"] <email address> | ||
478 | may not work because of additional output after <email address>. | ||
479 | Using "--rolestats" and "--git-blame" shows the #/total=% commits, | ||
480 | not the percentage of the entire file authored. # of commits is | ||
481 | not a good measure of amount of code authored. 1 major commit may | ||
482 | contain a thousand lines, 5 trivial commits may modify a single line. | ||
483 | If git is not installed, but mercurial (hg) is installed and an .hg | ||
484 | repository exists, the following options apply to mercurial: | ||
485 | --git, | ||
486 | --git-min-signatures, --git-max-maintainers, --git-min-percent, and | ||
487 | --git-blame | ||
488 | Use --hg-since not --git-since to control date selection | ||
438 | EOT | 489 | EOT |
439 | } | 490 | } |
440 | 491 | ||
@@ -493,7 +544,7 @@ sub parse_email { | |||
493 | } | 544 | } |
494 | 545 | ||
495 | sub format_email { | 546 | sub format_email { |
496 | my ($name, $address) = @_; | 547 | my ($name, $address, $usename) = @_; |
497 | 548 | ||
498 | my $formatted_email; | 549 | my $formatted_email; |
499 | 550 | ||
@@ -506,11 +557,11 @@ sub format_email { | |||
506 | $name = "\"$name\""; | 557 | $name = "\"$name\""; |
507 | } | 558 | } |
508 | 559 | ||
509 | if ($email_usename) { | 560 | if ($usename) { |
510 | if ("$name" eq "") { | 561 | if ("$name" eq "") { |
511 | $formatted_email = "$address"; | 562 | $formatted_email = "$address"; |
512 | } else { | 563 | } else { |
513 | $formatted_email = "$name <${address}>"; | 564 | $formatted_email = "$name <$address>"; |
514 | } | 565 | } |
515 | } else { | 566 | } else { |
516 | $formatted_email = $address; | 567 | $formatted_email = $address; |
@@ -547,6 +598,71 @@ sub find_ending_index { | |||
547 | return $index; | 598 | return $index; |
548 | } | 599 | } |
549 | 600 | ||
601 | sub get_maintainer_role { | ||
602 | my ($index) = @_; | ||
603 | |||
604 | my $i; | ||
605 | my $start = find_starting_index($index); | ||
606 | my $end = find_ending_index($index); | ||
607 | |||
608 | my $role; | ||
609 | my $subsystem = $typevalue[$start]; | ||
610 | if (length($subsystem) > 20) { | ||
611 | $subsystem = substr($subsystem, 0, 17); | ||
612 | $subsystem =~ s/\s*$//; | ||
613 | $subsystem = $subsystem . "..."; | ||
614 | } | ||
615 | |||
616 | for ($i = $start + 1; $i < $end; $i++) { | ||
617 | my $tv = $typevalue[$i]; | ||
618 | if ($tv =~ m/^(\C):\s*(.*)/) { | ||
619 | my $ptype = $1; | ||
620 | my $pvalue = $2; | ||
621 | if ($ptype eq "S") { | ||
622 | $role = $pvalue; | ||
623 | } | ||
624 | } | ||
625 | } | ||
626 | |||
627 | $role = lc($role); | ||
628 | if ($role eq "supported") { | ||
629 | $role = "supporter"; | ||
630 | } elsif ($role eq "maintained") { | ||
631 | $role = "maintainer"; | ||
632 | } elsif ($role eq "odd fixes") { | ||
633 | $role = "odd fixer"; | ||
634 | } elsif ($role eq "orphan") { | ||
635 | $role = "orphan minder"; | ||
636 | } elsif ($role eq "obsolete") { | ||
637 | $role = "obsolete minder"; | ||
638 | } elsif ($role eq "buried alive in reporters") { | ||
639 | $role = "chief penguin"; | ||
640 | } | ||
641 | |||
642 | return $role . ":" . $subsystem; | ||
643 | } | ||
644 | |||
645 | sub get_list_role { | ||
646 | my ($index) = @_; | ||
647 | |||
648 | my $i; | ||
649 | my $start = find_starting_index($index); | ||
650 | my $end = find_ending_index($index); | ||
651 | |||
652 | my $subsystem = $typevalue[$start]; | ||
653 | if (length($subsystem) > 20) { | ||
654 | $subsystem = substr($subsystem, 0, 17); | ||
655 | $subsystem =~ s/\s*$//; | ||
656 | $subsystem = $subsystem . "..."; | ||
657 | } | ||
658 | |||
659 | if ($subsystem eq "THE REST") { | ||
660 | $subsystem = ""; | ||
661 | } | ||
662 | |||
663 | return $subsystem; | ||
664 | } | ||
665 | |||
550 | sub add_categories { | 666 | sub add_categories { |
551 | my ($index) = @_; | 667 | my ($index) = @_; |
552 | 668 | ||
@@ -564,17 +680,22 @@ sub add_categories { | |||
564 | if ($ptype eq "L") { | 680 | if ($ptype eq "L") { |
565 | my $list_address = $pvalue; | 681 | my $list_address = $pvalue; |
566 | my $list_additional = ""; | 682 | my $list_additional = ""; |
683 | my $list_role = get_list_role($i); | ||
684 | |||
685 | if ($list_role ne "") { | ||
686 | $list_role = ":" . $list_role; | ||
687 | } | ||
567 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { | 688 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { |
568 | $list_address = $1; | 689 | $list_address = $1; |
569 | $list_additional = $2; | 690 | $list_additional = $2; |
570 | } | 691 | } |
571 | if ($list_additional =~ m/subscribers-only/) { | 692 | if ($list_additional =~ m/subscribers-only/) { |
572 | if ($email_subscriber_list) { | 693 | if ($email_subscriber_list) { |
573 | push(@list_to, $list_address); | 694 | push(@list_to, [$list_address, "subscriber list${list_role}"]); |
574 | } | 695 | } |
575 | } else { | 696 | } else { |
576 | if ($email_list) { | 697 | if ($email_list) { |
577 | push(@list_to, $list_address); | 698 | push(@list_to, [$list_address, "open list${list_role}"]); |
578 | } | 699 | } |
579 | } | 700 | } |
580 | } elsif ($ptype eq "M") { | 701 | } elsif ($ptype eq "M") { |
@@ -585,13 +706,14 @@ sub add_categories { | |||
585 | if ($tv =~ m/^(\C):\s*(.*)/) { | 706 | if ($tv =~ m/^(\C):\s*(.*)/) { |
586 | if ($1 eq "P") { | 707 | if ($1 eq "P") { |
587 | $name = $2; | 708 | $name = $2; |
588 | $pvalue = format_email($name, $address); | 709 | $pvalue = format_email($name, $address, $email_usename); |
589 | } | 710 | } |
590 | } | 711 | } |
591 | } | 712 | } |
592 | } | 713 | } |
593 | if ($email_maintainer) { | 714 | if ($email_maintainer) { |
594 | push_email_addresses($pvalue); | 715 | my $role = get_maintainer_role($i); |
716 | push_email_addresses($pvalue, $role); | ||
595 | } | 717 | } |
596 | } elsif ($ptype eq "T") { | 718 | } elsif ($ptype eq "T") { |
597 | push(@scm, $pvalue); | 719 | push(@scm, $pvalue); |
@@ -618,7 +740,7 @@ sub email_inuse { | |||
618 | } | 740 | } |
619 | 741 | ||
620 | sub push_email_address { | 742 | sub push_email_address { |
621 | my ($line) = @_; | 743 | my ($line, $role) = @_; |
622 | 744 | ||
623 | my ($name, $address) = parse_email($line); | 745 | my ($name, $address) = parse_email($line); |
624 | 746 | ||
@@ -627,9 +749,9 @@ sub push_email_address { | |||
627 | } | 749 | } |
628 | 750 | ||
629 | if (!$email_remove_duplicates) { | 751 | if (!$email_remove_duplicates) { |
630 | push(@email_to, format_email($name, $address)); | 752 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
631 | } elsif (!email_inuse($name, $address)) { | 753 | } elsif (!email_inuse($name, $address)) { |
632 | push(@email_to, format_email($name, $address)); | 754 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
633 | $email_hash_name{$name}++; | 755 | $email_hash_name{$name}++; |
634 | $email_hash_address{$address}++; | 756 | $email_hash_address{$address}++; |
635 | } | 757 | } |
@@ -638,24 +760,52 @@ sub push_email_address { | |||
638 | } | 760 | } |
639 | 761 | ||
640 | sub push_email_addresses { | 762 | sub push_email_addresses { |
641 | my ($address) = @_; | 763 | my ($address, $role) = @_; |
642 | 764 | ||
643 | my @address_list = (); | 765 | my @address_list = (); |
644 | 766 | ||
645 | if (rfc822_valid($address)) { | 767 | if (rfc822_valid($address)) { |
646 | push_email_address($address); | 768 | push_email_address($address, $role); |
647 | } elsif (@address_list = rfc822_validlist($address)) { | 769 | } elsif (@address_list = rfc822_validlist($address)) { |
648 | my $array_count = shift(@address_list); | 770 | my $array_count = shift(@address_list); |
649 | while (my $entry = shift(@address_list)) { | 771 | while (my $entry = shift(@address_list)) { |
650 | push_email_address($entry); | 772 | push_email_address($entry, $role); |
651 | } | 773 | } |
652 | } else { | 774 | } else { |
653 | if (!push_email_address($address)) { | 775 | if (!push_email_address($address, $role)) { |
654 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); | 776 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); |
655 | } | 777 | } |
656 | } | 778 | } |
657 | } | 779 | } |
658 | 780 | ||
781 | sub add_role { | ||
782 | my ($line, $role) = @_; | ||
783 | |||
784 | my ($name, $address) = parse_email($line); | ||
785 | my $email = format_email($name, $address, $email_usename); | ||
786 | |||
787 | foreach my $entry (@email_to) { | ||
788 | if ($email_remove_duplicates) { | ||
789 | my ($entry_name, $entry_address) = parse_email($entry->[0]); | ||
790 | if ($name eq $entry_name || $address eq $entry_address) { | ||
791 | if ($entry->[1] eq "") { | ||
792 | $entry->[1] = "$role"; | ||
793 | } else { | ||
794 | $entry->[1] = "$entry->[1],$role"; | ||
795 | } | ||
796 | } | ||
797 | } else { | ||
798 | if ($email eq $entry->[0]) { | ||
799 | if ($entry->[1] eq "") { | ||
800 | $entry->[1] = "$role"; | ||
801 | } else { | ||
802 | $entry->[1] = "$entry->[1],$role"; | ||
803 | } | ||
804 | } | ||
805 | } | ||
806 | } | ||
807 | } | ||
808 | |||
659 | sub which { | 809 | sub which { |
660 | my ($bin) = @_; | 810 | my ($bin) = @_; |
661 | 811 | ||
@@ -669,7 +819,7 @@ sub which { | |||
669 | } | 819 | } |
670 | 820 | ||
671 | sub mailmap { | 821 | sub mailmap { |
672 | my @lines = @_; | 822 | my (@lines) = @_; |
673 | my %hash; | 823 | my %hash; |
674 | 824 | ||
675 | foreach my $line (@lines) { | 825 | foreach my $line (@lines) { |
@@ -678,14 +828,14 @@ sub mailmap { | |||
678 | $hash{$name} = $address; | 828 | $hash{$name} = $address; |
679 | } elsif ($address ne $hash{$name}) { | 829 | } elsif ($address ne $hash{$name}) { |
680 | $address = $hash{$name}; | 830 | $address = $hash{$name}; |
681 | $line = format_email($name, $address); | 831 | $line = format_email($name, $address, $email_usename); |
682 | } | 832 | } |
683 | if (exists($mailmap{$name})) { | 833 | if (exists($mailmap{$name})) { |
684 | my $obj = $mailmap{$name}; | 834 | my $obj = $mailmap{$name}; |
685 | foreach my $map_address (@$obj) { | 835 | foreach my $map_address (@$obj) { |
686 | if (($map_address eq $address) && | 836 | if (($map_address eq $address) && |
687 | ($map_address ne $hash{$name})) { | 837 | ($map_address ne $hash{$name})) { |
688 | $line = format_email($name, $hash{$name}); | 838 | $line = format_email($name, $hash{$name}, $email_usename); |
689 | } | 839 | } |
690 | } | 840 | } |
691 | } | 841 | } |
@@ -694,34 +844,38 @@ sub mailmap { | |||
694 | return @lines; | 844 | return @lines; |
695 | } | 845 | } |
696 | 846 | ||
697 | sub recent_git_signoffs { | 847 | sub git_execute_cmd { |
698 | my ($file) = @_; | 848 | my ($cmd) = @_; |
699 | |||
700 | my $sign_offs = ""; | ||
701 | my $cmd = ""; | ||
702 | my $output = ""; | ||
703 | my $count = 0; | ||
704 | my @lines = (); | 849 | my @lines = (); |
705 | my %hash; | ||
706 | my $total_sign_offs; | ||
707 | 850 | ||
708 | if (which("git") eq "") { | 851 | my $output = `$cmd`; |
709 | warn("$P: git not found. Add --nogit to options?\n"); | 852 | $output =~ s/^\s*//gm; |
710 | return; | 853 | @lines = split("\n", $output); |
711 | } | ||
712 | if (!(-d ".git")) { | ||
713 | warn("$P: .git directory not found. Use a git repository for better results.\n"); | ||
714 | warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n"); | ||
715 | return; | ||
716 | } | ||
717 | 854 | ||
718 | $cmd = "git log --since=${email_git_since} -- ${file}"; | 855 | return @lines; |
856 | } | ||
719 | 857 | ||
720 | $output = `${cmd}`; | 858 | sub hg_execute_cmd { |
721 | $output =~ s/^\s*//gm; | 859 | my ($cmd) = @_; |
860 | my @lines = (); | ||
722 | 861 | ||
862 | my $output = `$cmd`; | ||
723 | @lines = split("\n", $output); | 863 | @lines = split("\n", $output); |
724 | 864 | ||
865 | return @lines; | ||
866 | } | ||
867 | |||
868 | sub vcs_find_signers { | ||
869 | my ($cmd) = @_; | ||
870 | my @lines = (); | ||
871 | my $commits; | ||
872 | |||
873 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); | ||
874 | |||
875 | my $pattern = $VCS_cmds{"commit_pattern"}; | ||
876 | |||
877 | $commits = grep(/$pattern/, @lines); # of commits | ||
878 | |||
725 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); | 879 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); |
726 | if (!$email_git_penguin_chiefs) { | 880 | if (!$email_git_penguin_chiefs) { |
727 | @lines = grep(!/${penguin_chiefs}/i, @lines); | 881 | @lines = grep(!/${penguin_chiefs}/i, @lines); |
@@ -729,111 +883,183 @@ sub recent_git_signoffs { | |||
729 | # cut -f2- -d":" | 883 | # cut -f2- -d":" |
730 | s/.*:\s*(.+)\s*/$1/ for (@lines); | 884 | s/.*:\s*(.+)\s*/$1/ for (@lines); |
731 | 885 | ||
732 | $total_sign_offs = @lines; | 886 | ## Reformat email addresses (with names) to avoid badly written signatures |
733 | 887 | ||
734 | if ($email_remove_duplicates) { | 888 | foreach my $line (@lines) { |
735 | @lines = mailmap(@lines); | 889 | my ($name, $address) = parse_email($line); |
890 | $line = format_email($name, $address, 1); | ||
736 | } | 891 | } |
737 | 892 | ||
738 | @lines = sort(@lines); | 893 | return ($commits, @lines); |
739 | |||
740 | # uniq -c | ||
741 | $hash{$_}++ for @lines; | ||
742 | |||
743 | # sort -rn | ||
744 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | ||
745 | my $sign_offs = $hash{$line}; | ||
746 | $count++; | ||
747 | last if ($sign_offs < $email_git_min_signatures || | ||
748 | $count > $email_git_max_maintainers || | ||
749 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent); | ||
750 | push_email_address($line); | ||
751 | } | ||
752 | } | 894 | } |
753 | 895 | ||
754 | sub save_commits { | 896 | sub vcs_save_commits { |
755 | my ($cmd, @commits) = @_; | 897 | my ($cmd) = @_; |
756 | my $output; | ||
757 | my @lines = (); | 898 | my @lines = (); |
899 | my @commits = (); | ||
758 | 900 | ||
759 | $output = `${cmd}`; | 901 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
760 | 902 | ||
761 | @lines = split("\n", $output); | ||
762 | foreach my $line (@lines) { | 903 | foreach my $line (@lines) { |
763 | if ($line =~ m/^(\w+) /) { | 904 | if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) { |
764 | push (@commits, $1); | 905 | push(@commits, $1); |
765 | } | 906 | } |
766 | } | 907 | } |
908 | |||
767 | return @commits; | 909 | return @commits; |
768 | } | 910 | } |
769 | 911 | ||
770 | sub git_assign_blame { | 912 | sub vcs_blame { |
771 | my ($file) = @_; | 913 | my ($file) = @_; |
772 | |||
773 | my @lines = (); | ||
774 | my @commits = (); | ||
775 | my $cmd; | 914 | my $cmd; |
776 | my $output; | 915 | my @commits = (); |
777 | my %hash; | 916 | |
778 | my $total_sign_offs; | 917 | return @commits if (!(-f $file)); |
779 | my $count; | 918 | |
919 | if (@range && $VCS_cmds{"blame_range_cmd"} eq "") { | ||
920 | my @all_commits = (); | ||
921 | |||
922 | $cmd = $VCS_cmds{"blame_file_cmd"}; | ||
923 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
924 | @all_commits = vcs_save_commits($cmd); | ||
780 | 925 | ||
781 | if (@range) { | ||
782 | foreach my $file_range_diff (@range) { | 926 | foreach my $file_range_diff (@range) { |
783 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); | 927 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
784 | my $diff_file = $1; | 928 | my $diff_file = $1; |
785 | my $diff_start = $2; | 929 | my $diff_start = $2; |
786 | my $diff_length = $3; | 930 | my $diff_length = $3; |
787 | next if (!("$file" eq "$diff_file")); | 931 | next if ("$file" ne "$diff_file"); |
788 | $cmd = "git blame -l -L $diff_start,+$diff_length $file"; | 932 | for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) { |
789 | @commits = save_commits($cmd, @commits); | 933 | push(@commits, $all_commits[$i]); |
934 | } | ||
790 | } | 935 | } |
791 | } else { | 936 | } elsif (@range) { |
792 | if (-f $file) { | 937 | foreach my $file_range_diff (@range) { |
793 | $cmd = "git blame -l $file"; | 938 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
794 | @commits = save_commits($cmd, @commits); | 939 | my $diff_file = $1; |
940 | my $diff_start = $2; | ||
941 | my $diff_length = $3; | ||
942 | next if ("$file" ne "$diff_file"); | ||
943 | $cmd = $VCS_cmds{"blame_range_cmd"}; | ||
944 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
945 | push(@commits, vcs_save_commits($cmd)); | ||
795 | } | 946 | } |
947 | } else { | ||
948 | $cmd = $VCS_cmds{"blame_file_cmd"}; | ||
949 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
950 | @commits = vcs_save_commits($cmd); | ||
796 | } | 951 | } |
797 | 952 | ||
798 | $total_sign_offs = 0; | 953 | return @commits; |
799 | @commits = uniq(@commits); | 954 | } |
800 | foreach my $commit (@commits) { | ||
801 | $cmd = "git log -1 ${commit}"; | ||
802 | 955 | ||
803 | $output = `${cmd}`; | 956 | my $printed_novcs = 0; |
804 | $output =~ s/^\s*//gm; | 957 | sub vcs_exists { |
805 | @lines = split("\n", $output); | 958 | %VCS_cmds = %VCS_cmds_git; |
959 | return 1 if eval $VCS_cmds{"available"}; | ||
960 | %VCS_cmds = %VCS_cmds_hg; | ||
961 | return 1 if eval $VCS_cmds{"available"}; | ||
962 | %VCS_cmds = (); | ||
963 | if (!$printed_novcs) { | ||
964 | warn("$P: No supported VCS found. Add --nogit to options?\n"); | ||
965 | warn("Using a git repository produces better results.\n"); | ||
966 | warn("Try Linus Torvalds' latest git repository using:\n"); | ||
967 | warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); | ||
968 | $printed_novcs = 1; | ||
969 | } | ||
970 | return 0; | ||
971 | } | ||
806 | 972 | ||
807 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); | 973 | sub vcs_assign { |
808 | if (!$email_git_penguin_chiefs) { | 974 | my ($role, $divisor, @lines) = @_; |
809 | @lines = grep(!/${penguin_chiefs}/i, @lines); | ||
810 | } | ||
811 | 975 | ||
812 | # cut -f2- -d":" | 976 | my %hash; |
813 | s/.*:\s*(.+)\s*/$1/ for (@lines); | 977 | my $count = 0; |
814 | 978 | ||
815 | $total_sign_offs += @lines; | 979 | return if (@lines <= 0); |
816 | 980 | ||
817 | if ($email_remove_duplicates) { | 981 | if ($divisor <= 0) { |
818 | @lines = mailmap(@lines); | 982 | warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n"); |
819 | } | 983 | $divisor = 1; |
984 | } | ||
820 | 985 | ||
821 | $hash{$_}++ for @lines; | 986 | if ($email_remove_duplicates) { |
987 | @lines = mailmap(@lines); | ||
822 | } | 988 | } |
823 | 989 | ||
824 | $count = 0; | 990 | @lines = sort(@lines); |
991 | |||
992 | # uniq -c | ||
993 | $hash{$_}++ for @lines; | ||
994 | |||
995 | # sort -rn | ||
825 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | 996 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
826 | my $sign_offs = $hash{$line}; | 997 | my $sign_offs = $hash{$line}; |
998 | my $percent = $sign_offs * 100 / $divisor; | ||
999 | |||
1000 | $percent = 100 if ($percent > 100); | ||
827 | $count++; | 1001 | $count++; |
828 | last if ($sign_offs < $email_git_min_signatures || | 1002 | last if ($sign_offs < $email_git_min_signatures || |
829 | $count > $email_git_max_maintainers || | 1003 | $count > $email_git_max_maintainers || |
830 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent); | 1004 | $percent < $email_git_min_percent); |
831 | push_email_address($line); | 1005 | push_email_address($line, ''); |
1006 | if ($output_rolestats) { | ||
1007 | my $fmt_percent = sprintf("%.0f", $percent); | ||
1008 | add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%"); | ||
1009 | } else { | ||
1010 | add_role($line, $role); | ||
1011 | } | ||
1012 | } | ||
1013 | } | ||
1014 | |||
1015 | sub vcs_file_signoffs { | ||
1016 | my ($file) = @_; | ||
1017 | |||
1018 | my @signers = (); | ||
1019 | my $commits; | ||
1020 | |||
1021 | return if (!vcs_exists()); | ||
1022 | |||
1023 | my $cmd = $VCS_cmds{"find_signers_cmd"}; | ||
1024 | $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd | ||
1025 | |||
1026 | ($commits, @signers) = vcs_find_signers($cmd); | ||
1027 | vcs_assign("commit_signer", $commits, @signers); | ||
1028 | } | ||
1029 | |||
1030 | sub vcs_file_blame { | ||
1031 | my ($file) = @_; | ||
1032 | |||
1033 | my @signers = (); | ||
1034 | my @commits = (); | ||
1035 | my $total_commits; | ||
1036 | |||
1037 | return if (!vcs_exists()); | ||
1038 | |||
1039 | @commits = vcs_blame($file); | ||
1040 | @commits = uniq(@commits); | ||
1041 | $total_commits = @commits; | ||
1042 | |||
1043 | foreach my $commit (@commits) { | ||
1044 | my $commit_count; | ||
1045 | my @commit_signers = (); | ||
1046 | |||
1047 | my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; | ||
1048 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
1049 | |||
1050 | ($commit_count, @commit_signers) = vcs_find_signers($cmd); | ||
1051 | push(@signers, @commit_signers); | ||
1052 | } | ||
1053 | |||
1054 | if ($from_filename) { | ||
1055 | vcs_assign("commits", $total_commits, @signers); | ||
1056 | } else { | ||
1057 | vcs_assign("modified commits", $total_commits, @signers); | ||
832 | } | 1058 | } |
833 | } | 1059 | } |
834 | 1060 | ||
835 | sub uniq { | 1061 | sub uniq { |
836 | my @parms = @_; | 1062 | my (@parms) = @_; |
837 | 1063 | ||
838 | my %saw; | 1064 | my %saw; |
839 | @parms = grep(!$saw{$_}++, @parms); | 1065 | @parms = grep(!$saw{$_}++, @parms); |
@@ -841,7 +1067,7 @@ sub uniq { | |||
841 | } | 1067 | } |
842 | 1068 | ||
843 | sub sort_and_uniq { | 1069 | sub sort_and_uniq { |
844 | my @parms = @_; | 1070 | my (@parms) = @_; |
845 | 1071 | ||
846 | my %saw; | 1072 | my %saw; |
847 | @parms = sort @parms; | 1073 | @parms = sort @parms; |
@@ -849,8 +1075,27 @@ sub sort_and_uniq { | |||
849 | return @parms; | 1075 | return @parms; |
850 | } | 1076 | } |
851 | 1077 | ||
1078 | sub merge_email { | ||
1079 | my @lines; | ||
1080 | my %saw; | ||
1081 | |||
1082 | for (@_) { | ||
1083 | my ($address, $role) = @$_; | ||
1084 | if (!$saw{$address}) { | ||
1085 | if ($output_roles) { | ||
1086 | push(@lines, "$address ($role)"); | ||
1087 | } else { | ||
1088 | push(@lines, $address); | ||
1089 | } | ||
1090 | $saw{$address} = 1; | ||
1091 | } | ||
1092 | } | ||
1093 | |||
1094 | return @lines; | ||
1095 | } | ||
1096 | |||
852 | sub output { | 1097 | sub output { |
853 | my @parms = @_; | 1098 | my (@parms) = @_; |
854 | 1099 | ||
855 | if ($output_multiline) { | 1100 | if ($output_multiline) { |
856 | foreach my $line (@parms) { | 1101 | foreach my $line (@parms) { |
@@ -947,11 +1192,9 @@ sub rfc822_validlist ($) { | |||
947 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && | 1192 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && |
948 | $s =~ m/^$rfc822_char*$/) { | 1193 | $s =~ m/^$rfc822_char*$/) { |
949 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { | 1194 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { |
950 | push @r, $1; | 1195 | push(@r, $1); |
951 | } | 1196 | } |
952 | return wantarray ? (scalar(@r), @r) : 1; | 1197 | return wantarray ? (scalar(@r), @r) : 1; |
953 | } | 1198 | } |
954 | else { | 1199 | return wantarray ? () : 0; |
955 | return wantarray ? () : 0; | ||
956 | } | ||
957 | } | 1200 | } |
diff --git a/scripts/headers.sh b/scripts/headers.sh index 0308ecc10d5b..1ddcdd38d97f 100755 --- a/scripts/headers.sh +++ b/scripts/headers.sh | |||
@@ -8,8 +8,6 @@ do_command() | |||
8 | { | 8 | { |
9 | if [ -f ${srctree}/arch/$2/include/asm/Kbuild ]; then | 9 | if [ -f ${srctree}/arch/$2/include/asm/Kbuild ]; then |
10 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 | 10 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 |
11 | elif [ -f ${srctree}/include/asm-$2/Kbuild ]; then | ||
12 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 | ||
13 | else | 11 | else |
14 | printf "Ignoring arch: %s\n" ${arch} | 12 | printf "Ignoring arch: %s\n" ${arch} |
15 | fi | 13 | fi |
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 80599e3a7994..999e8a7d5bf7 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
@@ -27,6 +27,7 @@ oldconfig: $(obj)/conf | |||
27 | $< -o $(Kconfig) | 27 | $< -o $(Kconfig) |
28 | 28 | ||
29 | silentoldconfig: $(obj)/conf | 29 | silentoldconfig: $(obj)/conf |
30 | $(Q)mkdir -p include/generated | ||
30 | $< -s $(Kconfig) | 31 | $< -s $(Kconfig) |
31 | 32 | ||
32 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf | 33 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf |
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index b55e72ff2fc6..c4dec80cfd8e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -677,7 +677,7 @@ int conf_write_autoconf(void) | |||
677 | struct symbol *sym; | 677 | struct symbol *sym; |
678 | const char *str; | 678 | const char *str; |
679 | const char *name; | 679 | const char *name; |
680 | FILE *out, *out_h; | 680 | FILE *out, *tristate, *out_h; |
681 | time_t now; | 681 | time_t now; |
682 | int i, l; | 682 | int i, l; |
683 | 683 | ||
@@ -692,9 +692,16 @@ int conf_write_autoconf(void) | |||
692 | if (!out) | 692 | if (!out) |
693 | return 1; | 693 | return 1; |
694 | 694 | ||
695 | tristate = fopen(".tmpconfig_tristate", "w"); | ||
696 | if (!tristate) { | ||
697 | fclose(out); | ||
698 | return 1; | ||
699 | } | ||
700 | |||
695 | out_h = fopen(".tmpconfig.h", "w"); | 701 | out_h = fopen(".tmpconfig.h", "w"); |
696 | if (!out_h) { | 702 | if (!out_h) { |
697 | fclose(out); | 703 | fclose(out); |
704 | fclose(tristate); | ||
698 | return 1; | 705 | return 1; |
699 | } | 706 | } |
700 | 707 | ||
@@ -707,6 +714,9 @@ int conf_write_autoconf(void) | |||
707 | "# %s" | 714 | "# %s" |
708 | "#\n", | 715 | "#\n", |
709 | sym_get_string_value(sym), ctime(&now)); | 716 | sym_get_string_value(sym), ctime(&now)); |
717 | fprintf(tristate, "#\n" | ||
718 | "# Automatically generated - do not edit\n" | ||
719 | "\n"); | ||
710 | fprintf(out_h, "/*\n" | 720 | fprintf(out_h, "/*\n" |
711 | " * Automatically generated C config: don't edit\n" | 721 | " * Automatically generated C config: don't edit\n" |
712 | " * Linux kernel version: %s\n" | 722 | " * Linux kernel version: %s\n" |
@@ -727,10 +737,14 @@ int conf_write_autoconf(void) | |||
727 | break; | 737 | break; |
728 | case mod: | 738 | case mod: |
729 | fprintf(out, "CONFIG_%s=m\n", sym->name); | 739 | fprintf(out, "CONFIG_%s=m\n", sym->name); |
740 | fprintf(tristate, "CONFIG_%s=M\n", sym->name); | ||
730 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); | 741 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); |
731 | break; | 742 | break; |
732 | case yes: | 743 | case yes: |
733 | fprintf(out, "CONFIG_%s=y\n", sym->name); | 744 | fprintf(out, "CONFIG_%s=y\n", sym->name); |
745 | if (sym->type == S_TRISTATE) | ||
746 | fprintf(tristate, "CONFIG_%s=Y\n", | ||
747 | sym->name); | ||
734 | fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); | 748 | fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); |
735 | break; | 749 | break; |
736 | } | 750 | } |
@@ -772,13 +786,19 @@ int conf_write_autoconf(void) | |||
772 | } | 786 | } |
773 | } | 787 | } |
774 | fclose(out); | 788 | fclose(out); |
789 | fclose(tristate); | ||
775 | fclose(out_h); | 790 | fclose(out_h); |
776 | 791 | ||
777 | name = getenv("KCONFIG_AUTOHEADER"); | 792 | name = getenv("KCONFIG_AUTOHEADER"); |
778 | if (!name) | 793 | if (!name) |
779 | name = "include/linux/autoconf.h"; | 794 | name = "include/generated/autoconf.h"; |
780 | if (rename(".tmpconfig.h", name)) | 795 | if (rename(".tmpconfig.h", name)) |
781 | return 1; | 796 | return 1; |
797 | name = getenv("KCONFIG_TRISTATE"); | ||
798 | if (!name) | ||
799 | name = "include/config/tristate.conf"; | ||
800 | if (rename(".tmpconfig_tristate", name)) | ||
801 | return 1; | ||
782 | name = conf_get_autoconfig_name(); | 802 | name = conf_get_autoconfig_name(); |
783 | /* | 803 | /* |
784 | * This must be the last step, kbuild has a dependency on auto.conf | 804 | * This must be the last step, kbuild has a dependency on auto.conf |
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h index bce3d0fe6fbd..23dbad80cce9 100755 --- a/scripts/mkcompile_h +++ b/scripts/mkcompile_h | |||
@@ -14,7 +14,7 @@ vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } | |||
14 | # So "sudo make install" won't change the "compiled by <user>" | 14 | # So "sudo make install" won't change the "compiled by <user>" |
15 | # do "compiled by root" | 15 | # do "compiled by root" |
16 | 16 | ||
17 | if [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then | 17 | if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then |
18 | vecho " SKIPPED $TARGET" | 18 | vecho " SKIPPED $TARGET" |
19 | exit 0 | 19 | exit 0 |
20 | fi | 20 | fi |
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile index 11d69c35e5b4..ff954f8168c1 100644 --- a/scripts/mod/Makefile +++ b/scripts/mod/Makefile | |||
@@ -8,7 +8,7 @@ modpost-objs := modpost.o file2alias.o sumversion.o | |||
8 | $(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h | 8 | $(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h |
9 | 9 | ||
10 | quiet_cmd_elfconfig = MKELF $@ | 10 | quiet_cmd_elfconfig = MKELF $@ |
11 | cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@ | 11 | cmd_elfconfig = $(obj)/mk_elfconfig < $< > $@ |
12 | 12 | ||
13 | $(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE | 13 | $(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE |
14 | $(call if_changed,elfconfig) | 14 | $(call if_changed,elfconfig) |
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 62a9025cdcc7..6f426afbc522 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
@@ -104,7 +104,7 @@ static void device_id_check(const char *modname, const char *device_id, | |||
104 | static void do_usb_entry(struct usb_device_id *id, | 104 | static void do_usb_entry(struct usb_device_id *id, |
105 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, | 105 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, |
106 | unsigned char range_lo, unsigned char range_hi, | 106 | unsigned char range_lo, unsigned char range_hi, |
107 | struct module *mod) | 107 | unsigned char max, struct module *mod) |
108 | { | 108 | { |
109 | char alias[500]; | 109 | char alias[500]; |
110 | strcpy(alias, "usb:"); | 110 | strcpy(alias, "usb:"); |
@@ -118,9 +118,22 @@ static void do_usb_entry(struct usb_device_id *id, | |||
118 | sprintf(alias + strlen(alias), "%0*X", | 118 | sprintf(alias + strlen(alias), "%0*X", |
119 | bcdDevice_initial_digits, bcdDevice_initial); | 119 | bcdDevice_initial_digits, bcdDevice_initial); |
120 | if (range_lo == range_hi) | 120 | if (range_lo == range_hi) |
121 | sprintf(alias + strlen(alias), "%u", range_lo); | 121 | sprintf(alias + strlen(alias), "%X", range_lo); |
122 | else if (range_lo > 0 || range_hi < 9) | 122 | else if (range_lo > 0 || range_hi < max) { |
123 | sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi); | 123 | if (range_lo > 0x9 || range_hi < 0xA) |
124 | sprintf(alias + strlen(alias), | ||
125 | "[%X-%X]", | ||
126 | range_lo, | ||
127 | range_hi); | ||
128 | else { | ||
129 | sprintf(alias + strlen(alias), | ||
130 | range_lo < 0x9 ? "[%X-9" : "[%X", | ||
131 | range_lo); | ||
132 | sprintf(alias + strlen(alias), | ||
133 | range_hi > 0xA ? "a-%X]" : "%X]", | ||
134 | range_lo); | ||
135 | } | ||
136 | } | ||
124 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) | 137 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) |
125 | strcat(alias, "*"); | 138 | strcat(alias, "*"); |
126 | 139 | ||
@@ -147,10 +160,49 @@ static void do_usb_entry(struct usb_device_id *id, | |||
147 | "MODULE_ALIAS(\"%s\");\n", alias); | 160 | "MODULE_ALIAS(\"%s\");\n", alias); |
148 | } | 161 | } |
149 | 162 | ||
163 | /* Handles increment/decrement of BCD formatted integers */ | ||
164 | /* Returns the previous value, so it works like i++ or i-- */ | ||
165 | static unsigned int incbcd(unsigned int *bcd, | ||
166 | int inc, | ||
167 | unsigned char max, | ||
168 | size_t chars) | ||
169 | { | ||
170 | unsigned int init = *bcd, i, j; | ||
171 | unsigned long long c, dec = 0; | ||
172 | |||
173 | /* If bcd is not in BCD format, just increment */ | ||
174 | if (max > 0x9) { | ||
175 | *bcd += inc; | ||
176 | return init; | ||
177 | } | ||
178 | |||
179 | /* Convert BCD to Decimal */ | ||
180 | for (i=0 ; i < chars ; i++) { | ||
181 | c = (*bcd >> (i << 2)) & 0xf; | ||
182 | c = c > 9 ? 9 : c; /* force to bcd just in case */ | ||
183 | for (j=0 ; j < i ; j++) | ||
184 | c = c * 10; | ||
185 | dec += c; | ||
186 | } | ||
187 | |||
188 | /* Do our increment/decrement */ | ||
189 | dec += inc; | ||
190 | *bcd = 0; | ||
191 | |||
192 | /* Convert back to BCD */ | ||
193 | for (i=0 ; i < chars ; i++) { | ||
194 | for (c=1,j=0 ; j < i ; j++) | ||
195 | c = c * 10; | ||
196 | c = (dec / c) % 10; | ||
197 | *bcd += c << (i << 2); | ||
198 | } | ||
199 | return init; | ||
200 | } | ||
201 | |||
150 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | 202 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) |
151 | { | 203 | { |
152 | unsigned int devlo, devhi; | 204 | unsigned int devlo, devhi; |
153 | unsigned char chi, clo; | 205 | unsigned char chi, clo, max; |
154 | int ndigits; | 206 | int ndigits; |
155 | 207 | ||
156 | id->match_flags = TO_NATIVE(id->match_flags); | 208 | id->match_flags = TO_NATIVE(id->match_flags); |
@@ -162,6 +214,17 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | |||
162 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? | 214 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? |
163 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; | 215 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; |
164 | 216 | ||
217 | /* Figure out if this entry is in bcd or hex format */ | ||
218 | max = 0x9; /* Default to decimal format */ | ||
219 | for (ndigits = 0 ; ndigits < sizeof(id->bcdDevice_lo) * 2 ; ndigits++) { | ||
220 | clo = (devlo >> (ndigits << 2)) & 0xf; | ||
221 | chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf; | ||
222 | if (clo > max || chi > max) { | ||
223 | max = 0xf; | ||
224 | break; | ||
225 | } | ||
226 | } | ||
227 | |||
165 | /* | 228 | /* |
166 | * Some modules (visor) have empty slots as placeholder for | 229 | * Some modules (visor) have empty slots as placeholder for |
167 | * run-time specification that results in catch-all alias | 230 | * run-time specification that results in catch-all alias |
@@ -173,21 +236,27 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | |||
173 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { | 236 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { |
174 | clo = devlo & 0xf; | 237 | clo = devlo & 0xf; |
175 | chi = devhi & 0xf; | 238 | chi = devhi & 0xf; |
176 | if (chi > 9) /* it's bcd not hex */ | 239 | if (chi > max) /* If we are in bcd mode, truncate if necessary */ |
177 | chi = 9; | 240 | chi = max; |
178 | devlo >>= 4; | 241 | devlo >>= 4; |
179 | devhi >>= 4; | 242 | devhi >>= 4; |
180 | 243 | ||
181 | if (devlo == devhi || !ndigits) { | 244 | if (devlo == devhi || !ndigits) { |
182 | do_usb_entry(id, devlo, ndigits, clo, chi, mod); | 245 | do_usb_entry(id, devlo, ndigits, clo, chi, max, mod); |
183 | break; | 246 | break; |
184 | } | 247 | } |
185 | 248 | ||
186 | if (clo > 0) | 249 | if (clo > 0x0) |
187 | do_usb_entry(id, devlo++, ndigits, clo, 9, mod); | 250 | do_usb_entry(id, |
188 | 251 | incbcd(&devlo, 1, max, | |
189 | if (chi < 9) | 252 | sizeof(id->bcdDevice_lo) * 2), |
190 | do_usb_entry(id, devhi--, ndigits, 0, chi, mod); | 253 | ndigits, clo, max, max, mod); |
254 | |||
255 | if (chi < max) | ||
256 | do_usb_entry(id, | ||
257 | incbcd(&devhi, -1, max, | ||
258 | sizeof(id->bcdDevice_lo) * 2), | ||
259 | ndigits, 0x0, chi, max, mod); | ||
191 | } | 260 | } |
192 | } | 261 | } |
193 | 262 | ||
diff --git a/scripts/mod/mk_elfconfig.c b/scripts/mod/mk_elfconfig.c index 6a96d47bd1e6..639bca7ba559 100644 --- a/scripts/mod/mk_elfconfig.c +++ b/scripts/mod/mk_elfconfig.c | |||
@@ -9,9 +9,6 @@ main(int argc, char **argv) | |||
9 | unsigned char ei[EI_NIDENT]; | 9 | unsigned char ei[EI_NIDENT]; |
10 | union { short s; char c[2]; } endian_test; | 10 | union { short s; char c[2]; } endian_test; |
11 | 11 | ||
12 | if (argc != 2) { | ||
13 | fprintf(stderr, "Error: no arch\n"); | ||
14 | } | ||
15 | if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { | 12 | if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { |
16 | fprintf(stderr, "Error: input truncated\n"); | 13 | fprintf(stderr, "Error: input truncated\n"); |
17 | return 1; | 14 | return 1; |
@@ -55,12 +52,6 @@ main(int argc, char **argv) | |||
55 | else | 52 | else |
56 | exit(1); | 53 | exit(1); |
57 | 54 | ||
58 | if ((strcmp(argv[1], "h8300") == 0) | ||
59 | || (strcmp(argv[1], "blackfin") == 0)) | ||
60 | printf("#define MODULE_SYMBOL_PREFIX \"_\"\n"); | ||
61 | else | ||
62 | printf("#define MODULE_SYMBOL_PREFIX \"\"\n"); | ||
63 | |||
64 | return 0; | 55 | return 0; |
65 | } | 56 | } |
66 | 57 | ||
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 801a16a17545..20923613467c 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
@@ -15,8 +15,17 @@ | |||
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <ctype.h> | 16 | #include <ctype.h> |
17 | #include "modpost.h" | 17 | #include "modpost.h" |
18 | #include "../../include/generated/autoconf.h" | ||
18 | #include "../../include/linux/license.h" | 19 | #include "../../include/linux/license.h" |
19 | 20 | ||
21 | /* Some toolchains use a `_' prefix for all user symbols. */ | ||
22 | #ifdef CONFIG_SYMBOL_PREFIX | ||
23 | #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX | ||
24 | #else | ||
25 | #define MODULE_SYMBOL_PREFIX "" | ||
26 | #endif | ||
27 | |||
28 | |||
20 | /* Are we using CONFIG_MODVERSIONS? */ | 29 | /* Are we using CONFIG_MODVERSIONS? */ |
21 | int modversions = 0; | 30 | int modversions = 0; |
22 | /* Warn about undefined symbols? (do so if we have vmlinux) */ | 31 | /* Warn about undefined symbols? (do so if we have vmlinux) */ |
@@ -451,8 +460,6 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
451 | info->export_unused_gpl_sec = i; | 460 | info->export_unused_gpl_sec = i; |
452 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | 461 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) |
453 | info->export_gpl_future_sec = i; | 462 | info->export_gpl_future_sec = i; |
454 | else if (strcmp(secname, "__markers_strings") == 0) | ||
455 | info->markers_strings_sec = i; | ||
456 | 463 | ||
457 | if (sechdrs[i].sh_type != SHT_SYMTAB) | 464 | if (sechdrs[i].sh_type != SHT_SYMTAB) |
458 | continue; | 465 | continue; |
@@ -515,7 +522,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
515 | break; | 522 | break; |
516 | case SHN_ABS: | 523 | case SHN_ABS: |
517 | /* CRC'd symbol */ | 524 | /* CRC'd symbol */ |
518 | if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { | 525 | if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { |
519 | crc = (unsigned int) sym->st_value; | 526 | crc = (unsigned int) sym->st_value; |
520 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, | 527 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, |
521 | export); | 528 | export); |
@@ -559,7 +566,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
559 | break; | 566 | break; |
560 | default: | 567 | default: |
561 | /* All exported symbols */ | 568 | /* All exported symbols */ |
562 | if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { | 569 | if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { |
563 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, | 570 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, |
564 | export); | 571 | export); |
565 | } | 572 | } |
@@ -1509,62 +1516,6 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
1509 | } | 1516 | } |
1510 | } | 1517 | } |
1511 | 1518 | ||
1512 | static void get_markers(struct elf_info *info, struct module *mod) | ||
1513 | { | ||
1514 | const Elf_Shdr *sh = &info->sechdrs[info->markers_strings_sec]; | ||
1515 | const char *strings = (const char *) info->hdr + sh->sh_offset; | ||
1516 | const Elf_Sym *sym, *first_sym, *last_sym; | ||
1517 | size_t n; | ||
1518 | |||
1519 | if (!info->markers_strings_sec) | ||
1520 | return; | ||
1521 | |||
1522 | /* | ||
1523 | * First count the strings. We look for all the symbols defined | ||
1524 | * in the __markers_strings section named __mstrtab_*. For | ||
1525 | * these local names, the compiler puts a random .NNN suffix on, | ||
1526 | * so the names don't correspond exactly. | ||
1527 | */ | ||
1528 | first_sym = last_sym = NULL; | ||
1529 | n = 0; | ||
1530 | for (sym = info->symtab_start; sym < info->symtab_stop; sym++) | ||
1531 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
1532 | sym->st_shndx == info->markers_strings_sec && | ||
1533 | !strncmp(info->strtab + sym->st_name, | ||
1534 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
1535 | if (first_sym == NULL) | ||
1536 | first_sym = sym; | ||
1537 | last_sym = sym; | ||
1538 | ++n; | ||
1539 | } | ||
1540 | |||
1541 | if (n == 0) | ||
1542 | return; | ||
1543 | |||
1544 | /* | ||
1545 | * Now collect each name and format into a line for the output. | ||
1546 | * Lines look like: | ||
1547 | * marker_name vmlinux marker %s format %d | ||
1548 | * The format string after the second \t can use whitespace. | ||
1549 | */ | ||
1550 | mod->markers = NOFAIL(malloc(sizeof mod->markers[0] * n)); | ||
1551 | mod->nmarkers = n; | ||
1552 | |||
1553 | n = 0; | ||
1554 | for (sym = first_sym; sym <= last_sym; sym++) | ||
1555 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
1556 | sym->st_shndx == info->markers_strings_sec && | ||
1557 | !strncmp(info->strtab + sym->st_name, | ||
1558 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
1559 | const char *name = strings + sym->st_value; | ||
1560 | const char *fmt = strchr(name, '\0') + 1; | ||
1561 | char *line = NULL; | ||
1562 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
1563 | NOFAIL(line); | ||
1564 | mod->markers[n++] = line; | ||
1565 | } | ||
1566 | } | ||
1567 | |||
1568 | static void read_symbols(char *modname) | 1519 | static void read_symbols(char *modname) |
1569 | { | 1520 | { |
1570 | const char *symname; | 1521 | const char *symname; |
@@ -1620,8 +1571,6 @@ static void read_symbols(char *modname) | |||
1620 | get_src_version(modname, mod->srcversion, | 1571 | get_src_version(modname, mod->srcversion, |
1621 | sizeof(mod->srcversion)-1); | 1572 | sizeof(mod->srcversion)-1); |
1622 | 1573 | ||
1623 | get_markers(&info, mod); | ||
1624 | |||
1625 | parse_elf_finish(&info); | 1574 | parse_elf_finish(&info); |
1626 | 1575 | ||
1627 | /* Our trick to get versioning for module struct etc. - it's | 1576 | /* Our trick to get versioning for module struct etc. - it's |
@@ -1976,96 +1925,6 @@ static void write_dump(const char *fname) | |||
1976 | write_if_changed(&buf, fname); | 1925 | write_if_changed(&buf, fname); |
1977 | } | 1926 | } |
1978 | 1927 | ||
1979 | static void add_marker(struct module *mod, const char *name, const char *fmt) | ||
1980 | { | ||
1981 | char *line = NULL; | ||
1982 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
1983 | NOFAIL(line); | ||
1984 | |||
1985 | mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) * | ||
1986 | sizeof mod->markers[0]))); | ||
1987 | mod->markers[mod->nmarkers++] = line; | ||
1988 | } | ||
1989 | |||
1990 | static void read_markers(const char *fname) | ||
1991 | { | ||
1992 | unsigned long size, pos = 0; | ||
1993 | void *file = grab_file(fname, &size); | ||
1994 | char *line; | ||
1995 | |||
1996 | if (!file) /* No old markers, silently ignore */ | ||
1997 | return; | ||
1998 | |||
1999 | while ((line = get_next_line(&pos, file, size))) { | ||
2000 | char *marker, *modname, *fmt; | ||
2001 | struct module *mod; | ||
2002 | |||
2003 | marker = line; | ||
2004 | modname = strchr(marker, '\t'); | ||
2005 | if (!modname) | ||
2006 | goto fail; | ||
2007 | *modname++ = '\0'; | ||
2008 | fmt = strchr(modname, '\t'); | ||
2009 | if (!fmt) | ||
2010 | goto fail; | ||
2011 | *fmt++ = '\0'; | ||
2012 | if (*marker == '\0' || *modname == '\0') | ||
2013 | goto fail; | ||
2014 | |||
2015 | mod = find_module(modname); | ||
2016 | if (!mod) { | ||
2017 | mod = new_module(modname); | ||
2018 | mod->skip = 1; | ||
2019 | } | ||
2020 | if (is_vmlinux(modname)) { | ||
2021 | have_vmlinux = 1; | ||
2022 | mod->skip = 0; | ||
2023 | } | ||
2024 | |||
2025 | if (!mod->skip) | ||
2026 | add_marker(mod, marker, fmt); | ||
2027 | } | ||
2028 | release_file(file, size); | ||
2029 | return; | ||
2030 | fail: | ||
2031 | fatal("parse error in markers list file\n"); | ||
2032 | } | ||
2033 | |||
2034 | static int compare_strings(const void *a, const void *b) | ||
2035 | { | ||
2036 | return strcmp(*(const char **) a, *(const char **) b); | ||
2037 | } | ||
2038 | |||
2039 | static void write_markers(const char *fname) | ||
2040 | { | ||
2041 | struct buffer buf = { }; | ||
2042 | struct module *mod; | ||
2043 | size_t i; | ||
2044 | |||
2045 | for (mod = modules; mod; mod = mod->next) | ||
2046 | if ((!external_module || !mod->skip) && mod->markers != NULL) { | ||
2047 | /* | ||
2048 | * Sort the strings so we can skip duplicates when | ||
2049 | * we write them out. | ||
2050 | */ | ||
2051 | qsort(mod->markers, mod->nmarkers, | ||
2052 | sizeof mod->markers[0], &compare_strings); | ||
2053 | for (i = 0; i < mod->nmarkers; ++i) { | ||
2054 | char *line = mod->markers[i]; | ||
2055 | buf_write(&buf, line, strlen(line)); | ||
2056 | while (i + 1 < mod->nmarkers && | ||
2057 | !strcmp(mod->markers[i], | ||
2058 | mod->markers[i + 1])) | ||
2059 | free(mod->markers[i++]); | ||
2060 | free(mod->markers[i]); | ||
2061 | } | ||
2062 | free(mod->markers); | ||
2063 | mod->markers = NULL; | ||
2064 | } | ||
2065 | |||
2066 | write_if_changed(&buf, fname); | ||
2067 | } | ||
2068 | |||
2069 | struct ext_sym_list { | 1928 | struct ext_sym_list { |
2070 | struct ext_sym_list *next; | 1929 | struct ext_sym_list *next; |
2071 | const char *file; | 1930 | const char *file; |
@@ -2077,8 +1936,6 @@ int main(int argc, char **argv) | |||
2077 | struct buffer buf = { }; | 1936 | struct buffer buf = { }; |
2078 | char *kernel_read = NULL, *module_read = NULL; | 1937 | char *kernel_read = NULL, *module_read = NULL; |
2079 | char *dump_write = NULL; | 1938 | char *dump_write = NULL; |
2080 | char *markers_read = NULL; | ||
2081 | char *markers_write = NULL; | ||
2082 | int opt; | 1939 | int opt; |
2083 | int err; | 1940 | int err; |
2084 | struct ext_sym_list *extsym_iter; | 1941 | struct ext_sym_list *extsym_iter; |
@@ -2122,12 +1979,6 @@ int main(int argc, char **argv) | |||
2122 | case 'w': | 1979 | case 'w': |
2123 | warn_unresolved = 1; | 1980 | warn_unresolved = 1; |
2124 | break; | 1981 | break; |
2125 | case 'M': | ||
2126 | markers_write = optarg; | ||
2127 | break; | ||
2128 | case 'K': | ||
2129 | markers_read = optarg; | ||
2130 | break; | ||
2131 | default: | 1982 | default: |
2132 | exit(1); | 1983 | exit(1); |
2133 | } | 1984 | } |
@@ -2182,11 +2033,5 @@ int main(int argc, char **argv) | |||
2182 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", | 2033 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", |
2183 | sec_mismatch_count); | 2034 | sec_mismatch_count); |
2184 | 2035 | ||
2185 | if (markers_read) | ||
2186 | read_markers(markers_read); | ||
2187 | |||
2188 | if (markers_write) | ||
2189 | write_markers(markers_write); | ||
2190 | |||
2191 | return err; | 2036 | return err; |
2192 | } | 2037 | } |
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 09f58e33d227..be987a44f250 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h | |||
@@ -112,8 +112,6 @@ struct module { | |||
112 | int has_init; | 112 | int has_init; |
113 | int has_cleanup; | 113 | int has_cleanup; |
114 | struct buffer dev_table_buf; | 114 | struct buffer dev_table_buf; |
115 | char **markers; | ||
116 | size_t nmarkers; | ||
117 | char srcversion[25]; | 115 | char srcversion[25]; |
118 | }; | 116 | }; |
119 | 117 | ||
@@ -128,7 +126,6 @@ struct elf_info { | |||
128 | Elf_Section export_gpl_sec; | 126 | Elf_Section export_gpl_sec; |
129 | Elf_Section export_unused_gpl_sec; | 127 | Elf_Section export_unused_gpl_sec; |
130 | Elf_Section export_gpl_future_sec; | 128 | Elf_Section export_gpl_future_sec; |
131 | Elf_Section markers_strings_sec; | ||
132 | const char *strtab; | 129 | const char *strtab; |
133 | char *modinfo; | 130 | char *modinfo; |
134 | unsigned int modinfo_len; | 131 | unsigned int modinfo_len; |
diff --git a/scripts/package/Makefile b/scripts/package/Makefile index f67cc885c807..62fcc3a7f4d3 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile | |||
@@ -77,9 +77,27 @@ clean-files += $(objtree)/binkernel.spec | |||
77 | 77 | ||
78 | # Deb target | 78 | # Deb target |
79 | # --------------------------------------------------------------------------- | 79 | # --------------------------------------------------------------------------- |
80 | quiet_cmd_builddeb = BUILDDEB | ||
81 | cmd_builddeb = set -e; \ | ||
82 | test `id -u` = 0 || \ | ||
83 | test -n "$(KBUILD_PKG_ROOTCMD)" || { \ | ||
84 | which fakeroot >/dev/null 2>&1 && \ | ||
85 | KBUILD_PKG_ROOTCMD="fakeroot -u"; \ | ||
86 | } || { \ | ||
87 | echo; \ | ||
88 | echo "builddeb must be run as root (or using fakeroot)."; \ | ||
89 | echo "KBUILD_PKG_ROOTCMD is unset and fakeroot not found."; \ | ||
90 | echo "Try setting KBUILD_PKG_ROOTCMD to a command to acquire"; \ | ||
91 | echo "root privileges (e.g., 'fakeroot -u' or 'sudo')."; \ | ||
92 | false; \ | ||
93 | } && \ | ||
94 | \ | ||
95 | $$KBUILD_PKG_ROOTCMD $(CONFIG_SHELL) \ | ||
96 | $(srctree)/scripts/package/builddeb | ||
97 | |||
80 | deb-pkg: FORCE | 98 | deb-pkg: FORCE |
81 | $(MAKE) KBUILD_SRC= | 99 | $(MAKE) KBUILD_SRC= |
82 | $(CONFIG_SHELL) $(srctree)/scripts/package/builddeb | 100 | $(call cmd,builddeb) |
83 | 101 | ||
84 | clean-dirs += $(objtree)/debian/ | 102 | clean-dirs += $(objtree)/debian/ |
85 | 103 | ||
diff --git a/scripts/package/buildtar b/scripts/package/buildtar index b1fd48db1640..51b2aa0acb82 100644 --- a/scripts/package/buildtar +++ b/scripts/package/buildtar | |||
@@ -101,7 +101,11 @@ esac | |||
101 | # | 101 | # |
102 | ( | 102 | ( |
103 | cd "${tmpdir}" | 103 | cd "${tmpdir}" |
104 | tar cf - . | ${compress} > "${tarball}${file_ext}" | 104 | opts= |
105 | if tar --owner=root --group=root --help >/dev/null 2>&1; then | ||
106 | opts="--owner=root --group=root" | ||
107 | fi | ||
108 | tar cf - . $opts | ${compress} > "${tarball}${file_ext}" | ||
105 | ) | 109 | ) |
106 | 110 | ||
107 | echo "Tarball successfully created in ${tarball}${file_ext}" | 111 | echo "Tarball successfully created in ${tarball}${file_ext}" |
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl index f0d14452632b..92f09fe9639e 100755 --- a/scripts/recordmcount.pl +++ b/scripts/recordmcount.pl | |||
@@ -113,13 +113,13 @@ $P =~ s@.*/@@g; | |||
113 | 113 | ||
114 | my $V = '0.1'; | 114 | my $V = '0.1'; |
115 | 115 | ||
116 | if ($#ARGV != 10) { | 116 | if ($#ARGV != 11) { |
117 | print "usage: $P arch bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; | 117 | print "usage: $P arch endian bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; |
118 | print "version: $V\n"; | 118 | print "version: $V\n"; |
119 | exit(1); | 119 | exit(1); |
120 | } | 120 | } |
121 | 121 | ||
122 | my ($arch, $bits, $objdump, $objcopy, $cc, | 122 | my ($arch, $endian, $bits, $objdump, $objcopy, $cc, |
123 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; | 123 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; |
124 | 124 | ||
125 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it | 125 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it |
@@ -295,6 +295,61 @@ if ($arch eq "x86_64") { | |||
295 | $ld .= " -m elf64_sparc"; | 295 | $ld .= " -m elf64_sparc"; |
296 | $cc .= " -m64"; | 296 | $cc .= " -m64"; |
297 | $objcopy .= " -O elf64-sparc"; | 297 | $objcopy .= " -O elf64-sparc"; |
298 | } elsif ($arch eq "mips") { | ||
299 | # To enable module support, we need to enable the -mlong-calls option | ||
300 | # of gcc for module, after using this option, we can not get the real | ||
301 | # offset of the calling to _mcount, but the offset of the lui | ||
302 | # instruction or the addiu one. herein, we record the address of the | ||
303 | # first one, and then we can replace this instruction by a branch | ||
304 | # instruction to jump over the profiling function to filter the | ||
305 | # indicated functions, or swith back to the lui instruction to trace | ||
306 | # them, which means dynamic tracing. | ||
307 | # | ||
308 | # c: 3c030000 lui v1,0x0 | ||
309 | # c: R_MIPS_HI16 _mcount | ||
310 | # c: R_MIPS_NONE *ABS* | ||
311 | # c: R_MIPS_NONE *ABS* | ||
312 | # 10: 64630000 daddiu v1,v1,0 | ||
313 | # 10: R_MIPS_LO16 _mcount | ||
314 | # 10: R_MIPS_NONE *ABS* | ||
315 | # 10: R_MIPS_NONE *ABS* | ||
316 | # 14: 03e0082d move at,ra | ||
317 | # 18: 0060f809 jalr v1 | ||
318 | # | ||
319 | # for the kernel: | ||
320 | # | ||
321 | # 10: 03e0082d move at,ra | ||
322 | # 14: 0c000000 jal 0 <loongson_halt> | ||
323 | # 14: R_MIPS_26 _mcount | ||
324 | # 14: R_MIPS_NONE *ABS* | ||
325 | # 14: R_MIPS_NONE *ABS* | ||
326 | # 18: 00020021 nop | ||
327 | if ($is_module eq "0") { | ||
328 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | ||
329 | } else { | ||
330 | $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$"; | ||
331 | } | ||
332 | $objdump .= " -Melf-trad".$endian."mips "; | ||
333 | |||
334 | if ($endian eq "big") { | ||
335 | $endian = " -EB "; | ||
336 | $ld .= " -melf".$bits."btsmip"; | ||
337 | } else { | ||
338 | $endian = " -EL "; | ||
339 | $ld .= " -melf".$bits."ltsmip"; | ||
340 | } | ||
341 | |||
342 | $cc .= " -mno-abicalls -fno-pic -mabi=" . $bits . $endian; | ||
343 | $ld .= $endian; | ||
344 | |||
345 | if ($bits == 64) { | ||
346 | $function_regex = | ||
347 | "^([0-9a-fA-F]+)\\s+<(.|[^\$]L.*?|\$[^L].*?|[^\$][^L].*?)>:"; | ||
348 | $type = ".dword"; | ||
349 | } | ||
350 | } elsif ($arch eq "microblaze") { | ||
351 | # Microblaze calls '_mcount' instead of plain 'mcount'. | ||
352 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | ||
298 | } else { | 353 | } else { |
299 | die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; | 354 | die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; |
300 | } | 355 | } |
diff --git a/scripts/tags.sh b/scripts/tags.sh index d52f7a01557c..1a0c44d7c4a7 100755 --- a/scripts/tags.sh +++ b/scripts/tags.sh | |||
@@ -89,7 +89,13 @@ all_defconfigs() | |||
89 | 89 | ||
90 | docscope() | 90 | docscope() |
91 | { | 91 | { |
92 | (echo \-k; echo \-q; all_sources) > cscope.files | 92 | # always use absolute paths for cscope, as recommended by cscope |
93 | # upstream | ||
94 | case "$tree" in | ||
95 | /*) ;; | ||
96 | *) tree=$PWD/$tree ;; | ||
97 | esac | ||
98 | (cd /; echo \-k; echo \-q; all_sources) > cscope.files | ||
93 | cscope -b -f cscope.out | 99 | cscope -b -f cscope.out |
94 | } | 100 | } |
95 | 101 | ||
diff --git a/scripts/unifdef.c b/scripts/unifdef.c index 30d459fb0709..44d39785e50d 100644 --- a/scripts/unifdef.c +++ b/scripts/unifdef.c | |||
@@ -1,13 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2002 - 2005 Tony Finch <dot@dotat.at>. All rights reserved. | 2 | * Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at> |
3 | * | ||
4 | * This code is derived from software contributed to Berkeley by Dave Yost. | ||
5 | * It was rewritten to support ANSI C by Tony Finch. The original version of | ||
6 | * unifdef carried the following copyright notice. None of its code remains | ||
7 | * in this version (though some of the names remain). | ||
8 | * | ||
9 | * Copyright (c) 1985, 1993 | ||
10 | * The Regents of the University of California. All rights reserved. | ||
11 | * | 3 | * |
12 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
@@ -31,23 +23,20 @@ | |||
31 | * SUCH DAMAGE. | 23 | * SUCH DAMAGE. |
32 | */ | 24 | */ |
33 | 25 | ||
34 | #include <sys/cdefs.h> | 26 | /* |
27 | * This code was derived from software contributed to Berkeley by Dave Yost. | ||
28 | * It was rewritten to support ANSI C by Tony Finch. The original version | ||
29 | * of unifdef carried the 4-clause BSD copyright licence. None of its code | ||
30 | * remains in this version (though some of the names remain) so it now | ||
31 | * carries a more liberal licence. | ||
32 | * | ||
33 | * The latest version is available from http://dotat.at/prog/unifdef | ||
34 | */ | ||
35 | 35 | ||
36 | #ifndef lint | 36 | static const char * const copyright[] = { |
37 | #if 0 | 37 | "@(#) Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at>\n", |
38 | static const char copyright[] = | 38 | "$dotat: unifdef/unifdef.c,v 1.190 2009/11/27 17:21:26 fanf2 Exp $", |
39 | "@(#) Copyright (c) 1985, 1993\n\ | 39 | }; |
40 | The Regents of the University of California. All rights reserved.\n"; | ||
41 | #endif | ||
42 | #ifdef __IDSTRING | ||
43 | __IDSTRING(Berkeley, "@(#)unifdef.c 8.1 (Berkeley) 6/6/93"); | ||
44 | __IDSTRING(NetBSD, "$NetBSD: unifdef.c,v 1.8 2000/07/03 02:51:36 matt Exp $"); | ||
45 | __IDSTRING(dotat, "$dotat: things/unifdef.c,v 1.171 2005/03/08 12:38:48 fanf2 Exp $"); | ||
46 | #endif | ||
47 | #endif /* not lint */ | ||
48 | #ifdef __FBSDID | ||
49 | __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05/21 09:55:09 ru Exp $"); | ||
50 | #endif | ||
51 | 40 | ||
52 | /* | 41 | /* |
53 | * unifdef - remove ifdef'ed lines | 42 | * unifdef - remove ifdef'ed lines |
@@ -72,8 +61,6 @@ __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05 | |||
72 | #include <string.h> | 61 | #include <string.h> |
73 | #include <unistd.h> | 62 | #include <unistd.h> |
74 | 63 | ||
75 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
76 | |||
77 | /* types of input lines: */ | 64 | /* types of input lines: */ |
78 | typedef enum { | 65 | typedef enum { |
79 | LT_TRUEI, /* a true #if with ignore flag */ | 66 | LT_TRUEI, /* a true #if with ignore flag */ |
@@ -90,6 +77,7 @@ typedef enum { | |||
90 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, | 77 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, |
91 | LT_PLAIN, /* ordinary line */ | 78 | LT_PLAIN, /* ordinary line */ |
92 | LT_EOF, /* end of file */ | 79 | LT_EOF, /* end of file */ |
80 | LT_ERROR, /* unevaluable #if */ | ||
93 | LT_COUNT | 81 | LT_COUNT |
94 | } Linetype; | 82 | } Linetype; |
95 | 83 | ||
@@ -100,7 +88,7 @@ static char const * const linetype_name[] = { | |||
100 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", | 88 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", |
101 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", | 89 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", |
102 | "DODGY ELSE", "DODGY ENDIF", | 90 | "DODGY ELSE", "DODGY ENDIF", |
103 | "PLAIN", "EOF" | 91 | "PLAIN", "EOF", "ERROR" |
104 | }; | 92 | }; |
105 | 93 | ||
106 | /* state of #if processing */ | 94 | /* state of #if processing */ |
@@ -168,11 +156,13 @@ static char const * const linestate_name[] = { | |||
168 | * Globals. | 156 | * Globals. |
169 | */ | 157 | */ |
170 | 158 | ||
159 | static bool compblank; /* -B: compress blank lines */ | ||
160 | static bool lnblank; /* -b: blank deleted lines */ | ||
171 | static bool complement; /* -c: do the complement */ | 161 | static bool complement; /* -c: do the complement */ |
172 | static bool debugging; /* -d: debugging reports */ | 162 | static bool debugging; /* -d: debugging reports */ |
173 | static bool iocccok; /* -e: fewer IOCCC errors */ | 163 | static bool iocccok; /* -e: fewer IOCCC errors */ |
164 | static bool strictlogic; /* -K: keep ambiguous #ifs */ | ||
174 | static bool killconsts; /* -k: eval constant #ifs */ | 165 | static bool killconsts; /* -k: eval constant #ifs */ |
175 | static bool lnblank; /* -l: blank deleted lines */ | ||
176 | static bool lnnum; /* -n: add #line directives */ | 166 | static bool lnnum; /* -n: add #line directives */ |
177 | static bool symlist; /* -s: output symbol list */ | 167 | static bool symlist; /* -s: output symbol list */ |
178 | static bool text; /* -t: this is a text file */ | 168 | static bool text; /* -t: this is a text file */ |
@@ -196,7 +186,9 @@ static bool ignoring[MAXDEPTH]; /* ignore comments state */ | |||
196 | static int stifline[MAXDEPTH]; /* start of current #if */ | 186 | static int stifline[MAXDEPTH]; /* start of current #if */ |
197 | static int depth; /* current #if nesting */ | 187 | static int depth; /* current #if nesting */ |
198 | static int delcount; /* count of deleted lines */ | 188 | static int delcount; /* count of deleted lines */ |
199 | static bool keepthis; /* don't delete constant #if */ | 189 | static unsigned blankcount; /* count of blank lines */ |
190 | static unsigned blankmax; /* maximum recent blankcount */ | ||
191 | static bool constexpr; /* constant #if expression */ | ||
200 | 192 | ||
201 | static int exitstat; /* program exit status */ | 193 | static int exitstat; /* program exit status */ |
202 | 194 | ||
@@ -206,13 +198,14 @@ static void done(void); | |||
206 | static void error(const char *); | 198 | static void error(const char *); |
207 | static int findsym(const char *); | 199 | static int findsym(const char *); |
208 | static void flushline(bool); | 200 | static void flushline(bool); |
209 | static Linetype get_line(void); | 201 | static Linetype parseline(void); |
210 | static Linetype ifeval(const char **); | 202 | static Linetype ifeval(const char **); |
211 | static void ignoreoff(void); | 203 | static void ignoreoff(void); |
212 | static void ignoreon(void); | 204 | static void ignoreon(void); |
213 | static void keywordedit(const char *); | 205 | static void keywordedit(const char *); |
214 | static void nest(void); | 206 | static void nest(void); |
215 | static void process(void); | 207 | static void process(void); |
208 | static const char *skipargs(const char *); | ||
216 | static const char *skipcomment(const char *); | 209 | static const char *skipcomment(const char *); |
217 | static const char *skipsym(const char *); | 210 | static const char *skipsym(const char *); |
218 | static void state(Ifstate); | 211 | static void state(Ifstate); |
@@ -220,7 +213,7 @@ static int strlcmp(const char *, const char *, size_t); | |||
220 | static void unnest(void); | 213 | static void unnest(void); |
221 | static void usage(void); | 214 | static void usage(void); |
222 | 215 | ||
223 | #define endsym(c) (!isalpha((unsigned char)c) && !isdigit((unsigned char)c) && c != '_') | 216 | #define endsym(c) (!isalnum((unsigned char)c) && c != '_') |
224 | 217 | ||
225 | /* | 218 | /* |
226 | * The main program. | 219 | * The main program. |
@@ -230,7 +223,7 @@ main(int argc, char *argv[]) | |||
230 | { | 223 | { |
231 | int opt; | 224 | int opt; |
232 | 225 | ||
233 | while ((opt = getopt(argc, argv, "i:D:U:I:cdeklnst")) != -1) | 226 | while ((opt = getopt(argc, argv, "i:D:U:I:BbcdeKklnst")) != -1) |
234 | switch (opt) { | 227 | switch (opt) { |
235 | case 'i': /* treat stuff controlled by these symbols as text */ | 228 | case 'i': /* treat stuff controlled by these symbols as text */ |
236 | /* | 229 | /* |
@@ -255,6 +248,13 @@ main(int argc, char *argv[]) | |||
255 | case 'I': | 248 | case 'I': |
256 | /* no-op for compatibility with cpp */ | 249 | /* no-op for compatibility with cpp */ |
257 | break; | 250 | break; |
251 | case 'B': /* compress blank lines around removed section */ | ||
252 | compblank = true; | ||
253 | break; | ||
254 | case 'b': /* blank deleted lines instead of omitting them */ | ||
255 | case 'l': /* backwards compatibility */ | ||
256 | lnblank = true; | ||
257 | break; | ||
258 | case 'c': /* treat -D as -U and vice versa */ | 258 | case 'c': /* treat -D as -U and vice versa */ |
259 | complement = true; | 259 | complement = true; |
260 | break; | 260 | break; |
@@ -264,12 +264,12 @@ main(int argc, char *argv[]) | |||
264 | case 'e': /* fewer errors from dodgy lines */ | 264 | case 'e': /* fewer errors from dodgy lines */ |
265 | iocccok = true; | 265 | iocccok = true; |
266 | break; | 266 | break; |
267 | case 'K': /* keep ambiguous #ifs */ | ||
268 | strictlogic = true; | ||
269 | break; | ||
267 | case 'k': /* process constant #ifs */ | 270 | case 'k': /* process constant #ifs */ |
268 | killconsts = true; | 271 | killconsts = true; |
269 | break; | 272 | break; |
270 | case 'l': /* blank deleted lines instead of omitting them */ | ||
271 | lnblank = true; | ||
272 | break; | ||
273 | case 'n': /* add #line directive after deleted lines */ | 273 | case 'n': /* add #line directive after deleted lines */ |
274 | lnnum = true; | 274 | lnnum = true; |
275 | break; | 275 | break; |
@@ -284,6 +284,8 @@ main(int argc, char *argv[]) | |||
284 | } | 284 | } |
285 | argc -= optind; | 285 | argc -= optind; |
286 | argv += optind; | 286 | argv += optind; |
287 | if (compblank && lnblank) | ||
288 | errx(2, "-B and -b are mutually exclusive"); | ||
287 | if (argc > 1) { | 289 | if (argc > 1) { |
288 | errx(2, "can only do one file"); | 290 | errx(2, "can only do one file"); |
289 | } else if (argc == 1 && strcmp(*argv, "-") != 0) { | 291 | } else if (argc == 1 && strcmp(*argv, "-") != 0) { |
@@ -302,7 +304,7 @@ main(int argc, char *argv[]) | |||
302 | static void | 304 | static void |
303 | usage(void) | 305 | usage(void) |
304 | { | 306 | { |
305 | fprintf(stderr, "usage: unifdef [-cdeklnst] [-Ipath]" | 307 | fprintf(stderr, "usage: unifdef [-BbcdeKknst] [-Ipath]" |
306 | " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); | 308 | " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); |
307 | exit(2); | 309 | exit(2); |
308 | } | 310 | } |
@@ -383,46 +385,46 @@ static state_fn * const trans_table[IS_COUNT][LT_COUNT] = { | |||
383 | /* IS_OUTSIDE */ | 385 | /* IS_OUTSIDE */ |
384 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, | 386 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, |
385 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, | 387 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, |
386 | print, done }, | 388 | print, done, abort }, |
387 | /* IS_FALSE_PREFIX */ | 389 | /* IS_FALSE_PREFIX */ |
388 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, | 390 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, |
389 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, | 391 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, |
390 | drop, Eeof }, | 392 | drop, Eeof, abort }, |
391 | /* IS_TRUE_PREFIX */ | 393 | /* IS_TRUE_PREFIX */ |
392 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, | 394 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, |
393 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | 395 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, |
394 | print, Eeof }, | 396 | print, Eeof, abort }, |
395 | /* IS_PASS_MIDDLE */ | 397 | /* IS_PASS_MIDDLE */ |
396 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, | 398 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, |
397 | Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, | 399 | Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, |
398 | print, Eeof }, | 400 | print, Eeof, abort }, |
399 | /* IS_FALSE_MIDDLE */ | 401 | /* IS_FALSE_MIDDLE */ |
400 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, | 402 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, |
401 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | 403 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, |
402 | drop, Eeof }, | 404 | drop, Eeof, abort }, |
403 | /* IS_TRUE_MIDDLE */ | 405 | /* IS_TRUE_MIDDLE */ |
404 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, | 406 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, |
405 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, | 407 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, |
406 | print, Eeof }, | 408 | print, Eeof, abort }, |
407 | /* IS_PASS_ELSE */ | 409 | /* IS_PASS_ELSE */ |
408 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, | 410 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, |
409 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, | 411 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, |
410 | print, Eeof }, | 412 | print, Eeof, abort }, |
411 | /* IS_FALSE_ELSE */ | 413 | /* IS_FALSE_ELSE */ |
412 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, | 414 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, |
413 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, | 415 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, |
414 | drop, Eeof }, | 416 | drop, Eeof, abort }, |
415 | /* IS_TRUE_ELSE */ | 417 | /* IS_TRUE_ELSE */ |
416 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, | 418 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, |
417 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, | 419 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, |
418 | print, Eeof }, | 420 | print, Eeof, abort }, |
419 | /* IS_FALSE_TRAILER */ | 421 | /* IS_FALSE_TRAILER */ |
420 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, | 422 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, |
421 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, | 423 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, |
422 | drop, Eeof } | 424 | drop, Eeof, abort } |
423 | /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF | 425 | /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF |
424 | TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) | 426 | TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) |
425 | PLAIN EOF */ | 427 | PLAIN EOF ERROR */ |
426 | }; | 428 | }; |
427 | 429 | ||
428 | /* | 430 | /* |
@@ -463,9 +465,11 @@ keywordedit(const char *replacement) | |||
463 | static void | 465 | static void |
464 | nest(void) | 466 | nest(void) |
465 | { | 467 | { |
466 | depth += 1; | 468 | if (depth > MAXDEPTH-1) |
467 | if (depth >= MAXDEPTH) | 469 | abort(); /* bug */ |
470 | if (depth == MAXDEPTH-1) | ||
468 | error("Too many levels of nesting"); | 471 | error("Too many levels of nesting"); |
472 | depth += 1; | ||
469 | stifline[depth] = linenum; | 473 | stifline[depth] = linenum; |
470 | } | 474 | } |
471 | static void | 475 | static void |
@@ -490,15 +494,23 @@ flushline(bool keep) | |||
490 | if (symlist) | 494 | if (symlist) |
491 | return; | 495 | return; |
492 | if (keep ^ complement) { | 496 | if (keep ^ complement) { |
493 | if (lnnum && delcount > 0) | 497 | bool blankline = tline[strspn(tline, " \t\n")] == '\0'; |
494 | printf("#line %d\n", linenum); | 498 | if (blankline && compblank && blankcount != blankmax) { |
495 | fputs(tline, stdout); | 499 | delcount += 1; |
496 | delcount = 0; | 500 | blankcount += 1; |
501 | } else { | ||
502 | if (lnnum && delcount > 0) | ||
503 | printf("#line %d\n", linenum); | ||
504 | fputs(tline, stdout); | ||
505 | delcount = 0; | ||
506 | blankmax = blankcount = blankline ? blankcount + 1 : 0; | ||
507 | } | ||
497 | } else { | 508 | } else { |
498 | if (lnblank) | 509 | if (lnblank) |
499 | putc('\n', stdout); | 510 | putc('\n', stdout); |
500 | exitstat = 1; | 511 | exitstat = 1; |
501 | delcount += 1; | 512 | delcount += 1; |
513 | blankcount = 0; | ||
502 | } | 514 | } |
503 | } | 515 | } |
504 | 516 | ||
@@ -510,9 +522,12 @@ process(void) | |||
510 | { | 522 | { |
511 | Linetype lineval; | 523 | Linetype lineval; |
512 | 524 | ||
525 | /* When compressing blank lines, act as if the file | ||
526 | is preceded by a large number of blank lines. */ | ||
527 | blankmax = blankcount = 1000; | ||
513 | for (;;) { | 528 | for (;;) { |
514 | linenum++; | 529 | linenum++; |
515 | lineval = get_line(); | 530 | lineval = parseline(); |
516 | trans_table[ifstate[depth]][lineval](); | 531 | trans_table[ifstate[depth]][lineval](); |
517 | debug("process %s -> %s depth %d", | 532 | debug("process %s -> %s depth %d", |
518 | linetype_name[lineval], | 533 | linetype_name[lineval], |
@@ -526,7 +541,7 @@ process(void) | |||
526 | * help from skipcomment(). | 541 | * help from skipcomment(). |
527 | */ | 542 | */ |
528 | static Linetype | 543 | static Linetype |
529 | get_line(void) | 544 | parseline(void) |
530 | { | 545 | { |
531 | const char *cp; | 546 | const char *cp; |
532 | int cursym; | 547 | int cursym; |
@@ -595,9 +610,21 @@ get_line(void) | |||
595 | if (incomment) | 610 | if (incomment) |
596 | linestate = LS_DIRTY; | 611 | linestate = LS_DIRTY; |
597 | } | 612 | } |
598 | /* skipcomment should have changed the state */ | 613 | /* skipcomment normally changes the state, except |
599 | if (linestate == LS_HASH) | 614 | if the last line of the file lacks a newline, or |
600 | abort(); /* bug */ | 615 | if there is too much whitespace in a directive */ |
616 | if (linestate == LS_HASH) { | ||
617 | size_t len = cp - tline; | ||
618 | if (fgets(tline + len, MAXLINE - len, input) == NULL) { | ||
619 | /* append the missing newline */ | ||
620 | tline[len+0] = '\n'; | ||
621 | tline[len+1] = '\0'; | ||
622 | cp++; | ||
623 | linestate = LS_START; | ||
624 | } else { | ||
625 | linestate = LS_DIRTY; | ||
626 | } | ||
627 | } | ||
601 | } | 628 | } |
602 | if (linestate == LS_DIRTY) { | 629 | if (linestate == LS_DIRTY) { |
603 | while (*cp != '\0') | 630 | while (*cp != '\0') |
@@ -610,17 +637,40 @@ get_line(void) | |||
610 | 637 | ||
611 | /* | 638 | /* |
612 | * These are the binary operators that are supported by the expression | 639 | * These are the binary operators that are supported by the expression |
613 | * evaluator. Note that if support for division is added then we also | 640 | * evaluator. |
614 | * need short-circuiting booleans because of divide-by-zero. | ||
615 | */ | 641 | */ |
616 | static int op_lt(int a, int b) { return (a < b); } | 642 | static Linetype op_strict(int *p, int v, Linetype at, Linetype bt) { |
617 | static int op_gt(int a, int b) { return (a > b); } | 643 | if(at == LT_IF || bt == LT_IF) return (LT_IF); |
618 | static int op_le(int a, int b) { return (a <= b); } | 644 | return (*p = v, v ? LT_TRUE : LT_FALSE); |
619 | static int op_ge(int a, int b) { return (a >= b); } | 645 | } |
620 | static int op_eq(int a, int b) { return (a == b); } | 646 | static Linetype op_lt(int *p, Linetype at, int a, Linetype bt, int b) { |
621 | static int op_ne(int a, int b) { return (a != b); } | 647 | return op_strict(p, a < b, at, bt); |
622 | static int op_or(int a, int b) { return (a || b); } | 648 | } |
623 | static int op_and(int a, int b) { return (a && b); } | 649 | static Linetype op_gt(int *p, Linetype at, int a, Linetype bt, int b) { |
650 | return op_strict(p, a > b, at, bt); | ||
651 | } | ||
652 | static Linetype op_le(int *p, Linetype at, int a, Linetype bt, int b) { | ||
653 | return op_strict(p, a <= b, at, bt); | ||
654 | } | ||
655 | static Linetype op_ge(int *p, Linetype at, int a, Linetype bt, int b) { | ||
656 | return op_strict(p, a >= b, at, bt); | ||
657 | } | ||
658 | static Linetype op_eq(int *p, Linetype at, int a, Linetype bt, int b) { | ||
659 | return op_strict(p, a == b, at, bt); | ||
660 | } | ||
661 | static Linetype op_ne(int *p, Linetype at, int a, Linetype bt, int b) { | ||
662 | return op_strict(p, a != b, at, bt); | ||
663 | } | ||
664 | static Linetype op_or(int *p, Linetype at, int a, Linetype bt, int b) { | ||
665 | if (!strictlogic && (at == LT_TRUE || bt == LT_TRUE)) | ||
666 | return (*p = 1, LT_TRUE); | ||
667 | return op_strict(p, a || b, at, bt); | ||
668 | } | ||
669 | static Linetype op_and(int *p, Linetype at, int a, Linetype bt, int b) { | ||
670 | if (!strictlogic && (at == LT_FALSE || bt == LT_FALSE)) | ||
671 | return (*p = 0, LT_FALSE); | ||
672 | return op_strict(p, a && b, at, bt); | ||
673 | } | ||
624 | 674 | ||
625 | /* | 675 | /* |
626 | * An evaluation function takes three arguments, as follows: (1) a pointer to | 676 | * An evaluation function takes three arguments, as follows: (1) a pointer to |
@@ -629,8 +679,8 @@ static int op_and(int a, int b) { return (a && b); } | |||
629 | * value of the expression; and (3) a pointer to a char* that points to the | 679 | * value of the expression; and (3) a pointer to a char* that points to the |
630 | * expression to be evaluated and that is updated to the end of the expression | 680 | * expression to be evaluated and that is updated to the end of the expression |
631 | * when evaluation is complete. The function returns LT_FALSE if the value of | 681 | * when evaluation is complete. The function returns LT_FALSE if the value of |
632 | * the expression is zero, LT_TRUE if it is non-zero, or LT_IF if the | 682 | * the expression is zero, LT_TRUE if it is non-zero, LT_IF if the expression |
633 | * expression could not be evaluated. | 683 | * depends on an unknown symbol, or LT_ERROR if there is a parse failure. |
634 | */ | 684 | */ |
635 | struct ops; | 685 | struct ops; |
636 | 686 | ||
@@ -649,7 +699,7 @@ static const struct ops { | |||
649 | eval_fn *inner; | 699 | eval_fn *inner; |
650 | struct op { | 700 | struct op { |
651 | const char *str; | 701 | const char *str; |
652 | int (*fn)(int, int); | 702 | Linetype (*fn)(int *, Linetype, int, Linetype, int); |
653 | } op[5]; | 703 | } op[5]; |
654 | } eval_ops[] = { | 704 | } eval_ops[] = { |
655 | { eval_table, { { "||", op_or } } }, | 705 | { eval_table, { { "||", op_or } } }, |
@@ -664,8 +714,8 @@ static const struct ops { | |||
664 | 714 | ||
665 | /* | 715 | /* |
666 | * Function for evaluating the innermost parts of expressions, | 716 | * Function for evaluating the innermost parts of expressions, |
667 | * viz. !expr (expr) defined(symbol) symbol number | 717 | * viz. !expr (expr) number defined(symbol) symbol |
668 | * We reset the keepthis flag when we find a non-constant subexpression. | 718 | * We reset the constexpr flag in the last two cases. |
669 | */ | 719 | */ |
670 | static Linetype | 720 | static Linetype |
671 | eval_unary(const struct ops *ops, int *valp, const char **cpp) | 721 | eval_unary(const struct ops *ops, int *valp, const char **cpp) |
@@ -673,68 +723,83 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp) | |||
673 | const char *cp; | 723 | const char *cp; |
674 | char *ep; | 724 | char *ep; |
675 | int sym; | 725 | int sym; |
726 | bool defparen; | ||
727 | Linetype lt; | ||
676 | 728 | ||
677 | cp = skipcomment(*cpp); | 729 | cp = skipcomment(*cpp); |
678 | if (*cp == '!') { | 730 | if (*cp == '!') { |
679 | debug("eval%d !", ops - eval_ops); | 731 | debug("eval%d !", ops - eval_ops); |
680 | cp++; | 732 | cp++; |
681 | if (eval_unary(ops, valp, &cp) == LT_IF) { | 733 | lt = eval_unary(ops, valp, &cp); |
682 | *cpp = cp; | 734 | if (lt == LT_ERROR) |
683 | return (LT_IF); | 735 | return (LT_ERROR); |
736 | if (lt != LT_IF) { | ||
737 | *valp = !*valp; | ||
738 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
684 | } | 739 | } |
685 | *valp = !*valp; | ||
686 | } else if (*cp == '(') { | 740 | } else if (*cp == '(') { |
687 | cp++; | 741 | cp++; |
688 | debug("eval%d (", ops - eval_ops); | 742 | debug("eval%d (", ops - eval_ops); |
689 | if (eval_table(eval_ops, valp, &cp) == LT_IF) | 743 | lt = eval_table(eval_ops, valp, &cp); |
690 | return (LT_IF); | 744 | if (lt == LT_ERROR) |
745 | return (LT_ERROR); | ||
691 | cp = skipcomment(cp); | 746 | cp = skipcomment(cp); |
692 | if (*cp++ != ')') | 747 | if (*cp++ != ')') |
693 | return (LT_IF); | 748 | return (LT_ERROR); |
694 | } else if (isdigit((unsigned char)*cp)) { | 749 | } else if (isdigit((unsigned char)*cp)) { |
695 | debug("eval%d number", ops - eval_ops); | 750 | debug("eval%d number", ops - eval_ops); |
696 | *valp = strtol(cp, &ep, 0); | 751 | *valp = strtol(cp, &ep, 0); |
752 | if (ep == cp) | ||
753 | return (LT_ERROR); | ||
754 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
697 | cp = skipsym(cp); | 755 | cp = skipsym(cp); |
698 | } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { | 756 | } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { |
699 | cp = skipcomment(cp+7); | 757 | cp = skipcomment(cp+7); |
700 | debug("eval%d defined", ops - eval_ops); | 758 | debug("eval%d defined", ops - eval_ops); |
701 | if (*cp++ != '(') | 759 | if (*cp == '(') { |
702 | return (LT_IF); | 760 | cp = skipcomment(cp+1); |
703 | cp = skipcomment(cp); | 761 | defparen = true; |
762 | } else { | ||
763 | defparen = false; | ||
764 | } | ||
704 | sym = findsym(cp); | 765 | sym = findsym(cp); |
705 | cp = skipsym(cp); | 766 | if (sym < 0) { |
706 | cp = skipcomment(cp); | 767 | lt = LT_IF; |
707 | if (*cp++ != ')') | 768 | } else { |
708 | return (LT_IF); | ||
709 | if (sym >= 0) | ||
710 | *valp = (value[sym] != NULL); | 769 | *valp = (value[sym] != NULL); |
711 | else { | 770 | lt = *valp ? LT_TRUE : LT_FALSE; |
712 | *cpp = cp; | ||
713 | return (LT_IF); | ||
714 | } | 771 | } |
715 | keepthis = false; | 772 | cp = skipsym(cp); |
773 | cp = skipcomment(cp); | ||
774 | if (defparen && *cp++ != ')') | ||
775 | return (LT_ERROR); | ||
776 | constexpr = false; | ||
716 | } else if (!endsym(*cp)) { | 777 | } else if (!endsym(*cp)) { |
717 | debug("eval%d symbol", ops - eval_ops); | 778 | debug("eval%d symbol", ops - eval_ops); |
718 | sym = findsym(cp); | 779 | sym = findsym(cp); |
719 | if (sym < 0) | 780 | cp = skipsym(cp); |
720 | return (LT_IF); | 781 | if (sym < 0) { |
721 | if (value[sym] == NULL) | 782 | lt = LT_IF; |
783 | cp = skipargs(cp); | ||
784 | } else if (value[sym] == NULL) { | ||
722 | *valp = 0; | 785 | *valp = 0; |
723 | else { | 786 | lt = LT_FALSE; |
787 | } else { | ||
724 | *valp = strtol(value[sym], &ep, 0); | 788 | *valp = strtol(value[sym], &ep, 0); |
725 | if (*ep != '\0' || ep == value[sym]) | 789 | if (*ep != '\0' || ep == value[sym]) |
726 | return (LT_IF); | 790 | return (LT_ERROR); |
791 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
792 | cp = skipargs(cp); | ||
727 | } | 793 | } |
728 | cp = skipsym(cp); | 794 | constexpr = false; |
729 | keepthis = false; | ||
730 | } else { | 795 | } else { |
731 | debug("eval%d bad expr", ops - eval_ops); | 796 | debug("eval%d bad expr", ops - eval_ops); |
732 | return (LT_IF); | 797 | return (LT_ERROR); |
733 | } | 798 | } |
734 | 799 | ||
735 | *cpp = cp; | 800 | *cpp = cp; |
736 | debug("eval%d = %d", ops - eval_ops, *valp); | 801 | debug("eval%d = %d", ops - eval_ops, *valp); |
737 | return (*valp ? LT_TRUE : LT_FALSE); | 802 | return (lt); |
738 | } | 803 | } |
739 | 804 | ||
740 | /* | 805 | /* |
@@ -746,11 +811,13 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
746 | const struct op *op; | 811 | const struct op *op; |
747 | const char *cp; | 812 | const char *cp; |
748 | int val; | 813 | int val; |
749 | Linetype lhs, rhs; | 814 | Linetype lt, rt; |
750 | 815 | ||
751 | debug("eval%d", ops - eval_ops); | 816 | debug("eval%d", ops - eval_ops); |
752 | cp = *cpp; | 817 | cp = *cpp; |
753 | lhs = ops->inner(ops+1, valp, &cp); | 818 | lt = ops->inner(ops+1, valp, &cp); |
819 | if (lt == LT_ERROR) | ||
820 | return (LT_ERROR); | ||
754 | for (;;) { | 821 | for (;;) { |
755 | cp = skipcomment(cp); | 822 | cp = skipcomment(cp); |
756 | for (op = ops->op; op->str != NULL; op++) | 823 | for (op = ops->op; op->str != NULL; op++) |
@@ -760,32 +827,16 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
760 | break; | 827 | break; |
761 | cp += strlen(op->str); | 828 | cp += strlen(op->str); |
762 | debug("eval%d %s", ops - eval_ops, op->str); | 829 | debug("eval%d %s", ops - eval_ops, op->str); |
763 | rhs = ops->inner(ops+1, &val, &cp); | 830 | rt = ops->inner(ops+1, &val, &cp); |
764 | if (op->fn == op_and && (lhs == LT_FALSE || rhs == LT_FALSE)) { | 831 | if (rt == LT_ERROR) |
765 | debug("eval%d: and always false", ops - eval_ops); | 832 | return (LT_ERROR); |
766 | if (lhs == LT_IF) | 833 | lt = op->fn(valp, lt, *valp, rt, val); |
767 | *valp = val; | ||
768 | lhs = LT_FALSE; | ||
769 | continue; | ||
770 | } | ||
771 | if (op->fn == op_or && (lhs == LT_TRUE || rhs == LT_TRUE)) { | ||
772 | debug("eval%d: or always true", ops - eval_ops); | ||
773 | if (lhs == LT_IF) | ||
774 | *valp = val; | ||
775 | lhs = LT_TRUE; | ||
776 | continue; | ||
777 | } | ||
778 | if (rhs == LT_IF) | ||
779 | lhs = LT_IF; | ||
780 | if (lhs != LT_IF) | ||
781 | *valp = op->fn(*valp, val); | ||
782 | } | 834 | } |
783 | 835 | ||
784 | *cpp = cp; | 836 | *cpp = cp; |
785 | debug("eval%d = %d", ops - eval_ops, *valp); | 837 | debug("eval%d = %d", ops - eval_ops, *valp); |
786 | if (lhs != LT_IF) | 838 | debug("eval%d lt = %s", ops - eval_ops, linetype_name[lt]); |
787 | lhs = (*valp ? LT_TRUE : LT_FALSE); | 839 | return (lt); |
788 | return lhs; | ||
789 | } | 840 | } |
790 | 841 | ||
791 | /* | 842 | /* |
@@ -796,17 +847,14 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
796 | static Linetype | 847 | static Linetype |
797 | ifeval(const char **cpp) | 848 | ifeval(const char **cpp) |
798 | { | 849 | { |
799 | const char *cp = *cpp; | ||
800 | int ret; | 850 | int ret; |
801 | int val; | 851 | int val = 0; |
802 | 852 | ||
803 | debug("eval %s", *cpp); | 853 | debug("eval %s", *cpp); |
804 | keepthis = killconsts ? false : true; | 854 | constexpr = killconsts ? false : true; |
805 | ret = eval_table(eval_ops, &val, &cp); | 855 | ret = eval_table(eval_ops, &val, cpp); |
806 | if (ret != LT_IF) | ||
807 | *cpp = cp; | ||
808 | debug("eval = %d", val); | 856 | debug("eval = %d", val); |
809 | return (keepthis ? LT_IF : ret); | 857 | return (constexpr ? LT_IF : ret == LT_ERROR ? LT_IF : ret); |
810 | } | 858 | } |
811 | 859 | ||
812 | /* | 860 | /* |
@@ -918,6 +966,31 @@ skipcomment(const char *cp) | |||
918 | } | 966 | } |
919 | 967 | ||
920 | /* | 968 | /* |
969 | * Skip macro arguments. | ||
970 | */ | ||
971 | static const char * | ||
972 | skipargs(const char *cp) | ||
973 | { | ||
974 | const char *ocp = cp; | ||
975 | int level = 0; | ||
976 | cp = skipcomment(cp); | ||
977 | if (*cp != '(') | ||
978 | return (cp); | ||
979 | do { | ||
980 | if (*cp == '(') | ||
981 | level++; | ||
982 | if (*cp == ')') | ||
983 | level--; | ||
984 | cp = skipcomment(cp+1); | ||
985 | } while (level != 0 && *cp != '\0'); | ||
986 | if (level == 0) | ||
987 | return (cp); | ||
988 | else | ||
989 | /* Rewind and re-detect the syntax error later. */ | ||
990 | return (ocp); | ||
991 | } | ||
992 | |||
993 | /* | ||
921 | * Skip over an identifier. | 994 | * Skip over an identifier. |
922 | */ | 995 | */ |
923 | static const char * | 996 | static const char * |
@@ -929,7 +1002,7 @@ skipsym(const char *cp) | |||
929 | } | 1002 | } |
930 | 1003 | ||
931 | /* | 1004 | /* |
932 | * Look for the symbol in the symbol table. If is is found, we return | 1005 | * Look for the symbol in the symbol table. If it is found, we return |
933 | * the symbol table index, else we return -1. | 1006 | * the symbol table index, else we return -1. |
934 | */ | 1007 | */ |
935 | static int | 1008 | static int |