summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-03 23:39:19 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-03 23:39:19 (GMT)
commit8789133f801d3447d2ebc070659a00a2a235a22b (patch)
tree1b5187e64428cd6c49fda35d0b4f4252cea3efc1 /src
parent821c7df1fe34006ebeb0150cc0a166563d583f25 (diff)
Added handle_dep sources
Diffstat (limited to 'src')
-rw-r--r--src/handle_dep.cc42
-rw-r--r--src/handle_dep.h10
2 files changed, 52 insertions, 0 deletions
diff --git a/src/handle_dep.cc b/src/handle_dep.cc
new file mode 100644
index 0000000..2a05b4a
--- /dev/null
+++ b/src/handle_dep.cc
@@ -0,0 +1,42 @@
+#include "handle_dep.h"
+#include "myqhash.h"
+#include <string>
+#include <sstream>
+#include <QString>
+#include <QDir>
+#include <QSet>
+#include <stdlib.h> // for system()
+
+QSet<std::string> dependencies;
+const char *make_command = NULL;
+
+void handle_dep(const std::string &filename)
+{
+ if (filename[0] == '/')
+ dependencies.insert(filename);
+ else {
+ QString dep = QDir::currentPath() + QString("/") + QString::fromStdString(filename);
+ dependencies.insert(dep.toStdString());
+ }
+ if (!QFile(QString::fromStdString(filename)).exists() && make_command) {
+ std::stringstream buf;
+ buf << make_command << " '" << QString::fromStdString(filename).replace("'", "'\\''").toUtf8().data() << "'";
+ system(buf.str().c_str()); // FIXME: Handle error
+ }
+}
+
+bool write_deps(const std::string &filename, const std::string &output_file)
+{
+ FILE *fp = fopen(filename.c_str(), "wt");
+ if (!fp) {
+ fprintf(stderr, "Can't open dependencies file `%s' for writing!\n", filename.c_str());
+ return false;
+ }
+ fprintf(fp, "%s:", output_file.c_str());
+ QSetIterator<std::string> i(dependencies);
+ while (i.hasNext())
+ fprintf(fp, " \\\n\t%s", i.next().c_str());
+ fprintf(fp, "\n");
+ fclose(fp);
+ return true;
+}
diff --git a/src/handle_dep.h b/src/handle_dep.h
new file mode 100644
index 0000000..1074a64
--- /dev/null
+++ b/src/handle_dep.h
@@ -0,0 +1,10 @@
+#ifndef HANDLE_DEP_H_
+#define HANDLE_DEP_H_
+
+#include <string>
+
+extern const char *make_command;
+void handle_dep(const std::string &filename);
+bool write_deps(const std::string &filename, const std::string &output_file);
+
+#endif
contact: Jan Huwald // Impressum