[svn:parrot] r39899 - in trunk: . config/gen config/gen/config_h lib/Parrot

fperrad at svn.parrot.org fperrad at svn.parrot.org
Mon Jul 6 17:48:50 UTC 2009


Author: fperrad
Date: Mon Jul  6 17:48:48 2009
New Revision: 39899
URL: https://trac.parrot.org/parrot/changeset/39899

Log:
[config] refactor the generation of has_header.h with a template

Added:
   trunk/config/gen/config_h/has_header_h.in   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/config/gen/config_h.pm
   trunk/lib/Parrot/Distribution.pm

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Mon Jul  6 17:05:03 2009	(r39898)
+++ trunk/MANIFEST	Mon Jul  6 17:48:48 2009	(r39899)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Jul  2 17:10:26 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Mon Jul  6 16:56:56 2009 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -299,6 +299,7 @@
 config/gen/config_h.pm                                      []
 config/gen/config_h/config_h.in                             []
 config/gen/config_h/feature_h.in                            []
+config/gen/config_h/has_header_h.in                         []
 config/gen/config_pm.pm                                     []
 config/gen/config_pm/Config_pm.in                           []
 config/gen/config_pm/config_lib_pasm.in                     []

Modified: trunk/config/gen/config_h.pm
==============================================================================
--- trunk/config/gen/config_h.pm	Mon Jul  6 17:05:03 2009	(r39898)
+++ trunk/config/gen/config_h.pm	Mon Jul  6 17:48:48 2009	(r39899)
@@ -30,8 +30,9 @@
     $data{description} = q{Generate C headers};
     $data{result}      = q{};
     $data{templates}    = {
-        config_h    => 'config/gen/config_h/config_h.in',
-        feature_h   => 'config/gen/config_h/feature_h.in',
+        config_h        => 'config/gen/config_h/config_h.in',
+        feature_h       => 'config/gen/config_h/feature_h.in',
+        has_header_h    => 'config/gen/config_h/has_header_h.in',
     };
     return \%data;
 }
@@ -49,109 +50,34 @@
         feature_file   => 1
     );
 
-    my $hh = "include/parrot/has_header.h";
-    $conf->append_configure_log($hh);
-    open( my $HH, ">", "$hh.tmp" )
-        or die "Can't open has_header.h: $!";
-
-    my $pkg = __PACKAGE__;
-
-    print {$HH} <<EOF;
-/*
- * ex: set ro:
- * DO NOT EDIT THIS FILE
- * Generated by $pkg (a step of Configure.pl)
- */
-
-#ifndef PARROT_HAS_HEADER_H_GUARD
-#define PARROT_HAS_HEADER_H_GUARD
-
-/*
- * i_(\\w+) header includes
- */
-
-EOF
-
-    for ( sort( $conf->data->keys() ) ) {
-        next unless /i_(\w+)/;
-        if ( $conf->data->get($_) ) {
-            print {$HH} "#define PARROT_HAS_HEADER_\U$1 1\n";
-        }
-        else {
-            print {$HH} "#undef  PARROT_HAS_HEADER_\U$1\n";
-        }
-    }
-
-    my $osname = $conf->data->get_p5('OSNAME');
-    print {$HH} "\n#define BUILD_OS_NAME \"$osname\"\n";
-
-    _handle_define_option($conf, $HH);
-
-    print {$HH} <<EOF;
-
-/*
- * HAS_(\\w+) config entries
- */
-
-EOF
-    for ( sort( $conf->data->keys() ) ) {
-        next unless /HAS_(\w+)/;
-        if ( $conf->data->get($_) ) {
-            print {$HH} "#define PARROT_HAS_\U$1 1\n";
-        }
-    }
-    print {$HH} <<EOF;
-
-/*
- * D_(\\w+) config entries
- */
-
-EOF
-    for ( sort( $conf->data->keys() ) ) {
-        next unless /D_(\w+)/;
-        my $val;
-        if ( $val = $conf->data->get($_) ) {
-            print {$HH} "#define PARROT_\U$1 $val\n";
-        }
-    }
-
-    # append the guard endif and C code coda
-    print {$HH} <<EOF;
-
-#endif /* PARROT_HAS_HEADER_H_GUARD */
-
-/*
- * Local variables:
- *   c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
-EOF
+    $conf->data->set( TEMP_header =>
+        join "\n", map { $conf->data->get($_)
+                       ? "#define PARROT_HAS_HEADER_" . uc(substr $_, 2) . " 1"
+                       : "#undef  PARROT_HAS_HEADER_" . uc(substr $_, 2) }
+                   grep { /^i_\w+/ }
+                   sort $conf->data->keys()
+    );
 
-    close $HH;
+    $conf->data->set( TEMP_has_config =>
+        join "\n", map { "#define PARROT_" . uc($_) . " 1" }
+                   grep { /^HAS_\w+/ && $conf->data->get($_) }
+                   sort $conf->data->keys()
+    );
 
-    move_if_diff( "$hh.tmp", $hh );
+    $conf->data->set( TEMP_d_config =>
+        join "\n", map { "#define PARROT_" . uc(substr $_, 2) . " " . $conf->data->get($_) }
+                   grep { /^D_\w+/ }
+                   sort $conf->data->keys()
+    );
 
-    return 1;
-}
+    $conf->data->set( TEMP_cli_define =>
+        join "\n", map { "#define PARROT_DEF_" . uc($_) . " 1" }
+                   split /,/, $conf->options->get('define') || ''
+    );
 
-sub _handle_define_option {
-    my ($conf, $HH) = @_;
-    my $define = $conf->options->get('define');
-
-    if ($define) {
-        my @vals = split /,/, $define;
-        print {$HH} <<EOF;
-
-/*
- * defines from commandline
- */
-
-EOF
-        for my $v (@vals) {
-            print {$HH} "#define PARROT_DEF_" . uc($v), " 1\n";
-        }
-    }
+    $conf->genfile($self->{templates}->{has_header_h}, 'include/parrot/has_header.h');
+
+    return 1;
 }
 
 1;

Added: trunk/config/gen/config_h/has_header_h.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/config/gen/config_h/has_header_h.in	Mon Jul  6 17:48:48 2009	(r39899)
@@ -0,0 +1,41 @@
+/* Copyright (C) 2009, Parrot Foundation.
+ * $Id$
+ */
+
+#ifndef PARROT_HAS_HEADER_H_GUARD
+#define PARROT_HAS_HEADER_H_GUARD
+
+/*
+ * i_\w+ header includes
+ */
+
+ at TEMP_header@
+
+#define BUILD_OS_NAME "@osname@"
+
+/*
+ * defines from commandline
+ */
+
+ at TEMP_cli_define@
+
+/*
+ * HAS_\w+ config entries
+ */
+
+ at TEMP_has_config@
+
+/*
+ * D_\w+ config entries
+ */
+
+ at TEMP_d_config@
+
+#endif /* PARROT_HAS_HEADER_H_GUARD */
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Modified: trunk/lib/Parrot/Distribution.pm
==============================================================================
--- trunk/lib/Parrot/Distribution.pm	Mon Jul  6 17:05:03 2009	(r39898)
+++ trunk/lib/Parrot/Distribution.pm	Mon Jul  6 17:48:48 2009	(r39899)
@@ -431,6 +431,7 @@
             compilers/pirc/macro/macroparser.c
             compilers/pirc/macro/macroparser.h
             include/parrot/config.h
+            include/parrot/has_header.h
             src/gc/malloc.c
             } unless @exemptions;
 


More information about the parrot-commits mailing list