Commit 7183b0c47f2ea3ab5a809cc5f154597ebdfdc9b2

Thomas de Grivel 2023-02-21T09:58:25

build, clean-build

diff --git a/lib/rbpkg.rb b/lib/rbpkg.rb
index 4ed150c..7a5ca05 100644
--- a/lib/rbpkg.rb
+++ b/lib/rbpkg.rb
@@ -147,6 +147,10 @@ module Rbpkg
     `which nproc >/dev/null 2>&1 && nproc || which sysctl >/dev/null 2>&1 && sysctl -n hw.ncpu || echo 1`.strip.to_i
   end
 
+  def self.obj_dir
+    "#{target_dir}/obj"
+  end
+
   def self.pull(repos)
     repos.each do |name|
       Repos.repo(name).pull()
diff --git a/lib/rbpkg/repo.rb b/lib/rbpkg/repo.rb
index 384aa16..75147ed 100644
--- a/lib/rbpkg/repo.rb
+++ b/lib/rbpkg/repo.rb
@@ -21,7 +21,10 @@ class Rbpkg::Repo
     if ! tag_present?("build-done")
       if File.file?("#{src_dir}/Makefile")
         cmd! "cd #{sh_quote(src_dir)} && make -j #{Rbpkg.ncpu}"
+      elsif File.file?("#{src_dir}/CMakeLists.txt")
+        cmd! "cmake -j #{Rbpkg.ncpu} --build #{sh_quote(obj_dir)}"
       end
+      tag_set("build-done")
     end
   end
 
@@ -30,6 +33,16 @@ class Rbpkg::Repo
     cmd! "cd #{sh_quote(src_dir!)} && git fetch #{sh_quote(git_remote)} #{sh_branch} && git checkout #{sh_branch} && git submodule update"
   end
 
+  def clean_build
+    if File.file?("#{src_dir}/Makefile")
+      cmd! "cd #{sh_quote(src_dir)} && make clean"
+    end
+    if File.directory?(obj_dir)
+      FileUtils.rm_rf(obj_dir)
+    end
+    tag_remove("build-done") if tag_present?("build-done")
+  end
+
   def clean_configure
     tag_remove("configure-done")
   end
@@ -123,6 +136,10 @@ class Rbpkg::Repo
     self.class.name.to_s.downcase.scan(/::([^:]*)$/)[0][0]
   end
 
+  def obj_dir
+    "#{Rbpkg.obj_dir}/#{dir}"
+  end
+
   def pull
     cmd! "cd #{sh_quote(src_dir!)} && git pull && git submodule update"
   end