aboutsummaryrefslogtreecommitdiff
path: root/Makerules
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2018-11-30 15:20:41 +0000
committerJoseph Myers <joseph@codesourcery.com>2018-11-30 15:20:41 +0000
commit7e1d42400c1b8f03316fe14176133c8853cd3bbe (patch)
treec34eb3317fd3d98b8e4ca27b409621e9238d9a24 /Makerules
parentce7387cc250a408d3fbb7a6fff7ad4d977166b00 (diff)
downloadglibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.zip
glibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.tar.gz
glibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.tar.bz2
Replace gen-as-const.awk by gen-as-const.py.
This patch replaces gen-as-const.awk, and some fragments of the Makefile code that used it, by a Python script. The point is not such much that awk is problematic for this particular script, as that I'd like to build up a general Python infrastructure for extracting information from C headers, for use in writing tests of such headers. Thus, although this patch does not set up such infrastructure, the compute_c_consts function in gen-as-const.py might be moved to a separate Python module in a subsequent patch as a starting point for such infrastructure. The general idea of the code is the same as in the awk version, but no attempt is made to make the output files textually identical. When generating a header, a dict of constant names and values is generated internally then defines are printed in sorted order (rather than the order in the .sym file, which would have been used before). When generating a test that the values computed match those from a normal header inclusion, the test code is made into a compilation test using _Static_assert, where previously the comparisons were done only when the test was executed. One fragment of test generation (converting the previously generated header to use asconst_* prefixes on its macro names) is still in awk code in the makefiles; only the .sym processing and subsequent execution of the compiler to extract constants have moved to the Python script. Tested for x86_64, and with build-many-glibcs.py. * scripts/gen-as-const.py: New file. * scripts/gen-as-const.awk: Remove. * Makerules ($(common-objpfx)%.h $(common-objpfx)%.h.d): Use gen-as-const.py. ($(objpfx)test-as-const-%.c): Likewise.
Diffstat (limited to 'Makerules')
-rw-r--r--Makerules18
1 files changed, 7 insertions, 11 deletions
diff --git a/Makerules b/Makerules
index 07bfe8a..8e49a73 100644
--- a/Makerules
+++ b/Makerules
@@ -282,15 +282,12 @@ ifdef gen-as-const-headers
# may include <tcb-offsets.h>. Target header files can check if
# GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
# may lead to build hang on a many-core machine.
-$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
+$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.py \
%.sym $(common-before-compile)
- $(AWK) -f $< $(filter %.sym,$^) \
- | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) \
- -DGEN_AS_CONST_HEADERS -x c - \
- -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
- sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
- $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
- rm -f $(@:.h.d=.h)T3
+ $(PYTHON) $< --cc="$(CC) $(CFLAGS) $(CPPFLAGS) -DGEN_AS_CONST_HEADERS \
+ -MD -MP -MF $(@:.h=.h.d)T \
+ -MT '$(@:.h=.h.d) $(@:.h.d=.h)'" \
+ $(filter %.sym,$^) > $(@:.h.d=.h)T
sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
$(@:.h=.h.d)T > $(@:.h=.h.d)T2
rm -f $(@:.h=.h.d)T
@@ -301,11 +298,10 @@ before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
-$(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
+$(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.py $(..)Makerules \
%.sym $(common-objpfx)%.h
($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
- $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
- echo '#include "$(..)test-skeleton.c"') > $@T
+ $(PYTHON) $< --test $(filter %.sym,$^)) > $@T
mv -f $@T $@
endif