From a4a44a37795df28f63cdeaa3a352b064359e0582 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 4 Jun 2018 13:15:36 +0900 Subject: [PATCH] Add configure script and remove more pfff artifacts --- Makefile.config | 9 +- configure | 309 +++++++++++++++++++++++++++++++++++ globals/config_flitter.ml | 2 +- globals/config_flitter.ml.in | 11 ++ globals/config_pfff.ml.in | 11 -- 5 files changed, 322 insertions(+), 20 deletions(-) create mode 100755 configure create mode 100644 globals/config_flitter.ml.in delete mode 100644 globals/config_pfff.ml.in diff --git a/Makefile.config b/Makefile.config index 992d42a..59f88b0 100644 --- a/Makefile.config +++ b/Makefile.config @@ -10,14 +10,7 @@ MANDIR=/usr/local/man LIBDIR=/usr/local/lib # Where to install the configuration files -SHAREDIR=/usr/local/share/pfff - -# Features -FEATURE_VISUAL=1 -FEATURE_FACEBOOK=0 - -FEATURE_BYTECODE=1 -FEATURE_CMT=0 +SHAREDIR=/usr/local/share/flitter OPTBIN=.opt OCAMLCFLAGS_EXTRA=-bin-annot -absname diff --git a/configure b/configure new file mode 100755 index 0000000..667644a --- /dev/null +++ b/configure @@ -0,0 +1,309 @@ +#!/usr/bin/perl +use strict; + +# this is not available in some distro :( +use Getopt::Long; +use Pod::Usage; + +###################################################################### +# Prelude +###################################################################### + +# Yes I know about autoconf ... and autoconf sucks. + +# We do not check for the following programs; we assume they are standard: +# - binutils, gcc, as, ld (the GNU toolchain) +# - make, perl, bash +# - diffutils, fileutils, findutils, grep, patchutils, sh-utils +# +#todo: +# - findutils? we need a good GNU find, not the macos find +# which adds some extra '//' in paths which bothers flitter +# - sharutils still?, for obrowser/ocsigen use of uuencode +# +# If you want to run the tests you will also need: +# - swipl +# - javac + +my $project = + "flitter"; +my $projectcmdline = + "./flitter -generate-nim "; + +###################################################################### +# Options +###################################################################### + +my $prefix="/usr/local"; + +# adjusted automatically based on local ocaml configuration +my $opt= ""; # ocamlc.opt? +my $ocamlc_flags = ""; #ocamlc -bin-annot? +my $ocaml_version = 3112; + + +my $man = 0; +my $help = 0; + +# See http://perldoc.perl.org/Getopt/Long.html +# coupling: if add options here, add an explanation at the bottom of this file +# too. Later you may also add something in the documentation latex file +# (or use LP). +GetOptions ( + "prefix=s" => \$prefix, + 'help|?' => \$help, + 'man' => \$man + ) or pod2usage(2); + #or die "$0: GetOptions: $!"; + +pod2usage(1) if $help; +pod2usage(-exitstatus => 0, -verbose => 2) if $man; + +my $src="$prefix/share/$project"; + +###################################################################### +# Helpers +###################################################################### +BEGIN { die "need Perl 5 or greater" if $] < 5 ; } + +#use Common; +sub pr2 { print STDERR "@_\n" } +sub cat { + my ($what) = @_; + my @list; + open(TMP, $what); + while() { push @list, "$_"; } + \@list; +} +sub notb { !$_[0] } +sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] } +sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } } + +sub check_config { my ($command, $expect, $msggood, $msgbad) = @_; + my $error = 0; + + my $full = cat($command); + my $res = join(" ", @{$full}); +# pr2 $res; + if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; } + else { pr2 $msggood } + return $error; +} + +sub show_error_msg_and_exit_if_error { + my ($error) = @_; + if($error) { + pr2 " +---------------------------------------------------------------------- +!!!! There seems to have a problem, we have found a missing program. +Have a look at install.txt and the install_xxx.txt corresponding to your +OS.!!!! +---------------------------------------------------------------------- +"; + exit 1; + } +#plural($error) . ". +#" . +#" . (($error > 1) ? "Some of those packages" : "This package") . +# " may be installed by picking " . ($error > 1 ? "them" : "it") . +# " in $project-dependencies.tgz available +#on the $project website. !!!! +} + +sub show_missing_package_error_msg { + my ($error2) = @_; + pr2 " +---------------------------------------------------------------------- +!!!! You can try to compile and test $project, +but some features or plugins may be missing. !!!!\n +We have found $error2 missing package" . plural($error2) . ". " . +#(($error2 > 1) ? "Some of those packages" : "This package") . +#" may be installed +#by picking " . ($error2 > 1 ? "them" : "it") . +#" in $project-dependencies.tgz available on the $project website. +#"; +" +Have a look at the install_xxx.txt corresponding to your OS. +"; +} + +###################################################################### +# Let's go +###################################################################### + +pr2 "Checking your configuration.\n"; + +# hard error, missing programs +my $error = 0; +# soft error, missing libraries, can not probably compile every flitter components +my $error2 = 0; + +my $arch = `uname`; + +#--------------------------------------------------------------------- +# Compilers and runtimes +#--------------------------------------------------------------------- +# We need at least 3.12 because I use the forall 'a. new typing feature +# as well as the '_' pattern in records (in my code but also in lib-sexp/) +$error += + check_config("echo \"1;;\\n\" | ocaml |", + "(Objective|OCaml)(.*) ([34]\.*.*)", + "OCaml (the wonderful language) is present.", + "The program ocaml is missing or is not a good version. We need at least 3.12", + ); +show_error_msg_and_exit_if_error($error); + +my $command = "echo \"1;;\\n\" | ocaml |"; +my $full = cat($command); +my $res = join(" ", @{$full}); +if ($res =~ /(Objective|OCaml)(.*) ([34])\.([0-9]+).([0-9]+)/) { + my $major = $3; + my $minor = $4; + my $other = $5; + $ocaml_version = $major * 1000 + $minor * 10 + $other; +} else { + die "wrong version of ocaml"; +} + +# allow to use ocamlc.opt instead of ocamlc, which speeds up compilation +if (`which ocamlc.opt` && `which ocamlopt.opt`) { + $opt = ".opt"; +} + +# -bin-annot is for codegraph, it needs ocaml 4.00, +# -absname is for tuareg mode under my mac, it also needs ocaml 4.00 +if($ocaml_version >= 4000) { + $ocamlc_flags="-bin-annot -absname"; +} + +#--------------------------------------------------------------- +# Developers tools +#--------------------------------------------------------------- + +my $MAKE_PROGRAM = "make"; +if( ($arch =~ /FreeBSD/) || ($arch =~ /OpenBSD/) ) { + $MAKE_PROGRAM = "gmake"; +} + +my $BREW_PROGRAM = ""; +if($arch =~ /Darwin/) { + $BREW_PROGRAM = `which brew`; +} + +#--------------------------------------------------------------------- +# More developers tools +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# Libraries +#--------------------------------------------------------------------- + +# if darwin or cygwin then could just modify this variable ? enough ? +my $prefix_distrib = "/usr"; + +if( ($arch =~ /FreeBSD/) || (($arch =~ /Darwin/) && ($BREW_PROGRAM)) ) { + $prefix_distrib = "/usr/local"; +} elsif ($arch =~ /Darwin/) { + $prefix_distrib = "/opt/local"; +} + +###################################################################### +# Generating the configuration +###################################################################### + +pr2 ""; +pr2 "$project target prefix: $prefix (you can use --prefix to override it)"; +pr2 "Generating Makefile.config (see also configure --help)"; +open(CONFIG, ">Makefile.config"); +print CONFIG "# autogenerated by configure + +# Where to install the binary +BINDIR=$prefix/bin + +# Where to install the man pages +MANDIR=$prefix/man + +# Where to install the lib +LIBDIR=$prefix/lib + +# Where to install the configuration files +SHAREDIR=$src + +OPTBIN=$opt +OCAMLCFLAGS_EXTRA=$ocamlc_flags +OCAMLVERSION=$ocaml_version +"; + + +pr2 "Generating globals/config_flitter.ml"; +`perl -p -e 's#Not_found1.\*#Not_found->\\\"$src\\\"#' globals/config_flitter.ml.in > globals/config_flitter.ml`; + +`perl -p -i -e 's#Not_found[0-9]#Not_found#' globals/config_flitter.ml`; + +if($error || $error2) { + pr2 "!!Problems during ./configure!!"; +} + +###################################################################### +# Diagnostic +###################################################################### + +if($error2) { + show_missing_package_error_msg($error2); +} else { + pr2 "All seems fine for $project."; +} + +pr2 " +To compile $project type: + \$ $MAKE_PROGRAM depend + \$ $MAKE_PROGRAM + +Then, to test $project simply type: + \$ $projectcmdline +and to run tests: + \$ make test +"; + + + +###################################################################### +# Documentation +###################################################################### + +__END__ + +=head1 NAME + +configure - setting compilation options for flitter + +=head1 SYNOPSIS + +configure [options] [--prefix=/path/to/install] + +Options are: +--prefix +--with-all + +=head1 OPTIONS + +=over 8 + + +=item B<-help> + +Print a brief help message and exits. + +=item B<-man> + +Prints the manual page and exits. + +=back + +=head1 DESCRIPTION + +B will read command line options and generate +a B and other files to set the compilation +environment for flitter. + +=cut diff --git a/globals/config_flitter.ml b/globals/config_flitter.ml index 2858bdc..3fd80e8 100644 --- a/globals/config_flitter.ml +++ b/globals/config_flitter.ml @@ -2,7 +2,7 @@ let version = "0.29" let path = try (Sys.getenv "FLITTER_HOME") - with Not_found->"./" + with Not_found->"/usr/local/share/flitter" let std_xxx = ref (Filename.concat path "xxx.yyy") diff --git a/globals/config_flitter.ml.in b/globals/config_flitter.ml.in new file mode 100644 index 0000000..a24cc44 --- /dev/null +++ b/globals/config_flitter.ml.in @@ -0,0 +1,11 @@ +let version = "0.29" + +let path = + try (Sys.getenv "FLITTER_HOME") + with Not_found1->"./" + +let std_xxx = ref (Filename.concat path "xxx.yyy") + +let logger = + try Some (Sys.getenv "FLITTER_LOGGER") + with Not_found2-> None diff --git a/globals/config_pfff.ml.in b/globals/config_pfff.ml.in deleted file mode 100644 index 0239be8..0000000 --- a/globals/config_pfff.ml.in +++ /dev/null @@ -1,11 +0,0 @@ -let version = "0.29" - -let path = - try (Sys.getenv "PFFF_HOME") - with Not_found1->"/usr/local/share/pfff" - -let std_xxx = ref (Filename.concat path "xxx.yyy") - -let logger = - try Some (Sys.getenv "PFFF_LOGGER") - with Not_found2-> None