aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-05-22 15:23:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-05-22 15:23:54 +0200
commit2b0b06cbf4288746075a74c12ef233efc929a095 (patch)
tree6fec848d888a56f718c2eaa13fba0b8a93a00d40 /build
parente7688fc3efaa79b3236b9a3775ef1a0ffaeed1b1 (diff)
Avoid relying on static initialization order
Diffstat (limited to 'build')
-rw-r--r--build/bin/target.cxx14
-rw-r--r--build/cxx/target.cxx12
-rw-r--r--build/target29
-rw-r--r--build/target.cxx30
4 files changed, 49 insertions, 36 deletions
diff --git a/build/bin/target.cxx b/build/bin/target.cxx
index cb7959c..1d69063 100644
--- a/build/bin/target.cxx
+++ b/build/bin/target.cxx
@@ -28,7 +28,7 @@ namespace build
"obja",
&file::static_type,
&obja_factory,
- file::static_type.search
+ &search_file
};
static target*
@@ -49,7 +49,7 @@ namespace build
"objso",
&file::static_type,
&objso_factory,
- file::static_type.search
+ &search_file
};
static target*
@@ -74,7 +74,7 @@ namespace build
"obj",
&target::static_type,
&obj_factory,
- target::static_type.search
+ &search_target
};
const target_type exe::static_type
@@ -83,7 +83,7 @@ namespace build
"exe",
&file::static_type,
&target_factory<exe>,
- file::static_type.search
+ &search_file
};
static target*
@@ -104,7 +104,7 @@ namespace build
"liba",
&file::static_type,
&liba_factory,
- file::static_type.search
+ &search_file
};
static target*
@@ -125,7 +125,7 @@ namespace build
"libso",
&file::static_type,
&libso_factory,
- file::static_type.search
+ &search_file
};
static target*
@@ -150,7 +150,7 @@ namespace build
"lib",
&target::static_type,
&lib_factory,
- target::static_type.search
+ &search_target
};
}
}
diff --git a/build/cxx/target.cxx b/build/cxx/target.cxx
index ab75b4c..e02801b 100644
--- a/build/cxx/target.cxx
+++ b/build/cxx/target.cxx
@@ -16,7 +16,7 @@ namespace build
"hxx",
&file::static_type,
&target_factory<hxx>,
- file::static_type.search
+ &search_file
};
const target_type ixx::static_type
@@ -25,7 +25,7 @@ namespace build
"ixx",
&file::static_type,
&target_factory<ixx>,
- file::static_type.search
+ &search_file
};
const target_type txx::static_type
@@ -34,7 +34,7 @@ namespace build
"txx",
&file::static_type,
&target_factory<txx>,
- file::static_type.search
+ &search_file
};
const target_type cxx::static_type
@@ -43,7 +43,7 @@ namespace build
"cxx",
&file::static_type,
&target_factory<cxx>,
- file::static_type.search
+ &search_file
};
const target_type h::static_type
@@ -52,7 +52,7 @@ namespace build
"h",
&file::static_type,
&target_factory<h>,
- file::static_type.search
+ &search_file
};
const target_type c::static_type
@@ -61,7 +61,7 @@ namespace build
"c",
&file::static_type,
&target_factory<c>,
- file::static_type.search
+ &search_file
};
}
}
diff --git a/build/target b/build/target
index d7bdd04..1770d9c 100644
--- a/build/target
+++ b/build/target
@@ -466,13 +466,6 @@ namespace build
extern target_type_map target_types;
- template <typename T>
- target*
- target_factory (dir_path d, std::string n, const std::string* e)
- {
- return new T (std::move (d), std::move (n), e);
- }
-
// Modification time-based target.
//
class mtime_target: public target
@@ -582,6 +575,28 @@ namespace build
virtual const target_type& type () const {return static_type;}
static const target_type static_type;
};
+
+ // Common implementation of the target factory and search functions.
+ //
+ template <typename T>
+ target*
+ target_factory (dir_path d, std::string n, const std::string* e)
+ {
+ return new T (std::move (d), std::move (n), e);
+ }
+
+ // The default behavior, that is, look for an existing target in the
+ // prerequisite's directory scope.
+ //
+ target*
+ search_target (const prerequisite_key&);
+
+ // First lookfor an existing target as above. If not found, then look
+ // for an existing file in the target-type-specific list of paths.
+ //
+ target*
+ search_file (const prerequisite_key&);
+
}
#include <build/target.ixx>
diff --git a/build/target.cxx b/build/target.cxx
index 164a13f..3810092 100644
--- a/build/target.cxx
+++ b/build/target.cxx
@@ -72,15 +72,6 @@ namespace build
return os << target_key {&t.type (), &t.dir, &t.name, &t.ext};
}
- static target*
- search_target (const prerequisite_key& pk)
- {
- // The default behavior is to look for an existing target in the
- // prerequisite's directory scope.
- //
- return search_existing_target (pk);
- }
-
// target_set
//
target_set targets;
@@ -284,10 +275,19 @@ namespace build
return path_mtime (path_);
}
- // file target
+ // Search functions.
//
- static target*
+ target*
+ search_target (const prerequisite_key& pk)
+ {
+ // The default behavior is to look for an existing target in the
+ // prerequisite's directory scope.
+ //
+ return search_existing_target (pk);
+ }
+
+ target*
search_file (const prerequisite_key& pk)
{
// First see if there is an existing target.
@@ -308,8 +308,6 @@ namespace build
return nullptr;
}
- // dir target
- //
static target*
search_alias (const prerequisite_key& pk)
{
@@ -343,7 +341,7 @@ namespace build
"mtime_target",
&target::static_type,
nullptr,
- target::static_type.search
+ &search_target
};
const target_type path_target::static_type
@@ -352,7 +350,7 @@ namespace build
"path_target",
&mtime_target::static_type,
nullptr,
- mtime_target::static_type.search
+ &search_target
};
const target_type file::static_type
@@ -379,6 +377,6 @@ namespace build
"fsdir",
&target::static_type,
&target_factory<fsdir>,
- target::static_type.search
+ &search_target
};
}