#!/bin/sh for PERL in /usr/bin/perl \ /bin/perl \ /usr/local/bin/perl \ /usr/pkg/bin/perl \ /usr/athena/bin/perl \ $(which perl) { if [ -x $PERL ] then break fi } if [ ! -x $PERL ] then echo "" echo "*** Warning: Could not find perl interpreter." if [ ! -e build/Makefile.conf ] then echo "*** Creating default config file in build/Makefile.conf" echo "*** Please install perl and re-run $0" echo "VOCAL_TOOLCHAIN_TYPE := gnu VOCAL_COMPILE_TYPE := debug VOCAL_CROSS_ROOT := /skiff/local/bin BUILD_SHARED_LIBS := no USE_DISTCC := no USE_CCACHE := no USE_DTLS := no USE_SSL := yes USE_POPT := yes USE_CURL := no USE_GOOGLE_MALLOC := no USE_GOOGLE_CPUPERF := no USE_IPV6 := no INSTALL_PREFIX := /usr/local" > build/Makefile.conf exit fi echo "*** Leaving build/Makefile.conf unmodified" exit fi exec $PERL -wx $0 $@ #!perl ###################################################################### # Usage: # ./configure [-y] # # Options: # -y Run non-interactively ###################################################################### # Change directory so that we can find the Makefile.conf file $mydir = $0; $mydir =~ s/\/[^\/]*$//; chdir ($mydir); $non_interactive = 0; $uname = `uname`; @yesno = ('yes','no'); @toolchains = ('gnu','intel','armcross','sunpro','msgnu'); @compiletypes = ('debug','nodebug','opt','gopt','prof','small'); ###################################################################### # The entries in the following array have the following # fields: # # name - Variable name to be used by the make system # # description - Question to ask the user # # default - Value to use by default # # validate - Optional array of allowed values # # predicate - Optional logical test; if false, the user # will not be asked to configure the value # # flag - For "yes/no" entries, adds commandline # flags of "--enable-foo" and "--disable-foo" # # option - Adds commandline options of "--foo=..." # @parameters = ( { name => "VOCAL_TOOLCHAIN_TYPE", description => "Which toolchain do you want to use?", default => &detectToolchain, validate => [@toolchains], option => 'with-toolchain', }, { name => "VOCAL_COMPILE_TYPE", description => "What compile profile will you use?", default => "debug", validate => [@compiletypes], option => 'with-compile-type', }, { name => "VOCAL_CROSS_ROOT", description => "Where is your cross compiler installed?", default => "/skiff/local/bin", predicate => "\$config{VOCAL_TOOLCHAIN_TYPE} =~ /cross/", option => 'with-cross-compiler-dir', }, { name => "BUILD_SHARED_LIBS", description => "Should the resip libraries be built shared?", default => "no", validate => [@yesno], flag => 'shared-libs', }, { name => "USE_DISTCC", description => "Will you be using distcc?", default => &detectDistcc, validate => [@yesno], flag => 'distcc', }, { name => "USE_CCACHE", description => "Will you be using ccache?", default => "no", validate => [@yesno], flag => 'ccache', }, { name => "USE_DTLS", description => "Do you want to include DTLS support?", default => "no", validate => [@yesno], flag => 'dtls', }, { name => "USE_SSL", description => "Do you want to include SSL support?", default => "yes", validate => [@yesno], flag => 'ssl', }, { name => "USE_POPT", description => "Use popt to read commandline options?", default => "yes", validate => [@yesno], flag => 'popt', }, { name => "USE_CURL", description => "Should DUM use curl to retreive identity information?", default => "no", validate => [@yesno], flag => 'curl', }, { name => "USE_GOOGLE_MALLOC", description => "Use the Google malloc() implementation?", default => "no", validate => [@yesno], flag => 'google-malloc', }, { name => "USE_GOOGLE_CPUPERF", description => "Use Google cpuperf?", default => "no", validate => [@yesno], flag => 'google-cpuperf', }, { name => "USE_IPV6", description => "Compile in IPv6 support?", default => "no", validate => [@yesno], flag => 'ipv6', }, { name => "INSTALL_PREFIX", description => "Where should the libraries be installed?", default => "/usr/local", option => "prefix", }, ); if (open (CONF, "build/Makefile.conf")) { while () { chomp; if (/([^ :=]+) *:?= *([^ #]*)/) { $config{$1} = $2; } } close (CONF); } &parseOptions; foreach $parameter (@parameters) { if (!exists($config{$parameter->{name}})) { $config{$parameter->{name}} = $parameter->{default}; } if (exists($parameter->{predicate}) && !eval($parameter->{predicate})) { next; } # If we're running interactively, confirm with the user if (!$non_interactive) { do { if (exists($parameter->{validate}) && !&validate($config{$parameter->{name}},@{$parameter->{validate}})) { print "*** '$config{$parameter->{name}}' is not a valid value for ". "$parameter->{name}\n\n"; $config{$parameter->{name}} = $parameter->{default}; } print "".$parameter->{description}."\n"; if (exists $parameter->{validate}) { print "(".join(', ',@{$parameter->{validate}}).") "; } print "[".$config{$parameter->{name}}."] "; $userinput = readline(*STDIN); chomp ($userinput); if (length($userinput)) { $config{$parameter->{name}} = $userinput; } print "\n"; } until (!exists($parameter->{validate}) || &validate($config{$parameter->{name}},@{$parameter->{validate}})); } if (exists($parameter->{validate}) && !&validate($config{$parameter->{name}},@{$parameter->{validate}})) { print "*** '$config{$parameter->{name}}' is not a valid value for ". "$parameter->{name} -- using default: $parameter->{default}\n"; $config{$parameter->{name}} = $parameter->{default}; } } # Write out the resulting configure file to Makefile.conf open (CONF, ">build/Makefile.conf") || die "Could not write to build/Makefile.conf: $!"; print "Writing Makefile.conf...\n"; foreach $parameter (@parameters) { print CONF ("# ".$parameter->{description}."\n"); if (exists $parameter->{validate}) { print CONF ("# Allowed values: ".join(', ',@{$parameter->{validate}})."\n"); } print CONF ($parameter->{name}." := ".$config{$parameter->{name}}."\n\n"); } close (CONF); if (-e 'contrib/ares/Makefile') { system "make -C contrib/ares distclean"; } ###################################################################### sub validate { my ($value, @allowed) = @_; my ($allowed); if (@allowed == 0) { return 1; } foreach $allowed (@allowed) { if ($value eq $allowed) { return 1; } } return 0; } sub parseOptions { my($option); my($curr); option: foreach $option (@ARGV) { if ($option eq '-y' || $option eq '--non-interactive') { $non_interactive = 1; next option; } foreach $parameter (@parameters) { if (defined $parameter->{flag}) { $curr = $parameter->{flag}; if ($option =~ /^--(enable|disable)-$curr$/) { $config{$parameter->{name}} = ($1 eq 'enable'?'yes':'no'); next option; } } if (defined $parameter->{option}) { $curr = $parameter->{option}; if ($option =~ /^--$curr\=\"?([^"]*)\"?$/) { $config{$parameter->{name}} = $1; next option; } } } print "\nUnknown option: $option\n\n"; &usage; } } sub usage { print <{flag}) { print " --enable-".$parameter->{flag}."\n"; print " --disable-".$parameter->{flag}."\n"; print " ".$parameter->{description}." "; print "(Now ".($config{$parameter->{name}} eq 'yes'? "enabled":"disabled").")\n"; } if (defined $parameter->{option}) { print " --".$parameter->{option}."=\"...\"\n"; print " ".$parameter->{description}." "; print "(Now \"".$config{$parameter->{name}}."\")\n"; if (defined $parameter->{validate}) { print " Valid values are: [". join(', ',@{$parameter->{validate}})."]\n"; } } print "\n"; } exit; } ###################################################################### # Here are functions to determine reasonable defaults sub detectToolchain { if ($uname =~ /SunOS/ || $uname =~ /Solaris/) { return "sunpro"; } "gnu"; } sub detectDistcc { if ($ENV{DISTCC_HOSTS}) { return "yes"; } "no"; } __END__