summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Builder.cpp8
-rw-r--r--Makefile15
-rw-r--r--YMakefile9
-rw-r--r--file.cpp24
-rw-r--r--file.h8
-rw-r--r--ymake.cpp3
-rw-r--r--yscan-main.cpp6
-rw-r--r--yscan.cpp55
-rw-r--r--yscan.h4
9 files changed, 120 insertions, 12 deletions
diff --git a/Builder.cpp b/Builder.cpp
index 1f6fbb2..58176d4 100644
--- a/Builder.cpp
+++ b/Builder.cpp
@@ -1,5 +1,7 @@
#include "Builder.h"
+#include "file.h"
+
#include <algorithm>
#include <chrono>
#include <cstdlib>
@@ -107,12 +109,6 @@ namespace {
return deps_from_depfile(depfile);
}
- // type of file can be built from dependencies
- bool is_buildable_by_extension(const fs::path& p) {
- fs::path ext{p.extension()};
- return ext.empty() || ext == ".o";
- }
-
std::unordered_map<fs::path, std::vector<fs::path>> get_dependencies(const pt::ptree& ptree) {
std::unordered_map<fs::path, std::vector<fs::path>> dependencies;
dependencies.emplace(get_target(ptree), get_objects(ptree));
diff --git a/Makefile b/Makefile
index c0a8132..4a8438a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,13 @@
PROJECTNAME=ymake
-SRC=main.cpp ymake.cpp Builder.cpp ProcessRunner.cpp
-
+SRC=main.cpp ymake.cpp Builder.cpp ProcessRunner.cpp file.cpp
OBJ=$(SRC:.cpp=.o)
-all: $(PROJECTNAME)
+YSCAN=yscan
+YSCAN_SRC=yscan-main.cpp yscan.cpp file.cpp
+YSCAN_OBJ=$(YSCAN_SRC:.cpp=.o)
+
+all: $(PROJECTNAME) $(YSCAN)
LDLIBS += -lfmt -lreichwein
CXXFLAGS += -std=c++17
@@ -12,15 +15,19 @@ CXXFLAGS += -std=c++17
$(PROJECTNAME): $(OBJ)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
+$(YSCAN): $(YSCAN_OBJ)
+ $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
+
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
install:
mkdir -p $(DESTDIR)/usr/bin
cp $(PROJECTNAME) $(DESTDIR)/usr/bin/
+ cp $(YSCAN) $(DESTDIR)/usr/bin/
clean:
- -rm -f *.o $(PROJECTNAME)
+ -rm -f *.o $(PROJECTNAME) $(YSCAN)
-dh_clean
deb:
diff --git a/YMakefile b/YMakefile
index 2881c10..e0bcbc0 100644
--- a/YMakefile
+++ b/YMakefile
@@ -6,4 +6,13 @@
<source>ProcessRunner.cpp</source>
<source>ymake.cpp</source>
</build>
+ <build>
+ <name>yscan</name>
+ <source>yscan.cpp</source>
+ <source>yscan-main.cpp</source>
+ </build>
+ <test>
+ <name>test-ymake</name>
+ <source>test-ymake.cpp</source>
+ </test>
</ymake>
diff --git a/file.cpp b/file.cpp
new file mode 100644
index 0000000..823d723
--- /dev/null
+++ b/file.cpp
@@ -0,0 +1,24 @@
+#include "file.h"
+
+#include <unordered_set>
+
+namespace fs = std::filesystem;
+
+const fs::path YMakefile{"YMakefile"};
+
+// type of file can be built from dependencies
+bool is_buildable_by_extension(const fs::path& p) {
+ fs::path ext{p.extension()};
+ return ext.empty() || ext == ".o";
+}
+
+namespace {
+ std::unordered_set<fs::path> compile_unit_source_types{".cpp", ".c"};
+}
+
+// type of file is source of compile unit (no included types like headers)
+bool is_compile_unit_source_by_extension(const fs::path& p) {
+ fs::path ext{p.extension()};
+ return compile_unit_source_types.find(ext) != compile_unit_source_types.end();
+}
+
diff --git a/file.h b/file.h
new file mode 100644
index 0000000..9570266
--- /dev/null
+++ b/file.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <filesystem>
+
+extern const std::filesystem::path YMakefile;
+
+bool is_buildable_by_extension(const std::filesystem::path& p);
+bool is_compile_unit_source_by_extension(const std::filesystem::path& p);
diff --git a/ymake.cpp b/ymake.cpp
index ad46d3c..62ddeb1 100644
--- a/ymake.cpp
+++ b/ymake.cpp
@@ -1,5 +1,6 @@
#include "ymake.h"
+#include "file.h"
#include "Builder.h"
#include <algorithm>
@@ -30,8 +31,6 @@ namespace pt = boost::property_tree;
using namespace std::string_literals;
namespace {
- const fs::path YMakefile{"YMakefile"};
-
void usage()
{
std::cout << "Usage: ymake <target>" << std::endl;
diff --git a/yscan-main.cpp b/yscan-main.cpp
new file mode 100644
index 0000000..f0d2930
--- /dev/null
+++ b/yscan-main.cpp
@@ -0,0 +1,6 @@
+#include "yscan.h"
+
+int main(int argc, char* argv[])
+{
+ return yscan(argc, argv);
+}
diff --git a/yscan.cpp b/yscan.cpp
new file mode 100644
index 0000000..8dad6bf
--- /dev/null
+++ b/yscan.cpp
@@ -0,0 +1,55 @@
+#include "yscan.h"
+
+#include "file.h"
+
+#include <filesystem>
+#include <iostream>
+#include <string>
+
+#include <fmt/format.h>
+
+#include <libreichwein/file.h>
+
+namespace fs = std::filesystem;
+using namespace std::string_literals;
+
+int yscan(int argc, char* argv[])
+{
+ try {
+ std::string name {fs::current_path().stem().string()};
+
+ std::string sources;
+ std::string test_sources;
+ for (const auto& i: fs::directory_iterator(".")) {
+ fs::path p{i.path().filename()};
+ if (is_compile_unit_source_by_extension(p)) {
+ if (p.string().substr(0, 4) == "test") {
+ test_sources += " <source>" + p.string() + "</source>\n";
+ } else {
+ sources += " <source>" + p.string() + "</source>\n";
+ }
+ }
+ }
+
+ if (!test_sources.empty()) {
+ test_sources = fmt::format(R"( <test>
+ <name>{}</name>
+{} </test>
+)", "test-"s + name, test_sources);
+ }
+
+ std::string contents {R"(<ymake>
+ <build>
+ <name>{}</name>
+{} </build>
+{}</ymake>
+)"};
+ contents = fmt::format(contents, name, sources, test_sources);
+ std::cout << contents << std::endl;
+ } catch (const std::exception& ex) {
+ std::cerr << "yscan: " << ex.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}
+
diff --git a/yscan.h b/yscan.h
new file mode 100644
index 0000000..66571c5
--- /dev/null
+++ b/yscan.h
@@ -0,0 +1,4 @@
+#pragma once
+
+int yscan(int argc, char* argv[]);
+