From b8f1169708f63ea542c0ed765a8b3a9d64f7684f Mon Sep 17 00:00:00 2001 From: Batchyx Date: Sun, 5 Mar 2023 16:16:56 +0100 Subject: [PATCH 1/2] Obey the CPPFLAGS environment variable. Most Linux packaging systems provide a generic CPPFLAGS environement variable that should be used by every package. --- README.md | 5 +++-- src/pc_port_env.erl | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index cfaaa34..7cc172b 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,9 @@ BELOW HERE BE DRAGONS %% By default, the following variables are defined: %% CC - C compiler %% CXX - C++ compiler -%% CFLAGS - C compiler -%% CXXFLAGS - C++ compiler +%% CPPFLAGS - C/C++ compiler preprocessor flags +%% CFLAGS - C compiler flags +%% CXXFLAGS - C++ compiler flags %% LDFLAGS - Link flags %% ERL_CFLAGS - default -I paths for erts and ei %% ERL_LDFLAGS - default -L and -lerl_interface -lei diff --git a/src/pc_port_env.erl b/src/pc_port_env.erl index 91d716b..1b7b18d 100644 --- a/src/pc_port_env.erl +++ b/src/pc_port_env.erl @@ -220,17 +220,17 @@ default_env() -> {"OBJDUMP", get_tool(Arch, "objdump", "objdump")}, {"DRV_CXX_TEMPLATE", - "$CXX -c $CXXFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, + "$CXX -c $CPPFLAGS $CXXFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"DRV_CC_TEMPLATE", - "$CC -c $CFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, + "$CC -c $CPPFLAGS $CFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"DRV_LINK_TEMPLATE", "$CC $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, {"DRV_LINK_CXX_TEMPLATE", "$CXX $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, {"EXE_CXX_TEMPLATE", - "$CXX -c $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, + "$CXX -c $CPPFLAGS $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"EXE_CC_TEMPLATE", - "$CC -c $CFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, + "$CC -c $CPPFLAGS $CFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"EXE_LINK_TEMPLATE", "$CC $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS -o $PORT_OUT_FILE"}, {"EXE_LINK_CXX_TEMPLATE", @@ -282,18 +282,18 @@ default_env() -> {"win32", "LINKER", "link.exe"}, {"win32", "DRV_CXX_TEMPLATE", %% DRV_* and EXE_* Templates are identical - "$CXX /c $CXXFLAGS $DRV_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, + "$CXX /c $CPPFLAGS $CXXFLAGS $DRV_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, {"win32", "DRV_CC_TEMPLATE", - "$CC /c $CFLAGS $DRV_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, + "$CC /c $CPPFLAGS $CFLAGS $DRV_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, {"win32", "DRV_LINK_TEMPLATE", "$LINKER $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS /OUT:$PORT_OUT_FILE"}, {"win32", "DRV_LINK_CXX_TEMPLATE", "$LINKER $PORT_IN_FILES $LDFLAGS $DRV_LDFLAGS /OUT:$PORT_OUT_FILE"}, %% DRV_* and EXE_* Templates are identical {"win32", "EXE_CXX_TEMPLATE", - "$CXX /c $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, + "$CXX /c $CPPFLAGS $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, {"win32", "EXE_CC_TEMPLATE", - "$CC /c $CFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, + "$CC /c $CPPFLAGS $CFLAGS $EXE_CFLAGS $PORT_IN_FILES /Fo$PORT_OUT_FILE"}, {"win32", "EXE_LINK_TEMPLATE", "$LINKER $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS /OUT:$PORT_OUT_FILE"}, {"win32", "EXE_LINK_CXX_TEMPLATE", From ffa5e66e816dba633a9adb4464d1a1b8c0b54154 Mon Sep 17 00:00:00 2001 From: Batchyx Date: Sun, 5 Mar 2023 16:19:54 +0100 Subject: [PATCH 2/2] Always use CFLAGS/CXXFLAGS when linking. CFLAGS may contain CPU architecture-related flags and these should also be passed to the linker. This mirror the behavior of most other build systems. --- src/pc_port_env.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pc_port_env.erl b/src/pc_port_env.erl index 1b7b18d..bff108a 100644 --- a/src/pc_port_env.erl +++ b/src/pc_port_env.erl @@ -224,17 +224,17 @@ default_env() -> {"DRV_CC_TEMPLATE", "$CC -c $CPPFLAGS $CFLAGS $DRV_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"DRV_LINK_TEMPLATE", - "$CC $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, + "$CC $PORT_IN_FILES $CFLAGS $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, {"DRV_LINK_CXX_TEMPLATE", - "$CXX $PORT_IN_FILES $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, + "$CXX $PORT_IN_FILES $CXXFLAGS $LDFLAGS $LDLIBS $DRV_LDFLAGS -o $PORT_OUT_FILE"}, {"EXE_CXX_TEMPLATE", "$CXX -c $CPPFLAGS $CXXFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"EXE_CC_TEMPLATE", "$CC -c $CPPFLAGS $CFLAGS $EXE_CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"}, {"EXE_LINK_TEMPLATE", - "$CC $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS -o $PORT_OUT_FILE"}, + "$CC $PORT_IN_FILES $CFLAGS $LDFLAGS $EXE_LDFLAGS -o $PORT_OUT_FILE"}, {"EXE_LINK_CXX_TEMPLATE", - "$CXX $PORT_IN_FILES $LDFLAGS $EXE_LDFLAGS -o $PORT_OUT_FILE"}, + "$CXX $PORT_IN_FILES $CXXFLAGS $LDFLAGS $EXE_LDFLAGS -o $PORT_OUT_FILE"}, {"DRV_CFLAGS" , "-g -Wall -fPIC -MMD $ERL_CFLAGS"}, {"DRV_LDFLAGS", "-shared $ERL_LDFLAGS"}, {"EXE_CFLAGS" , "-g -Wall -fPIC -MMD $ERL_CFLAGS"},