Skip to content

Commit 338e1b2

Browse files
committed
Implement FR #77230: Support custom CFLAGS and LDFLAGS from environment
While it is already possible to *set* CFLAGS and LDFLAGS (actually all variables) from the environment for `nmake` (by passing the `/E` option), it is not possible to *add* any (C|LD)FLAGS, which can be useful in some cases. Instead of allowing this for `nmake`, we add support for additional custom (C|LD)FLAGS to `configure`, similar to how that works on Linux, so one could actually write: ```` set CFLAGS=foo & set LDFLAGS=bar & configure ```` This also allows us to use these flags during configure.
1 parent 98b6330 commit 338e1b2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #78239 (Deprecation notice during string conversion converted to
77
exception hangs). (Nikita)
8+
. Implemented FR #77230 (Support custom CFLAGS and LDFLAGS from environment).
9+
(cmb)
810

911
- Date:
1012
. Updated timelib to 2018.02. (Derick)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ r SQLite3:
568568
- CTRL+C and CTRL+BREAK on console can be caught by setting a handler function
569569
with sapi_windows_set_ctrl_handler().
570570

571+
- configure now regards additional CFLAGS and LDFLAGS set as environment
572+
variables.
573+
571574
========================================
572575
13. Migration to pkg-config
573576
========================================

win32/build/confutils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ can be built that way. \
431431
}
432432
STDOUT.WriteLine(" " + arg.arg + pad + word_wrap_and_indent(max_width + 5, arg.helptext));
433433
}
434+
STDOUT.WriteBlankLines(1);
435+
STDOUT.WriteLine("Some influential environment variables:");
436+
STDOUT.WriteLine(" CFLAGS C compiler flags");
437+
STDOUT.WriteLine(" LDFLAGS linker flags");
434438
WScript.Quit(1);
435439
}
436440

@@ -3207,6 +3211,8 @@ function toolset_setup_linker()
32073211

32083212
function toolset_setup_common_cflags()
32093213
{
3214+
var envCFLAGS = WshShell.Environment("PROCESS").Item("CFLAGS");
3215+
32103216
// CFLAGS for building the PHP dll
32113217
DEFINE("CFLAGS_PHP", "/D _USRDLL /D PHP7DLLTS_EXPORTS /D PHP_EXPORTS \
32123218
/D LIBZEND_EXPORTS /D TSRM_EXPORTS /D SAPI_EXPORTS /D WINVER=" + WINVER);
@@ -3218,6 +3224,10 @@ function toolset_setup_common_cflags()
32183224
/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /W3 \
32193225
/D _USE_MATH_DEFINES");
32203226

3227+
if (envCFLAGS) {
3228+
ADD_FLAG("CFLAGS", envCFLAGS);
3229+
}
3230+
32213231
if (VS_TOOLSET) {
32223232
ADD_FLAG("CFLAGS", " /FD ");
32233233

@@ -3368,6 +3378,8 @@ function toolset_setup_intrinsic_cflags()
33683378

33693379
function toolset_setup_common_ldlags()
33703380
{
3381+
var envLDFLAGS = WshShell.Environment("PROCESS").Item("LDFLAGS");
3382+
33713383
// General DLL link flags
33723384
DEFINE("DLL_LDFLAGS", "/dll ");
33733385

@@ -3376,6 +3388,10 @@ function toolset_setup_common_ldlags()
33763388

33773389
DEFINE("LDFLAGS", "/nologo ");
33783390

3391+
if (envLDFLAGS) {
3392+
ADD_FLAG("LDFLAGS", envLDFLAGS);
3393+
}
3394+
33793395
// we want msvcrt in the PHP DLL
33803396
ADD_FLAG("PHP_LDFLAGS", "/nodefaultlib:libcmt");
33813397

0 commit comments

Comments
 (0)