summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Config')
-rw-r--r--Swiften/Config/.gitignore2
-rw-r--r--Swiften/Config/SConscript33
-rw-r--r--Swiften/Config/swiften-config.cpp103
3 files changed, 138 insertions, 0 deletions
diff --git a/Swiften/Config/.gitignore b/Swiften/Config/.gitignore
new file mode 100644
index 0000000..4514b26
--- /dev/null
+++ b/Swiften/Config/.gitignore
@@ -0,0 +1,2 @@
+swiften-config
+swiften-config.h
diff --git a/Swiften/Config/SConscript b/Swiften/Config/SConscript
new file mode 100644
index 0000000..962093a
--- /dev/null
+++ b/Swiften/Config/SConscript
@@ -0,0 +1,33 @@
+Import("env")
+
+def replaceSwiftenPath(input) :
+ return input.replace(env.Dir("#").abspath, "#")
+
+def cStringVariable(env, cVar, sconsVar) :
+ result = "const char* " + cVar + "[] = {\n"
+ # FIXME: Probably not very robust
+ for var in sconsVar.split(" ") :
+ result += "\t\"" + env.subst(var) + "\",\n"
+ result += "\t0\n"
+ result += "};\n"
+ return result
+
+config_flags = ""
+
+swiften_env = env.Clone()
+swiften_env.MergeFlags(swiften_env["SWIFTEN_FLAGS"])
+swiften_env.MergeFlags(swiften_env["SWIFTEN_DEP_FLAGS"])
+
+cppflags = replaceSwiftenPath(" ".join([swiften_env.subst("$_CPPDEFFLAGS"), swiften_env.subst("$_CPPINCFLAGS")]))
+config_flags += cStringVariable(swiften_env, "CPPFLAGS", cppflags)
+
+libflags = replaceSwiftenPath(" ".join([swiften_env.subst("$_LIBDIRFLAGS"), swiften_env.subst("$_LIBFLAGS")]))
+config_flags += cStringVariable(swiften_env, "LIBFLAGS", libflags)
+
+config_env = env.Clone()
+config_env.MergeFlags(config_env["SWIFTEN_FLAGS"])
+config_env.MergeFlags(config_env["BOOST_FLAGS"])
+config_env.WriteVal("swiften-config.h", config_env.Value(config_flags))
+config_env.Program("swiften-config", [
+ "swiften-config.cpp"
+ ])
diff --git a/Swiften/Config/swiften-config.cpp b/Swiften/Config/swiften-config.cpp
new file mode 100644
index 0000000..832618d
--- /dev/null
+++ b/Swiften/Config/swiften-config.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <iostream>
+
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options.hpp>
+#include <boost/version.hpp>
+
+#include <Swiften/Base/String.h>
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Platform.h>
+#include <Swiften/Base/Paths.h>
+
+#include "swiften-config.h"
+
+using namespace Swift;
+
+void printFlags(const std::vector<String>& flags) {
+ for (size_t i = 0; i < flags.size(); ++i) {
+ if (i > 0) {
+ std::cout << " ";
+ }
+ std::cout << flags[i];
+ }
+ std::cout << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ boost::program_options::options_description desc;
+ desc.add_options()
+ ("help", "Show this help message")
+ ("libs", "List the library flags")
+ ("cflags", "List the compiler & preprocessor flags")
+ ;
+ boost::program_options::variables_map vm;
+ try {
+ boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
+ } catch (boost::program_options::unknown_option option) {
+#if BOOST_VERSION >= 104200
+ std::cout << "Ignoring unknown option " << option.get_option_name() << " but continuing." << std::endl;
+#else
+ std::cout << "Error: " << option.what() << " (continuing)" << std::endl;
+#endif
+ }
+ boost::program_options::notify(vm);
+
+ if (vm.count("help") > 0) {
+ std::cout << desc << "\n";
+ return 0;
+ }
+
+ // Read in all variables
+ std::vector<String> libs;
+ for (size_t i = 0; LIBFLAGS[i]; ++i) {
+ libs.push_back(LIBFLAGS[i]);
+ }
+ std::vector<String> cflags;
+ for (size_t i = 0; CPPFLAGS[i]; ++i) {
+ cflags.push_back(CPPFLAGS[i]);
+ }
+
+ // Detect whether we're running in-place or not
+ boost::filesystem::path executablePath = Paths::getExecutablePath();
+ boost::filesystem::path topPath = executablePath / ".." / "..";
+ bool inPlace = true;
+
+ // Replace "#" variables with the correct path
+ for(size_t i = 0; i < libs.size(); ++i) {
+ if (inPlace) {
+ String lib = libs[i];
+ lib.replaceAll('#', topPath.string());
+ libs[i] = lib;
+ }
+ else {
+ // TODO
+ }
+ }
+ for(size_t i = 0; i < cflags.size(); ++i) {
+ if (inPlace) {
+ String cflag = cflags[i];
+ cflag.replaceAll('#', topPath.string());
+ cflags[i] = cflag;
+ }
+ else {
+ // TODO
+ }
+ }
+
+
+ // Print the requested variable
+ if (vm.count("libs") > 0) {
+ printFlags(libs);
+ }
+ else if (vm.count("cflags") > 0) {
+ printFlags(cflags);
+ }
+ return 0;
+}