@@ -1526,19 +1526,37 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
1526
1526
ADD_FLAG ( bd_flags_name , "/Fd" + sub_build + d ) ;
1527
1527
}
1528
1528
1529
+ if ( PHP_ANALYZER == "clang" ) {
1530
+ var analyzer_base_args = X64 ? "-m64" : "-m32" ;
1531
+
1532
+ analyzer_base_args += " --analyze" ;
1533
+
1534
+ var vc_ver ;
1535
+ if ( VS_TOOLSET ) {
1536
+ vc_ver = VCVERS ;
1537
+ } else {
1538
+ vc_ver = probe_binary ( PATH_PROG ( 'cl' , null ) ) ;
1539
+ }
1540
+
1541
+ analyzer_base_args += " -fms-compatibility -fms-compatibility-version=" + vc_ver + " -fms-extensions" ;
1542
+ }
1543
+
1529
1544
if ( PHP_MP_DISABLED ) {
1530
1545
for ( var j in srcs_by_dir [ k ] ) {
1531
1546
src = file_list [ srcs_by_dir [ k ] [ j ] ] ;
1532
- if ( PHP_ANALYZER == "pvs" ) {
1533
- MFO . WriteLine ( "\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
1534
- + " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" " ) ;
1535
- }
1536
1547
1537
1548
var _tmp = src . split ( "\\" ) ;
1538
1549
var filename = _tmp . pop ( ) ;
1539
1550
obj = filename . replace ( re , ".obj" ) ;
1540
1551
1541
1552
MFO . WriteLine ( "\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + d + obj ) ;
1553
+
1554
+ if ( "clang" == PHP_ANALYZER ) {
1555
+ MFO . WriteLine ( "\t\"@$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) /c " + dir + "\\" + src ) ;
1556
+ } else if ( PHP_ANALYZER == "pvs" ) {
1557
+ MFO . WriteLine ( "\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
1558
+ + " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" " ) ;
1559
+ }
1542
1560
}
1543
1561
} else {
1544
1562
/* TODO create a response file at least for the source files to work around the cmd line length limit. */
@@ -1548,6 +1566,10 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
1548
1566
}
1549
1567
1550
1568
MFO . WriteLine ( "\t$(CC) $(" + flags + ") $(CFLAGS) /Fo" + sub_build + d + " $(" + bd_flags_name + ") /c " + src_line ) ;
1569
+
1570
+ if ( "clang" == PHP_ANALYZER ) {
1571
+ MFO . WriteLine ( "\t\"$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) /c " + src_line ) ;
1572
+ }
1551
1573
}
1552
1574
}
1553
1575
@@ -1729,6 +1751,8 @@ function write_summary()
1729
1751
}
1730
1752
if ( PHP_ANALYZER == "vs" ) {
1731
1753
ar [ 5 ] = [ 'Static analyzer' , 'Visual Studio' ] ;
1754
+ } else if ( PHP_ANALYZER == "clang" ) {
1755
+ ar [ 5 ] = [ 'Static analyzer' , 'clang' ] ;
1732
1756
} else if ( PHP_ANALYZER == "pvs" ) {
1733
1757
ar [ 5 ] = [ 'Static analyzer' , 'PVS-Studio' ] ;
1734
1758
} else {
@@ -2057,6 +2081,54 @@ function generate_phpize()
2057
2081
CJ . Close ( ) ;
2058
2082
}
2059
2083
2084
+ function handle_analyzer_makefile_flags ( fd , key , val )
2085
+ {
2086
+ var relevant = false ;
2087
+
2088
+ /* VS integrates /analyze with the bulid process,
2089
+ no further action is required. */
2090
+ if ( "no" == PHP_ANALYZER || "vs" == PHP_ANALYZER ) {
2091
+ return ;
2092
+ }
2093
+
2094
+ if ( key . match ( "CFLAGS" ) ) {
2095
+ var new_val = val ;
2096
+ var reg = / \$ \( ( [ ^ \) ] + ) \) / g;
2097
+ while ( r = reg . exec ( val ) ) {
2098
+ var repl = "$(" + r [ 1 ] + "_ANALYZER)"
2099
+ new_val = new_val . replace ( r [ 0 ] , repl ) ;
2100
+ }
2101
+ val = new_val ;
2102
+
2103
+ if ( "clang" == PHP_ANALYZER ) {
2104
+ val = val . replace ( / \/ F D / , "" )
2105
+ . replace ( / \/ F p .+ ? / , "" )
2106
+ . replace ( / \/ F o .+ ? / , "" )
2107
+ . replace ( / \/ F d .+ ? / , "" )
2108
+ //.replace(/\/Fd.+?/, " ")
2109
+ . replace ( / \/ F R .+ ? / , "" )
2110
+ . replace ( "/guard:cf " , "" )
2111
+ . replace ( / \/ M P \d + / , "" )
2112
+ . replace ( / \/ M P / , "" )
2113
+ . replace ( "/LD " , "" ) ;
2114
+ }
2115
+
2116
+ relevant = true ;
2117
+ } else if ( key . match ( "BASE_INCLUDES" ) ) {
2118
+ relevant = true ;
2119
+ }
2120
+
2121
+ if ( ! relevant ) {
2122
+ return ;
2123
+ }
2124
+
2125
+ key += "_ANALYZER" ;
2126
+ //WARNING("KEY: " + key + " VAL: " + val);
2127
+
2128
+ fd . WriteLine ( key + "=" + val + " " ) ;
2129
+ fd . WriteBlankLines ( 1 ) ;
2130
+ }
2131
+
2060
2132
/* Generate the Makefile */
2061
2133
function generate_makefile ( )
2062
2134
{
@@ -2072,12 +2144,16 @@ function generate_makefile()
2072
2144
// The trailing space is needed to prevent the trailing backslash
2073
2145
// that is part of the build dir flags (CFLAGS_BD_XXX) from being
2074
2146
// seen as a line continuation character
2075
- MF . WriteLine ( keys [ i ] + "=" +
2076
- /* \s+\/ eliminates extra whitespace caused when using \ for string continuation,
2077
- whereby \/ is the start of the next compiler switch */
2078
- trim ( configure_subst . Item ( keys [ i ] ) ) . replace ( / \s + \/ / gm, " /" ) + " "
2079
- ) ;
2147
+
2148
+ /* \s+\/ eliminates extra whitespace caused when using \ for string continuation,
2149
+ whereby \/ is the start of the next compiler switch */
2150
+ var val = trim ( configure_subst . Item ( keys [ i ] ) ) . replace ( / \s + \/ / gm, " /" ) ;
2151
+
2152
+ MF . WriteLine ( keys [ i ] + "=" + val + " " ) ;
2080
2153
MF . WriteBlankLines ( 1 ) ;
2154
+
2155
+ /* If static analyze is enabled, add analyzer specific stuff to the Makefile. */
2156
+ handle_analyzer_makefile_flags ( MF , keys [ i ] , val ) ;
2081
2157
}
2082
2158
2083
2159
MF . WriteBlankLines ( 1 ) ;
0 commit comments