Skip to content

Commit 8289f11

Browse files
committed
fix file lists with subdirs passed to EXTENSION()
The underlying place responsible is the ADD_SOURCES() function. With this, the calls like EXTENSION("hello", "sub0/file0.c sub1/file1.c", ...) are working correctly. Same for ADD_SOURCES("some/dir", "sub0/file0.c sub1/file1.c", ...)
1 parent c9357f8 commit 8289f11

File tree

1 file changed

+92
-57
lines changed

1 file changed

+92
-57
lines changed

win32/build/confutils.js

+92-57
Original file line numberDiff line numberDiff line change
@@ -1445,83 +1445,118 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
14451445

14461446
dir = dir.replace(new RegExp("/", "g"), "\\");
14471447
var objs_line = "";
1448-
var srcs_line = "";
14491448

14501449
var sub_build = "$(BUILD_DIR)\\";
14511450

1452-
/* if module dir is not a child of the main source dir,
1453-
* we need to tweak it; we should have detected such a
1454-
* case in condense_path and rewritten the path to
1455-
* be relative.
1456-
* This probably breaks for non-sibling dirs, but that
1457-
* is not a problem as buildconf only checks for pecl
1458-
* as either a child or a sibling */
1459-
if (obj_dir == null) {
1460-
var build_dir = dir.replace(new RegExp("^..\\\\"), "");
1461-
var mangle_dir = build_dir.replace(new RegExp("[\\\\/.-]", "g"), "_");
1462-
var bd_flags_name = "CFLAGS_BD_" + mangle_dir.toUpperCase();
1463-
}
1464-
else {
1465-
var build_dir = obj_dir.replace(new RegExp("^..\\\\"), "");
1466-
var mangle_dir = build_dir.replace(new RegExp("[\\\\/.-]", "g"), "_");
1467-
var bd_flags_name = "CFLAGS_BD_" + mangle_dir.toUpperCase();
1468-
}
1451+
var srcs_line = "";
1452+
var objs_line = "";
1453+
14691454

1470-
var dirs = build_dir.split("\\");
1471-
var i, d = "";
1472-
for (i = 0; i < dirs.length; i++) {
1473-
d += dirs[i];
1474-
build_dirs[build_dirs.length] = d;
1475-
d += "\\";
1476-
}
1477-
sub_build += d;
1455+
var srcs_by_dir = {};
14781456

1457+
/* Parse the file list to create an aggregated structure based on the subdirs passed. */
1458+
for (i in file_list) {
1459+
src = file_list[i];
14791460

1480-
DEFINE(bd_flags_name, "/Fp" + sub_build + " /FR" + sub_build + " ");
1481-
if (VS_TOOLSET) {
1482-
ADD_FLAG(bd_flags_name, "/Fd" + sub_build);
1461+
var _tmp = src.split("\\");
1462+
1463+
var filename = _tmp.pop();
1464+
1465+
// build the obj out dir and use it as a key
1466+
var dirname = _tmp.join("\\");
1467+
1468+
//WARNING("dir: " + dir + " dirname: " + dirname + " filename: " + filename);
1469+
1470+
/* if module dir is not a child of the main source dir,
1471+
* we need to tweak it; we should have detected such a
1472+
* case in condense_path and rewritten the path to
1473+
* be relative.
1474+
* This probably breaks for non-sibling dirs, but that
1475+
* is not a problem as buildconf only checks for pecl
1476+
* as either a child or a sibling */
1477+
if (obj_dir == null) {
1478+
var build_dir = (dirname ? (dir + "\\" + dirname) : dir).replace(new RegExp("^..\\\\"), "");
1479+
}
1480+
else {
1481+
var build_dir = obj_dir.replace(new RegExp("^..\\\\"), "");
1482+
}
1483+
1484+
obj = sub_build + build_dir + "\\" + filename.replace(re, ".obj");
1485+
1486+
if (i > 0) {
1487+
srcs_line += " " + dir + "\\" + src;
1488+
objs_line += " " + obj
1489+
} else {
1490+
srcs_line = dir + "\\" + src;
1491+
objs_line = obj;
1492+
}
1493+
1494+
resp += " " + obj.replace('$(BUILD_DIR)', bd);
1495+
tv += " " + obj;
1496+
1497+
if (!srcs_by_dir.hasOwnProperty(build_dir)) {
1498+
srcs_by_dir[build_dir] = [];
1499+
}
1500+
1501+
/* storing the index from the file_list */
1502+
srcs_by_dir[build_dir].push(i);
14831503
}
14841504

1485-
for (i in file_list) {
1486-
src = file_list[i];
1487-
obj = src.replace(re, ".obj");
1488-
tv += " " + sub_build + obj;
1489-
resp += " " + sub_build.replace('$(BUILD_DIR)', bd) + obj;
1490-
1491-
if (!PHP_MP_DISABLED) {
1492-
if (i > 0) {
1493-
objs_line += " " + sub_build + obj;
1494-
srcs_line += " " + dir + "\\" + src;
1495-
} else {
1496-
objs_line = sub_build + obj;
1497-
srcs_line = dir + "\\" + src;
1505+
/* Create makefile build targets and dependencies. */
1506+
MFO.WriteLine(objs_line + ": " + srcs_line);
1507+
1508+
/* Create target subdirs if any and produce the compiler calls, /mp is respected if enabled. */
1509+
for (var k in srcs_by_dir) {
1510+
var dirs = k.split("\\");
1511+
var i, d = "";
1512+
for (i = 0; i < dirs.length; i++) {
1513+
d += dirs[i];
1514+
build_dirs[build_dirs.length] = d;
1515+
d += "\\";
1516+
}
1517+
1518+
var mangle_dir = k.replace(new RegExp("[\\\\/.-]", "g"), "_");
1519+
var bd_flags_name = "CFLAGS_BD_" + mangle_dir.toUpperCase();
1520+
1521+
DEFINE(bd_flags_name, "/Fp" + sub_build + d + " /FR" + sub_build + d + " ");
1522+
if (VS_TOOLSET) {
1523+
ADD_FLAG(bd_flags_name, "/Fd" + sub_build + d);
1524+
}
1525+
1526+
if (PHP_MP_DISABLED) {
1527+
for (var j in srcs_by_dir[k]) {
1528+
src = file_list[srcs_by_dir[k][j]];
1529+
if (PHP_ANALYZER == "pvs") {
1530+
MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
1531+
+ " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" ");
1532+
}
1533+
1534+
var _tmp = src.split("\\");
1535+
var filename = _tmp.pop();
1536+
obj = filename.replace(re, ".obj");
1537+
1538+
MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + d + obj);
14981539
}
14991540
} else {
1500-
MFO.WriteLine(sub_build + obj + ": " + dir + "\\" + src);
1501-
1502-
if (PHP_ANALYZER == "pvs") {
1503-
MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file " + dir + "\\" + src
1504-
+ " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" ");
1541+
/* TODO create a response file at least for the source files to work around the cmd line length limit. */
1542+
var src_line = "";
1543+
for (var j in srcs_by_dir[k]) {
1544+
src_line += dir + "\\" + file_list[srcs_by_dir[k][j]] + " ";
15051545
}
1506-
MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + obj);
1507-
}
1508-
}
15091546

1510-
if (!PHP_MP_DISABLED) {
1511-
MFO.WriteLine(objs_line + ": " + srcs_line);
1512-
MFO.WriteLine("\t$(CC) $(" + flags + ") $(CFLAGS) /Fo" + sub_build + " $(" + bd_flags_name + ") /c " + srcs_line);
1547+
MFO.WriteLine("\t$(CC) $(" + flags + ") $(CFLAGS) /Fo" + sub_build + d + " $(" + bd_flags_name + ") /c " + src_line);
1548+
}
15131549
}
15141550

15151551
DEFINE(sym, tv);
15161552

1517-
/* Generate the response file and define it to the Makefile. This can be
1518-
useful when getting the "command line too long" linker errors. */
1553+
/* Generate the object response file and define it to the Makefile. This can be
1554+
useful when getting the "command line too long" linker errors.
1555+
TODO pack this into a function when response files are used for other kinds of info. */
15191556
var obj_lst_fh = null;
15201557
if (!FSO.FileExists(obj_lst_fn)) {
15211558
obj_lst_fh = FSO.CreateTextFile(obj_lst_fn);
1522-
//STDOUT.WriteLine("Creating " + obj_lst_fn);
15231559
} else {
1524-
//STDOUT.WriteLine("Appending to " + obj_lst_fn);
15251560
obj_lst_fh = FSO.OpenTextFile(obj_lst_fn, 8);
15261561
}
15271562

0 commit comments

Comments
 (0)