diff --git a/lib/make.rb b/lib/make.rb index be1d190..e36943f 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -56,7 +56,9 @@ module Make @steps = makefile["steps"] || [] @environment = ENV.to_h.merge( - "PREFIX" => get_prefix + "PREFIX" => get_prefix, + "CPUS" => System.cpus.to_s, + "SUDO" => (@target == :user ? "" : "sudo") ) environment = makefile["environment"] @@ -69,13 +71,22 @@ module Make end def get_prefix + sys_prefix = case System.os_name + when :macos + "/usr" + else + "" + end + case @target when :user "#{ENV["HOME"]}/.local" when :package - "/pkg/#{@name}/#{@repository.branch}" + "#{sys_prefix}/pkg/#{@name}/#{@repository.branch}" when :system - "/" + "#{sys_prefix}/" + else + raise "Unknown target: #{@target.inspect}" end end diff --git a/lib/system/debian.rb b/lib/system/debian.rb index 61170c8..6504a2f 100644 --- a/lib/system/debian.rb +++ b/lib/system/debian.rb @@ -1,8 +1,15 @@ +require 'open3' + module DebianSystem def os_name "Debian Linux" end + def cpus + stdout, stderr, status = Open3.capture3("nproc") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/lib/system/macos.rb b/lib/system/macos.rb index 7cacd3d..b2a6a22 100644 --- a/lib/system/macos.rb +++ b/lib/system/macos.rb @@ -1,8 +1,15 @@ +require 'open3' + module MacOSSystem def os_name "macOS" end + def cpus + stdout, stderr, status = Open3.capture3("sysctl -n hw.ncpu") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/recipes/dry-run.yml b/recipes/dry-run.yml index f5258b5..77e8509 100644 --- a/recipes/dry-run.yml +++ b/recipes/dry-run.yml @@ -9,7 +9,7 @@ repository: branch: main steps: - - echo installing in $PREFIX + - echo installing in $PREFIX and cpus $CPUS - cd $WORK_DIR - ls