From d196845c85158de7b4ceb8e9417883fbd8e0fbdd Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 4 Nov 2018 00:16:53 -0400 Subject: [PATCH] parse 'configure' command-line options --- lib/rscons/application.rb | 56 ++++++++++++++++++++++++++++++++++++--- lib/rscons/cli.rb | 29 ++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 1ec38d4..63af893 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -15,23 +15,38 @@ module Rscons # Access any variables set on the rscons command-line. attr_reader :vars + # @return [String] + # Build directory (default "build"). + attr_accessor :build_dir + + # @return [String] + # Installation prefix (default "/usr/local"). + attr_accessor :prefix + def initialize - @vars = VarSet.new @n_threads = determine_n_threads + @vars = VarSet.new + @build_dir = "build" + @prefix = "/usr/local" + @default_environment = Environment.new end # Run the specified operation. # # @param operation [String] # The operation to perform (e.g. "clean", "configure", "build", etc...) + # @param script [Script] + # The script. # # @return [Integer] # Process exit code (0 on success). - def run(operation) - # TODO + def run(operation, script) + @script = script case operation when "clean" clean + when "configure" + configure end 0 end @@ -57,6 +72,41 @@ module Rscons cache.clear end + # Configure the project. + # + # @return [void] + def configure + if ccc = @script.check_c_compiler + check_c_compiler(ccc) + end + end + + # Configure: check for a working C compiler. + # + # @param ccc [Array] + # C compiler(s) to check for. + # + # @return [void] + def check_c_compiler(ccc) + if ccc.empty? + # Default C compiler search array. + ccc = %w[gcc clang] + end + cc = ccc.find do |cc| + test_c_compiler(cc) + end + end + + # Test a C compiler. + # + # @param cc [String] + # C compiler to test. + # + # @return [Boolean] + # Whether the C compiler tested successfully. + def test_c_compiler(cc) + end + # Determine the number of threads to use by default. # # @return [Integer] diff --git a/lib/rscons/cli.rb b/lib/rscons/cli.rb index cf1c8b5..2a45e1e 100644 --- a/lib/rscons/cli.rb +++ b/lib/rscons/cli.rb @@ -108,9 +108,34 @@ module Rscons if do_help puts USAGE exit 0 - else - exit Rscons.application.run(operation) end + + parse_operation_args(operation, argv) + + exit Rscons.application.run(operation, script) + end + + private + + def parse_operation_args(operation, argv) + case operation + when "configure" + parse_configure_args(argv) + end + end + + def parse_configure_args(argv) + OptionParser.new do |opts| + opts.banner = "Usage: #{$0} [options]" + + opts.on("-b", "--build DIR") do |build_dir| + Rscons.application.build_dir = build_dir + end + + opts.on("--prefix PREFIX") do |prefix| + Rscons.application.prefix = prefix + end + end.order!(argv) end end