Merge pull request #9824 from shindere/honour-cflags-cppflags

Build system: honour the CFLAGS and CPPFLAGS build variables
master
David Allsopp 2020-08-06 15:37:22 +01:00 committed by GitHub
commit 5da188b3ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 64 additions and 62 deletions

View File

@ -318,6 +318,9 @@ Working version
- #9804: Build C stubs of libraries in otherlibs/ with debug info.
(Stephen Dolan, review by Sébastien Hinderer and David Allsopp)
- #9824: Honour the CFLAGS and CPPFLAGS variables.
(Sébastien Hinderer, review by David Allsopp)
### Bug fixes:
- #7902, #9556: Type-checker infers recursive type, even though -rectypes is

View File

@ -53,7 +53,6 @@ else
OCAML_NATDYNLINKOPTS = -ccopt "$(NATDYNLINKOPTS)"
endif
YACCFLAGS=-v --strict
CAMLLEX=$(CAMLRUN) boot/ocamllex
CAMLDEP=$(CAMLRUN) boot/ocamlc -depend
DEPFLAGS=-slash
@ -928,13 +927,16 @@ endif
# Check that the stack limit is reasonable (Unix-only)
.PHONY: checkstack
checkstack:
ifeq "$(UNIX_OR_WIN32)" "unix"
if $(MKEXE) $(OUTPUTEXE)tools/checkstack$(EXE) tools/checkstack.c; \
then tools/checkstack$(EXE); \
fi
rm -f tools/checkstack$(EXE)
checkstack := tools/checkstack
checkstack: $(checkstack)$(EXE)
$<
.INTERMEDIATE: $(checkstack)$(EXE) $(checkstack).$(O)
$(checkstack)$(EXE): $(checkstack).$(O)
$(MKEXE) $(OUTPUTEXE)$@ $<
else
checkstack:
@
endif

View File

@ -109,7 +109,8 @@ REQUIRED_HEADERS := $(RUNTIME_HEADERS) $(wildcard *.h)
endif
%.$(O): %.c $(REQUIRED_HEADERS)
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
$(CC) -c $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) \
$(OUTPUTOBJ)$@ $<
$(DEPDIR):
$(MKDIR) $@

View File

@ -179,7 +179,9 @@ UNIXLIB=@unixlib@
INSTALL_SOURCE_ARTIFACTS=@install_source_artifacts@
OC_CFLAGS=@oc_cflags@
CFLAGS?=@CFLAGS@
OC_CPPFLAGS=@oc_cppflags@
CPPFLAGS?=@CPPFLAGS@
OCAMLC_CFLAGS=@ocamlc_cflags@
OCAMLC_CPPFLAGS=@ocamlc_cppflags@
@ -252,10 +254,10 @@ ifeq "$(TOOLCHAIN)" "msvc"
MERGEMANIFESTEXE=test ! -f $(1).manifest \
|| mt -nologo -outputresource:$(1) -manifest $(1).manifest \
&& rm -f $(1).manifest
MKEXE_BOOT=$(CC) $(OC_CFLAGS) $(OUTPUTEXE)$(1) $(2) \
MKEXE_BOOT=$(CC) $(OUTPUTEXE)$(1) $(2) \
/link /subsystem:console $(OC_LDFLAGS) && ($(MERGEMANIFESTEXE))
else
MKEXE_BOOT=$(CC) $(OC_CFLAGS) $(OC_LDFLAGS) $(OUTPUTEXE)$(1) $(2)
MKEXE_BOOT=$(CC) $(OC_LDFLAGS) $(OUTPUTEXE)$(1) $(2)
endif # ifeq "$(TOOLCHAIN)" "msvc"
# The following variables were defined only in the Windows-specific makefiles.

13
configure vendored
View File

@ -2780,7 +2780,7 @@ programs_man_section=1
libraries_man_section=3
# Command to build executalbes
mkexe="\$(CC) \$(OC_CFLAGS) \$(OC_CPPFLAGS) \$(OC_LDFLAGS)"
mkexe="\$(CC) \$(OC_LDFLAGS)"
# Flags for building executable files with debugging symbols
mkexedebugflag="-g"
@ -3460,10 +3460,14 @@ esac
fi
# libtool expects host_os=mingw for native Windows
# Also, it has been observed that, on some platforms (e.g. msvc) LT_INIT
# alters the CFLAGS variable, so we save its value before calling the macro
# and restore it after the call
old_host_os=$host_os
if test x"$host_os" = "xwindows"; then :
host_os=mingw
fi
saved_CFLAGS="$CFLAGS"
case `pwd` in
*\ * | *\ *)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@ -12309,6 +12313,7 @@ CC=$lt_save_CC
# Only expand once:
CFLAGS="$saved_CFLAGS"
host_os=$old_host_os
case $host in #(
@ -12727,7 +12732,7 @@ $as_echo "$as_me: WARNING: Consider using GCC version 4.2 or above." >&2;};
internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE="
internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)" ;; #(
xlc-*) :
common_cflags="-O5 -qtune=balanced -qnoipa -qinline $CFLAGS";
common_cflags="-O5 -qtune=balanced -qnoipa -qinline";
internal_cflags="$cc_warnings" ;; #(
*) :
common_cflags="-O" ;;
@ -16980,8 +16985,8 @@ fi
oc_cflags="$common_cflags $internal_cflags"
oc_cppflags="$common_cppflags $internal_cppflags"
ocamlc_cflags="$common_cflags $sharedlib_cflags"
ocamlc_cppflags="$common_cppflags"
ocamlc_cflags="$common_cflags $sharedlib_cflags \$(CFLAGS)"
ocamlc_cppflags="$common_cppflags \$(CPPFLAGS)"
cclibs="$cclibs $mathlib"
case $host in #(

View File

@ -37,7 +37,7 @@ programs_man_section=1
libraries_man_section=3
# Command to build executalbes
mkexe="\$(CC) \$(OC_CFLAGS) \$(OC_CPPFLAGS) \$(OC_LDFLAGS)"
mkexe="\$(CC) \$(OC_LDFLAGS)"
# Flags for building executable files with debugging symbols
mkexedebugflag="-g"
@ -406,9 +406,14 @@ AS_IF([test x"$enable_unix_lib" = "xno" -o x"$enable_str_lib" = "xno"],
# User-specified LD still takes precedence.
AC_CHECK_TOOLS([LD],[ld link])
# libtool expects host_os=mingw for native Windows
# Also, it has been observed that, on some platforms (e.g. msvc) LT_INIT
# alters the CFLAGS variable, so we save its value before calling the macro
# and restore it after the call
old_host_os=$host_os
AS_IF([test x"$host_os" = "xwindows"],[host_os=mingw])
saved_CFLAGS="$CFLAGS"
LT_INIT
CFLAGS="$saved_CFLAGS"
host_os=$old_host_os
AS_CASE([$host],
@ -628,7 +633,7 @@ AS_CASE([$host],
internal_cppflags="$internal_cppflags -DWINDOWS_UNICODE="
internal_cppflags="${internal_cppflags}\$(WINDOWS_UNICODE)"],
[xlc-*],
[common_cflags="-O5 -qtune=balanced -qnoipa -qinline $CFLAGS";
[common_cflags="-O5 -qtune=balanced -qnoipa -qinline";
internal_cflags="$cc_warnings"],
[common_cflags="-O"])])
@ -1851,8 +1856,8 @@ AS_IF([test x"$DEFAULT_STRING" = "xunsafe"],
oc_cflags="$common_cflags $internal_cflags"
oc_cppflags="$common_cppflags $internal_cppflags"
ocamlc_cflags="$common_cflags $sharedlib_cflags"
ocamlc_cppflags="$common_cppflags"
ocamlc_cflags="$common_cflags $sharedlib_cflags \$(CFLAGS)"
ocamlc_cppflags="$common_cppflags \$(CPPFLAGS)"
cclibs="$cclibs $mathlib"
AS_CASE([$host],

View File

@ -27,7 +27,6 @@ CAMLC=$(BEST_OCAMLC) -g -nostdlib -I $(ROOTDIR)/stdlib
COMPFLAGS=$(INCLUDES) -absname -w +a-4-9-41-42-44-45-48 -warn-error A \
-safe-string -strict-sequence -strict-formats
LINKFLAGS=-linkall -I $(UNIXDIR) -I $(DYNLINKDIR)
YACCFLAGS=
CAMLLEX=$(BEST_OCAMLLEX)
CAMLDEP=$(BEST_OCAMLDEP)
DEPFLAGS=-slash

View File

@ -27,7 +27,6 @@ CAMLOPT = $(CAMLRUN) $(ROOTDIR)/ocamlopt$(EXE) -nostdlib -I $(ROOTDIR)/stdlib
COMPFLAGS = -absname -w +a-4-9-41-42-44-45-48 -warn-error A \
-safe-string -strict-sequence -strict-formats -bin-annot
LINKFLAGS =
YACCFLAGS = -v
CAMLLEX = $(CAMLRUN) $(ROOTDIR)/boot/ocamllex
CAMLDEP = $(BOOT_OCAMLC) -depend
DEPFLAGS = -slash
@ -56,7 +55,7 @@ clean::
rm -f *.cmo *.cmi *.cmx *.cmt *.cmti *.o *.obj
parser.ml parser.mli: parser.mly
$(CAMLYACC) $(YACCFLAGS) parser.mly
$(CAMLYACC) -v parser.mly
clean::
rm -f parser.ml parser.mli parser.output

View File

@ -304,7 +304,7 @@ include $(addprefix $(DEPDIR)/, $(c_files:.c=.$(D)))
endif
$(DEPDIR)/%.$(D): %.c | $(DEPDIR)
$(DEP_CC) $(OC_CPPFLAGS) $< -MT '$*.$(O)' -MF $@
$(DEP_CC) $(OC_CPPFLAGS) $(CPPFLAGS) $< -MT '$*.$(O)' -MF $@
.PHONY: depend
depend: $(dependencies_generated_prereqs)

View File

@ -144,4 +144,4 @@ endif
endif
$(DEPDIR)/%.$(D): %.c | $(DEPDIR)
$(DEP_CC) $(OC_CPPFLAGS) $< -MT '$*.$(O)' -MF $@
$(DEP_CC) $(OC_CPPFLAGS) $(CPPFLAGS) $< -MT '$*.$(O)' -MF $@

View File

@ -100,7 +100,8 @@ st_stubs.%.$(O): st_stubs.c
else
st_stubs.%.$(O): st_stubs.c $(RUNTIME_HEADERS) $(wildcard *.h)
endif
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<
$(CC) -c $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) \
$(OUTPUTOBJ)$@ $<
partialclean:
rm -f *.cm*
@ -162,7 +163,7 @@ endif
define GEN_RULE
$(DEPDIR)/%.$(1).$(D): %.c | $(DEPDIR)
$$(DEP_CC) $$(OC_CPPFLAGS) $$< -MT '$$*.$(1).$(O)' -MF $$@
$$(DEP_CC) $$(OC_CPPFLAGS) $$(CPPFLAGS) $$< -MT '$$*.$(1).$(O)' -MF $$@
endef
$(foreach object_type, b n, $(eval $(call GEN_RULE,$(object_type))))

View File

@ -349,13 +349,15 @@ ifneq "$(1)" "%"
# don't use -MG and instead include $(GENERATED_HEADERS) in the order only
# dependencies to ensure that they exist before dependencies are computed.
$(DEPDIR)/$(1).$(D): %.c | $(DEPDIR) $(GENERATED_HEADERS)
$$(DEP_CC) $$(OC_CPPFLAGS) $$< -MT '$$*$(subst %,,$(1)).$(O)' -MF $$@
$$(DEP_CC) $$(OC_CPPFLAGS) $$(CPPFLAGS) $$< -MT \
'$$*$(subst %,,$(1)).$(O)' -MF $$@
endif
$(1).$(O): %.c
else
$(1).$(O): %.c $(CONFIG_HEADERS) $(GENERATED_HEADERS) $(RUNTIME_HEADERS)
endif
$$(CC) -c $$(OC_CFLAGS) $$(OC_CPPFLAGS) $$(OUTPUTOBJ)$$@ $$<
$$(CC) -c $$(OC_CFLAGS) $$(CFLAGS) $$(OC_CPPFLAGS) $$(CPPFLAGS) \
$$(OUTPUTOBJ)$$@ $$<
endef
object_types := % %.b %.bd %.bi %.bpic

View File

@ -148,7 +148,8 @@ $(HEADERPROGRAM)%$(O): \
OC_CPPFLAGS += -DRUNTIME_NAME='"$(HEADER_PATH)ocamlrun$(subst .,,$*)"'
$(HEADERPROGRAM)%$(O): $(HEADERPROGRAM).c
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $^
$(CC) -c $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) \
$(OUTPUTOBJ)$@ $^
camlheader_ur: camlheader
cp camlheader $@
@ -159,7 +160,7 @@ tmptargetcamlheader%exe: $(TARGETHEADERPROGRAM)%$(O)
strip $@
$(TARGETHEADERPROGRAM)%$(O): $(HEADERPROGRAM).c
$(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) \
$(CC) -c $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS) \
-DRUNTIME_NAME='"$(HEADER_TARGET_PATH)ocamlrun$(subst .,,$*)"' \
$(OUTPUTOBJ)$@ $^

View File

@ -48,16 +48,6 @@ arch_error() {
error "$msg"
}
# Change a variable in Makefile.config
# Usage: set_config_var <variable name> <new value>
set_config_var() {
conffile=Makefile.config
mv ${conffile} ${conffile}.bak
(grep -v "^$1=" ${conffile}.bak; echo "$1=$2") > ${conffile}
}
#########################################################################
# Print each command before its execution
@ -151,10 +141,6 @@ echo "======== clang 9, address sanitizer, UB sanitizer =========="
git clean -q -f -d -x
# Use clang 9
# We cannot give the sanitizer options as part of -cc because
# then various autoconfiguration tests fail.
# Instead, we'll fix OC_CFLAGS a posteriori.
./configure CC=clang-9 --disable-stdlib-manpages --enable-dependency-generation
# These are the undefined behaviors we want to check
# Others occur on purpose e.g. signed arithmetic overflow
@ -172,12 +158,14 @@ shift-exponent,\
unreachable"
# Select address sanitizer and UB sanitizer, with trap-on-error behavior
sanitizers="-fsanitize=address -fsanitize-trap=$ubsan"
# Don't optimize too much to get better backtraces of errors
set_config_var OC_CFLAGS "-O1 \
-fno-strict-aliasing -fwrapv -fno-omit-frame-pointer \
-Wall -Werror \
-fsanitize=address \
-fsanitize-trap=$ubsan"
./configure \
CC=clang-9 \
CFLAGS="-O1 -fno-omit-frame-pointer $sanitizers" \
--disable-stdlib-manpages --enable-dependency-generation
# Build the system. We want to check for memory leaks, hence
# 1- force ocamlrun to free memory before exiting
@ -205,14 +193,13 @@ echo "======== clang 9, thread sanitizer =========="
git clean -q -f -d -x
./configure CC=clang-9 --disable-stdlib-manpages --enable-dependency-generation
# Select thread sanitizer
# Don't optimize too much to get better backtraces of errors
set_config_var OC_CFLAGS "-O1 \
-fno-strict-aliasing -fwrapv -fno-omit-frame-pointer \
-Wall -Werror \
-fsanitize=thread"
./configure \
CC=clang-9 \
CFLAGS="-O1 -fno-omit-frame-pointer -fsanitize=thread" \
--disable-stdlib-manpages --enable-dependency-generation
# Build the system
make $jobs
@ -234,20 +221,15 @@ TSAN_OPTIONS="die_after_fork=0" $run_testsuite
# git clean -q -f -d -x
# # Use clang 6.0
# # We cannot give the sanitizer options as part of -cc because
# # then various autoconfiguration tests fail.
# # Instead, we'll fix OC_CFLAGS a posteriori.
# # Memory sanitizer doesn't like the static data generated by ocamlopt,
# # hence build bytecode only
# ./configure CC=clang-9 --disable-native-compiler
# # Select memory sanitizer
# # Don't optimize at all to get better backtraces of errors
# set_config_var OC_CFLAGS "-O0 -g \
# -fno-strict-aliasing -fwrapv -fno-omit-frame-pointer \
# -Wall -Werror \
# -fsanitize=memory"
# ./configure \
# CC=clang-9 \
# CFLAGS="-O0 -g -fno-omit-frame-pointer -fsanitize=memory" \
# --disable-native-compiler
# # A tool that makes error backtraces nicer
# # Need to pick the one that matches clang-6.0
# export MSAN_SYMBOLIZER_PATH=/usr/lib/llvm-6.0/bin/llvm-symbolizer