module ConfigCore # The super class that stores all the settings require 'bdb1'; class Settings attr_accessor :pkgname, :version, :with_options, :toggle_options, :subst_vars; attr_accessor :languages, :cur_lang, :cache; def initialize # So the output looks proper $stdout.sync=true $stderr.sync=true printf "Welcome to the ruby based configurator thing\n\n"; printf $clear_str; printf 'Setting up the hashes'; @with_options = Hash.new; @toggle_options = Hash.new; @subst_vars = Hash.new; @languages = Hash.new; #sleep 2; printf $clear_str; printf 'Checking for a cache'; @cache = BDB1::Hash.open './cache', 'a+', 0600 unless @cache['cache_timestamp'].is_a?(NilClass) @cache['cache_timestamp']=Time::now.to_s; end #sleep 2; printf $clear_str; printf 'Filling hashes with default values'; @subst_vars['SHELL'] = '/bin/sh'; @subst_vars['exec_prefix'] = '${prefix}'; @subst_vars['datadir'] = '${prefix}/share'; @subst_vars['sysconfdir'] = '${prefix}/etc'; @subst_vars['sharedstatedir'] = '${prefix}/com'; @subst_vars['localstatedir'] = '${prefix}/var'; @subst_vars['DEFS'] = '-DHAVE_CONFIG_H'; @subst_vars['top_srcdir'] = Dir::getwd; @subst_vars['all_includes']='-I$(top_builddir)/ -I$(top_srcdir)'; #sleep 2; printf $clear_str; # Hacks! printf 'Filling hashes with ugly hacks'; @subst_vars['AUTOCONF'] = 'true'; @subst_vars['ACLOCAL'] = 'true'; @subst_vars['AUTOHEADER'] = 'true'; @subst_vars['AUTOMAKE'] = 'automake'; # This is the one we don't handle #sleep 2; printf $clear_str; end end # The class that stores information about a --with-foo commandline option class WithOption attr_accessor :default, :description, :param; def initialize (a_default, a_description) @default = a_default; @description = a_description; @param = nil.to_s; end end def rcConfigureInitialize (pkgname, version) $settings.pkgname = pkgname; $settings.version = version; $stdout.sync = true; $stderr.sync = true; printf 'Checking commandline options... '; parse_commandline; #sleep 2; printf $clear_str; # Package specific stuff $settings.subst_vars['PACKAGE'] = $settings.pkgname; $settings.subst_vars['VERSION'] = $settings.version; printf $clear_str; printf "-=[RubyConfThing script for the %s package]=-\n\n", $settings.pkgname; unless $settings.cache['cache_timestamp'].is_a?(NilClass) printf "Cache is from %s\n", $settings.cache['cache_timestamp'] else printf "No cache found. Today's date is %s\n", Time::now.to_s; end $settings.cache['cache_timestamp'] = Time::now.to_s; end def rcRegisterLanguage (lang, obj) if !lang.is_a?(String) printf "WARNING: language is not a string!\n"; end if !$settings.languages[lang] $settings.languages[lang] = obj; else printf "WARNING: The %s language has already been registered!!\n", lang; end $settings.cur_lang=lang; end def rcFindCompiler (lang) if $settings.languages[lang] $settings.languages[lang].find_compiler; else printf "WARNING: language %s not registered, could not find_compiler\n", lang; end end def rcSetLang (lang) if $settings.languages[lang] $settings.cur_lang = lang; else printf "WARNING: language %s not registered, could not set cur_lang.\n", lang end end def rcRedirect(fn) @olddefout = $defout.dup @oldstderr = $stderr.dup open(fn, 'a') do |file| $defout = file $stderr = file begin yield ensure $defout = @olddefout $stderr = @oldstderr end end end private def parse_commandline # Scan for commandline stuffs for arg in $* case arg when '--help' usage; when /--with-.*/ opt = arg.sub(/^--with-/, nil.to_s); param = nil.to_s; if /=/ =~ arg param = opt.sub(/^.*=/, nil.to_s); end opt.sub!(/=.*/, nil.to_s); if $settings.with_options[opt] != nil if ($settings.with_options[opt].default != 'with') && ($settings.with_options[opt].default != 'without') $settings.with_options[opt].param = param; elsif (param != nil) printf "Unexpected paramater at %s/%s\n", opt, param; usage; end else printf "Invalid option: %s\n", opt; usage; end when /--.*/ print 'Unknown arg ' + arg + '\n'; usage; when /./ printf "Unexpected %s\n", arg; usage; # Since this was unexpected end end end def usage print "usage\n"; $settings.with_options.each {|key,value| #status = (value.default == 'with') ? 'without' : 'with'; arg = nil.to_s; case value.default when 'with' status = 'without'; when 'without' status = 'with'; when /./ status = 'with'; arg = '=' + value.default; end printf "\t--%s-%s%s\t%s\n", status, key, arg, value.description } exit 2; end # Define some global variables unless $no_term_tricks $clear_str = sprintf '%c%s%c', 0x0d, ' '*79, 0x0d; else $clear_str = "\n"; end $settings = Settings.new; end include ConfigCore;