From 2f944c9a4aec933ba64b3837ee18321c7e5f69b4 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sat, 28 Oct 2023 19:03:49 +0200 Subject: [PATCH] Change runtime/gen_primitives.sh to take the list of .c files as argument This avoids writing the list twice, in the top-level Makefile and in the script. The Dune build needs updating accordingly. Also: move relevant comments from Makefile to runtime/gen_primitives.sh . --- Makefile | 22 ++-------------------- runtime/gen_primitives.sh | 39 +++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 514996694db..d1bb156207d 100644 --- a/Makefile +++ b/Makefile @@ -1251,29 +1251,11 @@ runtime/ld.conf: $(ROOTDIR)/Makefile.config $(V_GEN)echo "$(STUBLIBDIR)" > $@ && \ echo "$(LIBDIR)" >> $@ -# If primitives contain duplicated lines (e.g. because the code is defined -# like -# #ifdef X -# CAMLprim value caml_foo() ... -# #else -# CAMLprim value caml_foo() ... -# #endif), horrible things will happen: duplicated entries in Runtimedef -> -# double registration in Symtable -> empty entry in the PRIM table -> -# the bytecode interpreter is confused. -# We sort the primitive file and remove duplicates to avoid this problem. - -# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC -# port, the "sort" program in the path is Microsoft's and not cygwin's - -# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly. -# Sort is unstable for "is_directory" and "isatty" -# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html: -# "using sort to process pathnames, it is recommended that LC_ALL .. set to C" - # To speed up builds, we avoid changing "primitives" when files # containing primitives change but the primitives table does not runtime/primitives: \ - $(shell runtime/gen_primitives.sh > runtime/primitives.new; \ + $(shell runtime/gen_primitives.sh $(runtime_BYTECODE_C_SOURCES) \ + > runtime/primitives.new; \ cmp -s runtime/primitives runtime/primitives.new || \ echo runtime/primitives.new) $(V_GEN)cp $^ $@ diff --git a/runtime/gen_primitives.sh b/runtime/gen_primitives.sh index 9979732f38c..0fe676d496d 100755 --- a/runtime/gen_primitives.sh +++ b/runtime/gen_primitives.sh @@ -15,18 +15,29 @@ #* * #************************************************************************** -# #8985: the meaning of character range a-z depends on the locale, so force C -# locale throughout. +# If primitives contain duplicated lines (e.g. because the code is defined +# like +# #ifdef X +# CAMLprim value caml_foo() ... +# #else +# CAMLprim value caml_foo() ... +# #endif), horrible things will happen: duplicated entries in Runtimedef -> +# double registration in Symtable -> empty entry in the PRIM table -> +# the bytecode interpreter is confused. +# We sort the primitive file and remove duplicates to avoid this problem. + +# Warning: we use "sort | uniq" instead of "sort -u" because in the MSVC +# port, the "sort" program in the path is Microsoft's and not cygwin's + +# Warning: POSIX sort is locale dependent, that's why we set LC_ALL explicitly. +# Sort is unstable for "is_directory" and "isatty" +# see http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html: +# "using sort to process pathnames, it is recommended that LC_ALL .. set to C" + +# #8985: in sed, the meaning of character range a-z depends on the locale, +# so force C locale throughout. + export LC_ALL=C -( - for prim in \ - alloc array compare extern floats gc_ctrl hash intern interp ints io \ - lexing md5 meta memprof obj parsing signals str sys callback weak \ - finalise domain platform fiber memory startup_aux runtime_events sync \ - dynlink backtrace_byt backtrace afl \ - bigarray prng - do - sed -n -e 's/^CAMLprim value \([a-z0-9_][a-z0-9_]*\).*/\1/p' \ - "runtime/$prim.c" - done -) | sort | uniq + +sed -n -e 's/^CAMLprim value \([a-z][a-z0-9_]*\).*$/\1/p' "$@" | \ +sort | uniq