Commits

Anonymous committed bfe5420

Add the front-ends preprocessing code.

This adds the code for preprocessing and installing the wml_frontend directory.

Comments (0)

Files changed (8)

src/CMakeLists.txt

 # see - http://www.cmake.org/Wiki/CMake_FAQ#Is_there_an_option_to_produce_more_.27verbose.27_compiling.3F
 SET(CMAKE_VERBOSE_MAKEFILE ON)
 
+SET(VERSION "2.1.1")
+
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 # TODO:
     wml_backend  
     wml_common
     wml_docs
+    wml_frontend
      )

src/wml_frontend/CMakeLists.txt

+SET (username "unknown")
+
+EXECUTE_PROCESS(COMMAND "whoami"
+    OUTPUT_VARIABLE username
+)
+
+CHOMP(username)
+
+EXECUTE_PROCESS(COMMAND "${PATH_PERL}"
+    "-MPOSIX" "-e" "print strftime('%Y-%m-%d', localtime())"
+    OUTPUT_VARIABLE date
+)
+
+FOREACH (cmd wmk wml wmb wmd wmu)
+    SET (destbase "${cmd}.pl")
+    SET (dest "${CMAKE_CURRENT_BINARY_DIR}/${destbase}")
+    SET (src "${CMAKE_CURRENT_SOURCE_DIR}/${cmd}.src")
+    SET (manname "${CMAKE_CURRENT_BINARY_DIR}/${cmd}.1")
+
+    ADD_CUSTOM_COMMAND(
+        OUTPUT "${dest}"
+        COMMAND "${PATH_PERL}"
+        ARGS "${CMAKE_CURRENT_SOURCE_DIR}/preprocess-perl-source.pl"
+            "--input" "${src}"
+            "--output" "${dest}"
+            "--subst" "WML_VERSION=${VERSION}"
+            "--subst" "WML_CONFIG_ARGS="
+            "--subst" "perlprog=${PATH_PERL}"
+            "--subst" "perlvers=${PATH_PERL}"
+            "--subst" "built_system=${CMAKE_SYSTEM_NAME}"
+            "--subst" "built_user=${username}"
+            "--subst" "built_date=${date}"
+            "--subst" "prefix=${CMAKE_INSTALL_PREFIX}"
+            "--subst" "bindir=${CMAKE_INSTALL_PREFIX}/bin"
+            "--subst" "libdir=${CMAKE_INSTALL_PREFIX}/lib"
+            "--subst" "mandir=${CMAKE_INSTALL_PREFIX}/share/man"
+            "--subst" "PATH_PERL=${PATH_PERL}"
+        DEPENDS "${src}"
+    )
+    INSTALL (FILES "${dest}" DESTINATION "bin")
+    RUN_POD2MAN("${cmd}_pod" "${src}" "${manname}" "1" "EN Tools" "EN Tools")
+    ADD_CUSTOM_TARGET(
+        "preprocess_perl_frontend_${cmd}" ALL
+        DEPENDS "${dest}"
+    )
+ENDFOREACH(cmd)

src/wml_frontend/preprocess-perl-source.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+
+my @params = (qw(
+    WML_VERSION WML_CONFIG_ARGS perlprog perlvers built_system
+    built_user built_date prefix bindir libdir mandir PATH_PERL
+    ));
+
+my %substitutions;
+
+my $input_fn;
+my $output_fn;
+
+GetOptions
+(
+    "subst=s" => \%substitutions,
+    "input=s" => \$input_fn,
+    "output=s" => \$output_fn,
+);
+
+if (!defined($input_fn))
+{
+    die "Input filename not specified!";
+}
+
+if (!defined($output_fn))
+{
+    die "Output filename not specified!";
+}
+
+verify_all_keys(
+        [sort { $a cmp $b } @params],
+        [sort { $a cmp $b } keys(%substitutions)]
+    );
+
+my $subst_keys_re = join("|", map { quotemeta($_) } @params);
+
+open my $in_fh, "<", $input_fn
+    or die "Could not open '$input_fn'";
+
+open my $out_fh, ">", $output_fn
+    or die "Could not open '$output_fn'";
+
+LINES:
+while (my $line = <$in_fh>)
+{
+    if ($line =~ /\A__END__/)
+    {
+        last LINES;
+    }
+    elsif ($line =~ /^=head1/)
+    {
+        DISCARD_POD:
+        while ($line = <$in_fh>)
+        {
+            if ($line =~ /^=cut/)
+            {
+                last DISCARD_POD;
+            }
+        }
+    }
+    else
+    {
+        $line =~ s{\@($subst_keys_re)\@}[$substitutions{$1}]eg;
+        print {$out_fh} $line;
+    }
+}
+close($in_fh);
+close($out_fh);
+
+chmod(0755, $output_fn);
+
+exit(0);
+
+sub verify_all_keys
+{
+    my ($want, $have) = @_;
+
+    for my $idx (0 .. @$want)
+    {
+        if ($want->[$idx] ne $have->[$idx])
+        {
+            die "Substitution $want->[$idx] is missing!";
+        }       
+    }
+
+    if (@$have != @$want)
+    {
+        die "Extra keys in substitution: "
+            .  join(",", @{$have}[@$want .. $#$have]) . " !";
+    }
+
+    return;
+}
+

src/wml_frontend/wmb.src

 
 $VERSION = "@WML_VERSION@";
 
-use lib "@INSTALLPRIVLIB@";
-use lib "@INSTALLARCHLIB@";
-
 use Getopt::Long 2.13;
 use Term::ReadKey;
 

src/wml_frontend/wmd.src

 
 $VERSION = "@WML_VERSION@";
 
-use lib "@INSTALLPRIVLIB@";
-use lib "@INSTALLARCHLIB@";
-
 use Getopt::Long 2.13;
 
 

src/wml_frontend/wmk.src

 
 $VERSION = "@WML_VERSION@";
 
-use lib "@INSTALLPRIVLIB@";
-use lib "@INSTALLARCHLIB@";
-
 use Term::Cap;
 use Getopt::Long 2.13;
 use Cwd;

src/wml_frontend/wml.src

 
 $VERSION = "@WML_VERSION@";
 
-use lib "@INSTALLPRIVLIB@";
-use lib "@INSTALLARCHLIB@";
-
 if ($ENV{'PATH'} !~ m|@bindir@|) {
     $ENV{'PATH'} = '@bindir@:'.$ENV{'PATH'};
 }

src/wml_frontend/wmu.src

 
 $VERSION = "@WML_VERSION@";
 
-use lib "@INSTALLPRIVLIB@";
-use lib "@INSTALLARCHLIB@";
-
 use Getopt::Long 2.13;
 use IO::Socket::INET;
 use Term::ReadKey;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.