diff --git a/src/libCom/env/RULES b/src/libCom/env/RULES index 24e1522cd..f63475d25 100644 --- a/src/libCom/env/RULES +++ b/src/libCom/env/RULES @@ -9,4 +9,4 @@ envData.c: $(LIBCOM)/env/envDefs.h $(LIBCOM)/env/bldEnvData.pl \ $(CONFIG)/CONFIG_ENV $(CONFIG)/CONFIG_SITE_ENV - $(PERL) $(LIBCOM)/env/bldEnvData.pl $(CONFIG) + $(PERL) $(LIBCOM)/env/bldEnvData.pl $(INSTALL_QUIETLY) $(CONFIG) diff --git a/src/libCom/env/bldEnvData.pl b/src/libCom/env/bldEnvData.pl index d8a44ad3f..0382b0904 100644 --- a/src/libCom/env/bldEnvData.pl +++ b/src/libCom/env/bldEnvData.pl @@ -1,125 +1,115 @@ #!/usr/bin/perl #************************************************************************* -# Copyright (c) 2002 The University of Chicago, as Operator of Argonne +# Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. # Copyright (c) 2002 The Regents of the University of California, as # Operator of Los Alamos National Laboratory. -# EPICS BASE Versions 3.13.7 -# and higher are distributed subject to a Software License Agreement found -# in file LICENSE that is included with this distribution. +# EPICS BASE is distributed subject to a Software License Agreement found +# in file LICENSE that is included with this distribution. #************************************************************************* # -# Author: Kay-Uwe Kasemir -# based on bldEnvData shell scripts, Andrew Johnson (RGO) -# Date: 1-30-97 -# -# Experimental Physics and Industrial Control System (EPICS) -# -# tool to build envData.c from envDefs.h and config/CONFIG*ENV +# Author: Kay-Uwe Kasemir +# Date: 1-30-97 -use Cwd 'abs_path'; +use strict; -# We need exactly one argument: -$usage="Usage:\tbldEnvData "; -die $usage unless $#ARGV==0; +use lib '../../../lib/perl'; -$config_dir = abs_path($ARGV[0]); -$config_env = "${config_dir}/CONFIG_ENV"; -$config_site_env = "${config_dir}/CONFIG_SITE_ENV"; +use Getopt::Std; +use File::Basename; +use EPICS::Path; +use EPICS::Release; +use Text::Wrap; -$env_dir = abs_path("../env"); -$env_defs = "${env_dir}/envDefs.h"; +my $tool = basename($0); -$out_name = "envData.c"; +our ($opt_h, $opt_q); +our $opt_o = 'envData.c'; -# $tool = basename of this script -$tool=$0; -$tool=~ s'.*/''; +$Getopt::Std::OUTPUT_HELP_VERSION = 1; +$Text::Wrap::columns = 75; +&HELP_MESSAGE unless getopts('ho:q') && @ARGV == 1; +&HELP_MESSAGE if $opt_h; -# Start by extracting the ENV_PARAM declarations from $env_defs -# i.e. gather the names of params we are interested in: +my $config = AbsPath(shift); +my $env_defs = AbsPath('../env/envDefs.h'); + +# Parse the ENV_PARAM declarations in envDefs.h +# to get the param names we are interested in # -open SRC, "<$env_defs" or die "Cannot open $env_defs"; +open SRC, '<', $env_defs + or die "$tool: Cannot open $env_defs: $!\n"; + +my @vars; while () { - if (m/epicsShareExtern\s+const\s+ENV_PARAM\s+([A-Za-z_]\w*)\s*;/) { - $need_var{$1} = 1; - } + if (m/epicsShareExtern\s+const\s+ENV_PARAM\s+([A-Za-z_]\w*)\s*;/) { + push @vars, $1; + } } close SRC; +# Read the values from the CONFIG_ENV and CONFIG_SITE_ENV files +# +my $config_env = "$config/CONFIG_ENV"; +my $config_site_env = "$config/CONFIG_SITE_ENV"; -# Read the default values from the config file into shell variables -sub GetVars { - my ($filename) = @_; - open IN, "<$filename" or die "Cannot read $filename"; - while () { - # Discard comments, carriage returns and trailing whitespace - next if m/^ \s* \#/x; - chomp; - if (m/^ \s* ([A-Za-z_]\w*) \s* = \s* ( \S* | ".*" ) \s* $/x) { - my ($var, $val) = ($1, $2); - next unless $need_var{$var}; - $val =~ s/^"(.*)"$/$1/; - $value{$var} = $val; - } - } - close IN; +my %values; +readReleaseFiles($config_env, \%values); +readReleaseFiles($config_site_env, \%values); + +# Warn about any vars with no value +# +my @undefs = grep {!exists $values{$_}} @vars; +warn "$tool: No value given for $_\n" foreach @undefs; + +print "Generating $opt_o\n" unless $opt_q; + +# Start creating the output +# +open OUT, '>', $opt_o + or die "$tool: Cannot create $opt_o: $!\n"; + +print OUT << "END"; +/* Generated file $opt_o + * + * Created from + * $env_defs + * $config_env + * $config_site_env + */ + +#include +#define epicsExportSharedSymbols +#include "envDefs.h" + +END + +# Define all parameters, giving variable name and default value +# +foreach my $var (@vars) { + my $default = $values{$var} || ''; + $default =~ s/^"//; + $default =~ s/"$//; + + print OUT "epicsShareDef const ENV_PARAM $var =\n", + " {\"$var\", \"$default\"};\n"; } -GetVars ($config_env); -GetVars ($config_site_env); - -# Generate header file +# Now create a list of all those parameters # - -print "Generating $out_name\n"; - -open OUT, ">$out_name" or die "cannot create $out_name"; - -# Write header -print OUT "/* $out_name\n", - " *\n", - " * Created " . localtime() . "\n", - " * by $tool from files:\n", - " *\t$env_defs\n", - " *\t$config_env\n", - " *\t$config_site_env\n", - " */\n", - "\n", - "#define epicsExportSharedSymbols\n", - "#include \"envDefs.h\"\n", - "\n"; - - -# Print variables -# -@vars = sort keys %need_var; -foreach $var (@vars) { - $default = exists $value{$var} ? $value{$var} : ""; - print "Warning: No default value found for $var\n" - unless exists $value{$var}; - - print OUT "epicsShareDef const ENV_PARAM $var =\n", - "\t{\"$var\", \"$default\"};\n"; -} - -# Now create an array pointing to all parameters - print OUT "\n", - "epicsShareDef const ENV_PARAM* env_param_list[] = {\n"; - -# Contents are the addresses of each parameter -foreach $var (@vars) { - print OUT "\t&$var,\n"; -} - -# Finally finish list with 0 -print OUT "\t0\n", - "};\n", - "\n", - "/*\tEOF $out_name */\n"; - + "epicsShareDef const ENV_PARAM* env_param_list[] = {\n", + wrap(' ', ' ', join(', ', map("&$_", @vars), 'NULL')), + "\n};\n"; close OUT; -# EOF bldEnvData.pl +sub HELP_MESSAGE { + print STDERR "Usage: $tool [options] configure\n", + " -h Help: Print this message\n", + " -q Quiet: Only print errors\n", + " -o file Output filename, default is $opt_o\n", + "\n"; + + exit 1; +} diff --git a/src/libCom/misc/RULES b/src/libCom/misc/RULES index 7cf9254e3..ddcce46a2 100644 --- a/src/libCom/misc/RULES +++ b/src/libCom/misc/RULES @@ -7,7 +7,12 @@ # This is a Makefile fragment, see src/libCom/Makefile. -$(COMMON_DIR)/epicsVersion.h: $(CONFIG)/CONFIG_BASE_VERSION \ - $(CONFIG)/CONFIG_SITE $(LIBCOM)/misc/makeEpicsVersion.pl - $(PERL) $(LIBCOM)/misc/makeEpicsVersion.pl $(CONFIG)/CONFIG_BASE_VERSION $(@D) $(EPICS_SITE_VERSION) +MAKEVERSION = $(LIBCOM)/misc/makeEpicsVersion.pl +MAKEVERSION_FLAGS = -o $(notdir $@) $(INSTALL_QUIETLY) +MAKEVERSION_FLAGS += $(if $(EPICS_SITE_VERSION),-v "$(EPICS_SITE_VERSION)") +$(COMMON_DIR)/epicsVersion.h: $(CONFIG)/CONFIG_BASE_VERSION \ + $(CONFIG)/CONFIG_SITE $(MAKEVERSION) + @$(RM) $(notdir $@) + $(PERL) $(MAKEVERSION) $(MAKEVERSION_FLAGS) $< + @$(MV) $(notdir $@) $@ diff --git a/src/libCom/misc/makeEpicsVersion.pl b/src/libCom/misc/makeEpicsVersion.pl index 9678c8fc8..2a720e86d 100644 --- a/src/libCom/misc/makeEpicsVersion.pl +++ b/src/libCom/misc/makeEpicsVersion.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl #************************************************************************* -# Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne +# Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. # Copyright (c) 2002 The Regents of the University of California, as # Operator of Los Alamos National Laboratory. @@ -10,18 +10,27 @@ use strict; -my ($ver, $rev, $mod, $patch, $snapshot, $commit_date); +use Getopt::Std; +use File::Basename; -my ($infile, $outdir, $site_ver) = @ARGV; +my $tool = basename($0); -die "Usage: perl makeEpicsVersion.pl CONFIG_BASE_VERSION outdir siteversion" - unless ($infile && $outdir); +our ($opt_h, $opt_q, $opt_v); +our $opt_o = 'epicsVersion.h'; -print "Building epicsVersion.h from $infile\n"; +$Getopt::Std::OUTPUT_HELP_VERSION = 1; + +&HELP_MESSAGE unless getopts('ho:qv:') && @ARGV == 1; +&HELP_MESSAGE if $opt_h; + +my ($infile) = @ARGV; + +print "Building $opt_o from $infile\n" unless $opt_q; open my $VARS, '<', $infile - or die "Can't open $infile: $!\n"; + or die "$tool: Can't open $infile: $!\n"; +my ($ver, $rev, $mod, $patch, $snapshot, $commit_date); while (<$VARS>) { chomp; next if m/^\s*#/; # Skip comments @@ -35,46 +44,50 @@ while (<$VARS>) { close $VARS; map { - die "Variable missing from $infile" unless defined $_; + die "$tool: Variable missing from $infile" unless defined $_; } $ver, $rev, $mod, $patch, $snapshot, $commit_date; my $ver_str = "$ver.$rev.$mod"; $ver_str .= ".$patch" if $patch > 0; $ver_str .= $snapshot if $snapshot ne ''; -$ver_str .= "-$site_ver" if $site_ver; +$ver_str .= "-$opt_v" if $opt_v; -print "Found EPICS Version $ver_str\n"; +print "Found EPICS Version $ver_str\n" unless $opt_q; -my $epicsVersion="$outdir/epicsVersion.h"; +open my $OUT, '>', $opt_o + or die "$tool: Can't create $opt_o: $!\n"; -mkdir ($outdir, 0777) unless -d $outdir; +my $obase = basename($opt_o, '.h'); -open my $OUT, '>', $epicsVersion - or die "Cannot create $epicsVersion: $!\n"; +print $OUT <<"END"; +/* Generated file $opt_o */ -print $OUT <<"END_OUTPUT"; -/* Generated epicsVersion.h */ - -#ifndef INC_epicsVersion_H -#define INC_epicsVersion_H +#ifndef INC_${obase}_H +#define INC_${obase}_H #define EPICS_VERSION $ver #define EPICS_REVISION $rev #define EPICS_MODIFICATION $mod #define EPICS_PATCH_LEVEL $patch #define EPICS_DEV_SNAPSHOT "$snapshot" -#define EPICS_SITE_VERSION "$site_ver" +#define EPICS_SITE_VERSION "$opt_v" #define EPICS_VERSION_STRING "EPICS $ver_str" #define epicsReleaseVersion "EPICS R$ver_str $commit_date" #define VERSION_INT(V,R,M,P) ( ((V)<<24) | ((R)<<16) | ((M)<<8) | (P)) #define EPICS_VERSION_INT VERSION_INT($ver, $rev, $mod, $patch) -/* The following names are deprecated, use the equivalent name above */ -#define EPICS_UPDATE_LEVEL EPICS_PATCH_LEVEL -#define EPICS_CVS_SNAPSHOT EPICS_DEV_SNAPSHOT - -#endif /* INC_epicsVersion_H */ -END_OUTPUT +#endif /* INC_${obase}_H */ +END close $OUT; + +sub HELP_MESSAGE { + print STDERR "Usage: $tool [options] CONFIG_BASE_VERSION\n", + " -h Help: Print this message\n", + " -q Quiet: Only print errors\n", + " -o file Output filename, default is $opt_o\n", + " -v vers Site-specific version string\n", + "\n"; + exit 1; +}