From 66185536e8d545253842264bfd8486d5c1aa6086 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Mon, 24 Nov 2025 17:49:35 -0800 Subject: [PATCH 1/2] Configure: added option to configure position independent code flag. --- auto/help | 2 ++ auto/make | 5 +++-- auto/options | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/auto/help b/auto/help index 064a209b4..7fb6f6e23 100644 --- a/auto/help +++ b/auto/help @@ -16,6 +16,8 @@ default: "$NJS_ADDRESS_SANITIZER" --cc=FILE sets C compiler filename, default: "$CC" --cc-opt=OPTIONS sets additional C compiler options, \ default: "$NJS_CC_OPT" + --pic=OPTION sets position independent code flag, \ +default: "$NJS_PIC" --debug=YES enables additional runtime checks, \ default: "$NJS_DEBUG" --debug-memory=YES enables memory alloc debug, \ diff --git a/auto/make b/auto/make index feffb69aa..928d41d36 100644 --- a/auto/make +++ b/auto/make @@ -89,6 +89,7 @@ cat << END > $NJS_MAKEFILE NJS_CC = ${CC} NJS_STATIC_LINK = ${AR} -r -c NJS_LINK = ${CC} ${NJS_LD_OPT} +NJS_PIC = ${NJS_PIC} NJS_CFLAGS = ${NJS_CFLAGS} ${NJS_CC_OPT} ${CFLAGS} NJS_LIB_AUX_CFLAGS = ${NJS_LIB_AUX_CFLAGS} @@ -132,7 +133,7 @@ do cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/$njs_obj: $njs_src - \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_CFLAGS) \\ + \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(NJS_CFLAGS) \\ \$(NJS_LIB_AUX_CFLAGS) \\ -o $NJS_BUILD_DIR/$njs_obj \\ $njs_dep_flags \\ @@ -154,7 +155,7 @@ do cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/$njs_obj: $njs_src - \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_CFLAGS) \\ + \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(NJS_CFLAGS) \\ \$(NJS_LIB_AUX_CFLAGS) \\ -o $NJS_BUILD_DIR/$njs_obj \\ $njs_dep_flags \\ diff --git a/auto/options b/auto/options index 0a4dc6c74..d2fadbd05 100644 --- a/auto/options +++ b/auto/options @@ -5,6 +5,7 @@ NJS_CC_OPT=${NJS_CC_OPT:--O} NJS_LD_OPT=${NJS_CC_OPT:--O} +NJS_PIC=-fPIC NJS_DEBUG=NO NJS_DEBUG_MEMORY=NO @@ -40,6 +41,8 @@ do --ld-opt=*) NJS_LD_OPT="$value" ;; --ar=*) AR="$value" ;; + --pic=*) NJS_PIC="$value" ;; + --build-dir=*) NJS_BUILD_DIR="$value" ;; --address-sanitizer=*) NJS_ADDRESS_SANITIZER="$value" ;; From 339125fa87d17ccdf0fa8f6ee86b7aee687c7c1b Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Mon, 24 Nov 2025 16:19:59 -0800 Subject: [PATCH 2/2] Configure: respecting user provided CFLAGS. See https://www.gnu.org/prep/standards/html_node/Command-Variables.html and discussion in #900 issue on Github. --- auto/make | 14 +++++++------- auto/options | 4 ++-- auto/summary | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/auto/make b/auto/make index 928d41d36..296ff5a8d 100644 --- a/auto/make +++ b/auto/make @@ -90,7 +90,7 @@ NJS_CC = ${CC} NJS_STATIC_LINK = ${AR} -r -c NJS_LINK = ${CC} ${NJS_LD_OPT} NJS_PIC = ${NJS_PIC} -NJS_CFLAGS = ${NJS_CFLAGS} ${NJS_CC_OPT} ${CFLAGS} +CFLAGS = ${NJS_CC_OPT} ${CFLAGS:-${NJS_CFLAGS}} NJS_LIB_AUX_CFLAGS = ${NJS_LIB_AUX_CFLAGS} NJS_VER = $(grep NJS_VERSION src/njs.h | sed -e 's#.*"\(.*\)".*#\1#') @@ -133,7 +133,7 @@ do cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/$njs_obj: $njs_src - \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(NJS_CFLAGS) \\ + \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(CFLAGS) \\ \$(NJS_LIB_AUX_CFLAGS) \\ -o $NJS_BUILD_DIR/$njs_obj \\ $njs_dep_flags \\ @@ -155,7 +155,7 @@ do cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/$njs_obj: $njs_src - \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(NJS_CFLAGS) \\ + \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_PIC) \$(CFLAGS) \\ \$(NJS_LIB_AUX_CFLAGS) \\ -o $NJS_BUILD_DIR/$njs_obj \\ $njs_dep_flags \\ @@ -176,7 +176,7 @@ $NJS_BUILD_DIR/njs: \\ $NJS_BUILD_DIR/libnjs.a $QJS_LIB \\ external/njs_shell.c \$(NJS_LINK) -o $NJS_BUILD_DIR/njs \$(NJS_LIB_INCS) \\ - \$(NJS_CFLAGS) \$(NJS_LIB_AUX_CFLAGS)\\ + \$(CFLAGS) \$(NJS_LIB_AUX_CFLAGS)\\ external/njs_shell.c \\ $NJS_BUILD_DIR/libnjs.a $QJS_LIB \\ $NJS_LD_OPT -lm $NJS_LIBS $NJS_LIB_AUX_LIBS $NJS_READLINE_LIB @@ -221,7 +221,7 @@ do $NJS_BUILD_DIR/$njs_bin: $njs_src \\ $NJS_BUILD_DIR/libnjs.a \$(NJS_LINK) -o $NJS_BUILD_DIR/$njs_bin \$(NJS_LIB_INCS) \\ - \$(NJS_CFLAGS) $njs_dep_flags \\ + \$(CFLAGS) $njs_dep_flags \\ $njs_src $NJS_BUILD_DIR/libnjs.a \\ $njs_dep_post -lm $NJS_LD_OPT @@ -245,7 +245,7 @@ cat << END >> $NJS_MAKEFILE $NJS_BUILD_DIR/$njs_externals_obj: \\ $njs_src - \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(NJS_CFLAGS) \\ + \$(NJS_CC) -c \$(NJS_LIB_INCS) \$(CFLAGS) \\ \$(NJS_LIB_AUX_CFLAGS) \\ -o $NJS_BUILD_DIR/$njs_externals_obj \\ $njs_dep_flags \\ @@ -269,7 +269,7 @@ $NJS_BUILD_DIR/$njs_bin: $njs_src \\ $NJS_BUILD_DIR/libnjs.a \\ $NJS_BUILD_DIR/$njs_externals_obj \$(NJS_LINK) -o $NJS_BUILD_DIR/$njs_bin \$(NJS_LIB_INCS) \\ - \$(NJS_CFLAGS) \$(NJS_LIB_AUX_CFLAGS) \\ + \$(CFLAGS) \$(NJS_LIB_AUX_CFLAGS) \\ $njs_dep_flags \\ $NJS_BUILD_DIR/$njs_externals_obj \\ $njs_src $NJS_BUILD_DIR/libnjs.a \\ diff --git a/auto/options b/auto/options index d2fadbd05..49d980192 100644 --- a/auto/options +++ b/auto/options @@ -3,8 +3,8 @@ # Copyright (C) NGINX, Inc. -NJS_CC_OPT=${NJS_CC_OPT:--O} -NJS_LD_OPT=${NJS_CC_OPT:--O} +NJS_CC_OPT= +NJS_LD_OPT= NJS_PIC=-fPIC NJS_DEBUG=NO diff --git a/auto/summary b/auto/summary index f540f11ec..59d70428c 100644 --- a/auto/summary +++ b/auto/summary @@ -7,7 +7,7 @@ echo echo "NJS configuration summary:" echo echo " + using CC: \"$CC\"" -echo " + using CFLAGS: \"$NJS_CFLAGS $NJS_CC_OPT $CFLAGS\"" +echo " + using CFLAGS: \"$NJS_CC_OPT ${CFLAGS:-$NJS_CFLAGS}\"" echo if [ $NJS_HAVE_PCRE = YES ]; then