From 154ce9b1ce22532a68f95f2291fa12fd90c49fde Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Jun 2021 14:10:36 +0200 Subject: Make sources relative to the build-file (include paths are still relative to project rootdir). Add -b to control build-dir. --- Makefile | 4 +- libcppbuild.cc | 66 ++++++++++++++++----------- subdir/cppbuild.cc | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ subdir/cppbuild2.cc | 125 ---------------------------------------------------- task_cc.cc | 5 ++- task_cc.h | 2 +- 6 files changed, 172 insertions(+), 155 deletions(-) create mode 100644 subdir/cppbuild.cc delete mode 100644 subdir/cppbuild2.cc diff --git a/Makefile b/Makefile index 507d841..9b7e035 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ CXXFLAGS = -g -O3 -std=c++17 -I. libcppbuild.a: $(OBJ) ar rcs $@ $(OBJ) -cppbuild: cppbuild.cc libcppbuild.a - g++ $(CXXFLAGS) -pthread cppbuild.cc libcppbuild.a -o $@ +cppbuild: cppbuild.cc subdir/cppbuild.cc libcppbuild.a + g++ $(CXXFLAGS) -pthread cppbuild.cc subdir/cppbuild.cc libcppbuild.a -o $@ clean: rm -f libcppbuild.a $(OBJ) cppbuild diff --git a/libcppbuild.cc b/libcppbuild.cc index d58705d..f641a90 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -26,7 +27,8 @@ using namespace std::chrono_literals; std::list> taskFactory(const BuildConfiguration& config, - const Settings& settings) + const Settings& settings, + const std::string& sourceDir) { std::filesystem::path targetFile(config.target); @@ -34,7 +36,8 @@ std::list> taskFactory(const BuildConfiguration& config, std::list> tasks; for(const auto& file : config.sources) { - tasks.emplace_back(std::make_shared(config, settings, file)); + tasks.emplace_back(std::make_shared(config, settings, + sourceDir, file)); objects.push_back(tasks.back()->target()); } @@ -93,8 +96,7 @@ std::array configFiles; int numConfigFiles{0}; // TODO: Use c++20 when ready, somehing like this: -//void reg(const std::source_location location = -// std::source_location::current()) +//int reg(const std::source_location location = std::source_location::current()) int reg(const char* location, std::vector (*cb)()) { @@ -105,7 +107,7 @@ int reg(const char* location, return 0; } -void recompileCheck(int argc, char* argv[]) +void recompileCheck(const Settings& settings, int argc, char* argv[]) { bool dirty{false}; @@ -117,11 +119,18 @@ void recompileCheck(int argc, char* argv[]) std::filesystem::path binFile("cppbuild"); - std::cout << "Recompile check (" << numConfigFiles << "):\n"; + if(settings.verbose > 1) + { + std::cout << "Recompile check (" << numConfigFiles << "):\n"; + } + for(int i = 0; i < numConfigFiles; ++i) { std::string location = configFiles[i].file; - std::cout << " - " << location << "\n"; + if(settings.verbose > 1) + { + std::cout << " - " << location << "\n"; + } std::filesystem::path configFile(location); if(std::filesystem::last_write_time(binFile) <= std::filesystem::last_write_time(configFile)) @@ -163,21 +172,17 @@ void recompileCheck(int argc, char* argv[]) int main(int argc, char* argv[]) { - recompileCheck(argc, argv); - - Settings settings; - // TODO: Set from commandline - settings.builddir = "build/foo"; + Settings settings{}; + settings.builddir = "build/"; settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency() * 2 - 1); - settings.verbose = 0; dg::Options opt; opt.add("jobs", required_argument, 'j', - "Number of parallel jobs.", + "Number of parallel jobs. (default: cpucount * 2 - 1 )", [&]() { try { @@ -191,8 +196,15 @@ int main(int argc, char* argv[]) return 0; }); + opt.add("build-dir", required_argument, 'b', + "Set output directory for build files (default: build).", + [&]() { + settings.builddir = optarg; + return 0; + }); + opt.add("verbose", no_argument, 'v', - "Be verbose.", + "Be verbose. Add multiple times for more verbosity.", [&]() { settings.verbose++; return 0; @@ -208,28 +220,32 @@ int main(int argc, char* argv[]) opt.process(argc, argv); + recompileCheck(settings, argc, argv); + std::filesystem::path builddir(settings.builddir); std::filesystem::create_directories(builddir); - std::vector build_configs; + std::deque build_configs; + std::list> tasks; for(int i = 0; i < numConfigFiles; ++i) { - //std::string location = configFiles[i].file; + std::string path = + std::filesystem::path(configFiles[i].file).parent_path(); + if(settings.verbose > 1) + { + std::cout << configFiles[i].file << " in path " << path << "\n"; + } auto configs = configFiles[i].cb(); for(const auto& config : configs) { build_configs.push_back(config); + const auto& build_config = build_configs.back(); + std::vector objects; + auto t = taskFactory(build_config, settings, path); + tasks.insert(tasks.end(), t.begin(), t.end()); } } - std::list> tasks; - for(const auto& build_config : build_configs) - { - std::vector objects; - auto t = taskFactory(build_config, settings); - tasks.insert(tasks.end(), t.begin(), t.end()); - } - for(auto task : tasks) { task->registerDepTasks(tasks); diff --git a/subdir/cppbuild.cc b/subdir/cppbuild.cc new file mode 100644 index 0000000..808ac41 --- /dev/null +++ b/subdir/cppbuild.cc @@ -0,0 +1,125 @@ +#if 0/* +if [ "cppbuild" -ot "$0" ] +then + echo "Rebuilding cppbuild" + g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild + [ $? != 0 ] && exit 1 +fi + +echo "Launching cppbuild" +./cppbuild $* +exit $? +*/ +#endif + +#include +#include +#include + +#include "../libcppbuild.h" + +/* +Nested build configurations for for example unit-tests in a test folder +#include "test/cppbuild.cc" +*/ + +/* +Glob convenience methods +std::string glob = getFilesInDir(...); +*/ + +/* +Compilation database +https://clang.llvm.org/docs/JSONCompilationDatabase.html +*/ + +/* +En feature mere kunne være: pre-post build hooks +De vil kunne udtrykkes som intra-build dependencies +Og så selvfølgelig med conditions +*/ + +/* +Target som er "shell script" eller sådan noget +så kan man kalde f.eks. imageconvert +*/ + +/* +Compiler selection per-target (for arm cross-compilation) +*/ +namespace +{ +std::vector myConfigs() +{ + return + { + { + .target = "src.a", + .sources = { + "../drumgizmo/src/audiocache.cc", + "../drumgizmo/src/audiocacheeventhandler.cc", + "../drumgizmo/src/audiocachefile.cc", + "../drumgizmo/src/audiocacheidmanager.cc", + "../drumgizmo/src/audiofile.cc", + "../drumgizmo/src/audioinputengine.cc", + "../drumgizmo/src/audioinputenginemidi.cc", + "../drumgizmo/src/audiooutputengine.cc", + "../drumgizmo/src/bytesizeparser.cc", + "../drumgizmo/src/channel.cc", + "../drumgizmo/src/channelmixer.cc", + "../drumgizmo/src/configfile.cc", + "../drumgizmo/src/configparser.cc", + "../drumgizmo/src/dgxmlparser.cc", + "../drumgizmo/src/directory.cc", + "../drumgizmo/src/domloader.cc", + "../drumgizmo/src/drumgizmo.cc", + "../drumgizmo/src/drumgizmoconf.cc", + "../drumgizmo/src/drumkit.cc", + "../drumgizmo/src/drumkitloader.cc", + "../drumgizmo/src/events.cc", + "../drumgizmo/src/events_ds.cc", + "../drumgizmo/src/inputprocessor.cc", + "../drumgizmo/src/instrument.cc", + "../drumgizmo/src/latencyfilter.cc", + "../drumgizmo/src/midimapparser.cc", + "../drumgizmo/src/midimapper.cc", + "../drumgizmo/src/path.cc", + "../drumgizmo/src/powerlist.cc", + "../drumgizmo/src/powermap.cc", + "../drumgizmo/src/powermapfilter.cc", + "../drumgizmo/src/random.cc", + "../drumgizmo/src/sample.cc", + "../drumgizmo/src/sample_selection.cc", + "../drumgizmo/src/sem.cc", + "../drumgizmo/src/staminafilter.cc", + "../drumgizmo/src/thread.cc", + "../drumgizmo/src/translation.cc", + "../drumgizmo/src/velocityfilter.cc", + "../drumgizmo/src/versionstr.cc", + "../drumgizmo/src/zrwrapper.cc", + }, + .depends = {}, + .cxxflags = { + "-fPIC", + "-DUI_X11", + "-O3", + "-g", + "-Wall", + "-Werror", + "-std=c++11", + "-Idrumgizmo/getoptpp", + "-Idrumgizmo/", + "-Idrumgizmo/hugin", + "-Idrumgizmo/plugingui/", + "-Idrumgizmo/src/", + "-Idrumgizmo/zita-resampler/libs", + "-Idrumgizmo/pugixml/src", + }, + .cflags = {}, + .ldflags = {} + } + }; +} + +int a = reg(__FILE__, myConfigs); +} diff --git a/subdir/cppbuild2.cc b/subdir/cppbuild2.cc deleted file mode 100644 index 374319d..0000000 --- a/subdir/cppbuild2.cc +++ /dev/null @@ -1,125 +0,0 @@ -#if 0/* -if [ "cppbuild" -ot "$0" ] -then - echo "Rebuilding cppbuild" - g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild - [ $? != 0 ] && exit 1 -fi - -echo "Launching cppbuild" -./cppbuild $* -exit $? -*/ -#endif - -#include -#include -#include - -#include "../libcppbuild.h" - -/* -Nested build configurations for for example unit-tests in a test folder -#include "test/cppbuild.cc" -*/ - -/* -Glob convenience methods -std::string glob = getFilesInDir(...); -*/ - -/* -Compilation database -https://clang.llvm.org/docs/JSONCompilationDatabase.html -*/ - -/* -En feature mere kunne være: pre-post build hooks -De vil kunne udtrykkes som intra-build dependencies -Og så selvfølgelig med conditions -*/ - -/* -Target som er "shell script" eller sådan noget -så kan man kalde f.eks. imageconvert -*/ - -/* -Compiler selection per-target (for arm cross-compilation) -*/ -namespace -{ -std::vector myConfigs() -{ - return - { - { - .target = "src.a", - .sources = { - "drumgizmo/src/audiocache.cc", - "drumgizmo/src/audiocacheeventhandler.cc", - "drumgizmo/src/audiocachefile.cc", - "drumgizmo/src/audiocacheidmanager.cc", - "drumgizmo/src/audiofile.cc", - "drumgizmo/src/audioinputengine.cc", - "drumgizmo/src/audioinputenginemidi.cc", - "drumgizmo/src/audiooutputengine.cc", - "drumgizmo/src/bytesizeparser.cc", - "drumgizmo/src/channel.cc", - "drumgizmo/src/channelmixer.cc", - "drumgizmo/src/configfile.cc", - "drumgizmo/src/configparser.cc", - "drumgizmo/src/dgxmlparser.cc", - "drumgizmo/src/directory.cc", - "drumgizmo/src/domloader.cc", - "drumgizmo/src/drumgizmo.cc", - "drumgizmo/src/drumgizmoconf.cc", - "drumgizmo/src/drumkit.cc", - "drumgizmo/src/drumkitloader.cc", - "drumgizmo/src/events.cc", - "drumgizmo/src/events_ds.cc", - "drumgizmo/src/inputprocessor.cc", - "drumgizmo/src/instrument.cc", - "drumgizmo/src/latencyfilter.cc", - "drumgizmo/src/midimapparser.cc", - "drumgizmo/src/midimapper.cc", - "drumgizmo/src/path.cc", - "drumgizmo/src/powerlist.cc", - "drumgizmo/src/powermap.cc", - "drumgizmo/src/powermapfilter.cc", - "drumgizmo/src/random.cc", - "drumgizmo/src/sample.cc", - "drumgizmo/src/sample_selection.cc", - "drumgizmo/src/sem.cc", - "drumgizmo/src/staminafilter.cc", - "drumgizmo/src/thread.cc", - "drumgizmo/src/translation.cc", - "drumgizmo/src/velocityfilter.cc", - "drumgizmo/src/versionstr.cc", - "drumgizmo/src/zrwrapper.cc", - }, - .depends = {}, - .cxxflags = { - "-fPIC", - "-DUI_X11", - "-O3", - "-g", - "-Wall", - "-Werror", - "-std=c++11", - "-Idrumgizmo/getoptpp", - "-Idrumgizmo/", - "-Idrumgizmo/hugin", - "-Idrumgizmo/plugingui/", - "-Idrumgizmo/src/", - "-Idrumgizmo/zita-resampler/libs", - "-Idrumgizmo/pugixml/src", - }, - .cflags = {}, - .ldflags = {} - } - }; -} - -int a = reg(__FILE__, myConfigs); -} diff --git a/task_cc.cc b/task_cc.cc index 4340f7b..f827c25 100644 --- a/task_cc.cc +++ b/task_cc.cc @@ -84,12 +84,13 @@ std::vector readDeps(const std::string& depFile) } // namespace :: TaskCC::TaskCC(const BuildConfiguration& config, const Settings& settings, - const std::string& source) + const std::string& sourceDir, const std::string& source) : Task({}) , config(config) , settings(settings) { - sourceFile = source; + sourceFile = sourceDir; + sourceFile /= source; targetFile = settings.builddir / sourceFile.stem(); targetFile += ".o"; diff --git a/task_cc.h b/task_cc.h index 63ae623..f88433f 100644 --- a/task_cc.h +++ b/task_cc.h @@ -17,7 +17,7 @@ class TaskCC public: TaskCC(const BuildConfiguration& config, const Settings& settings, - const std::string& source); + const std::string& sourceDir, const std::string& source); bool dirtyInner() override; -- cgit v1.2.3