automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/4] Add support for resources


From: Raja R Harinath
Subject: [PATCH 3/4] Add support for resources
Date: Thu, 28 Jun 2007 18:43:18 +0530

* automake.in (handle_cli_assembly_sources): Rename from handle_cli_assembly.
(handle_cli_assembly_resources): New.  Add support for handling resources.
(handle_cli_assembly): Call both the previous methods.
(cli_need_resgen): New.
(handle_cli): Use it to emit RESGEN suffix rules, if necessary.
* lib/am/cli.am (clean-%DIR%%PRIMARY%): Remove *.resources.
* tests/cli3.test: New.
* tests/Makefile.am (TESTS): Update.
---
 ChangeLog         |   12 ++++++
 automake.in       |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/am/cli.am     |    1 +
 tests/Makefile.am |    1 +
 tests/cli3.test   |   46 +++++++++++++++++++++++++
 5 files changed, 155 insertions(+), 2 deletions(-)
 create mode 100755 tests/cli3.test

diff --git a/ChangeLog b/ChangeLog
index ec49428..2e75139 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2007-06-27  Raja R Harinath  <address@hidden>
 
+       Add support for resources
+       * automake.in (handle_cli_assembly_sources): Rename from
+       handle_cli_assembly.
+       (handle_cli_assembly_resources): New.  Add support for handling
+       resources.
+       (handle_cli_assembly): Call both the previous methods.
+       (cli_need_resgen): New.
+       (handle_cli): Use it to emit RESGEN suffix rules, if necessary.
+       * lib/am/cli.am (clean-%DIR%%PRIMARY%): Remove *.resources.
+       * tests/cli3.test: New.
+       * tests/Makefile.am (TESTS): Update.
+
        Compute dependencies from assembly references
        * automake.in (handle_cli_assembly): Return true on success.
        (handle_cli_assembly_references): New.
diff --git a/automake.in b/automake.in
index 9bf8b43..c2ab593 100755
--- a/automake.in
+++ b/automake.in
@@ -4683,7 +4683,7 @@ sub handle_java
     push (@all, 'class' . $dir . '.stamp');
 }
 
-sub handle_cli_assembly ($$$%)
+sub handle_cli_assembly_sources ($$$%)
 {
   my ($one_file, $unxformed, $where, %transform) = @_;
   my @cmdsrcs = ();
@@ -4700,7 +4700,8 @@ sub handle_cli_assembly ($$$%)
       my $nodist = ($prefix =~ /^nodist_/);
       my $nodefine = ($prefix =~ /EXTRA_/);
 
-      push @cmdsrcs, "\$($outvarname)";
+      push @cmdsrcs, "\$($outvarname)"
+       unless $nodefine;
 
       push @sources, "\$($varname)";
       push @dist_sources, shadow_unconditionally ($varname, $where)
@@ -4762,6 +4763,78 @@ sub handle_cli_assembly ($$$%)
   return 1;
 }
 
+my $cli_need_resgen;
+
+sub handle_cli_assembly_resources ($$$%)
+{
+  my ($one_file, $unxformed, $where, %transform) = @_;
+  my @cmdrsrcs = ();
+
+  foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
+                     'dist_EXTRA_', 'nodist_EXTRA_')
+    {
+      my $varname = $prefix . $one_file . "_RESOURCES";
+      my $var = var $varname;
+      next unless $var;
+      my $xpfx = ($prefix eq '') ? 'am_' : $prefix;
+      my $cmdrsrc = $xpfx . $one_file . "_CMDRSRCS";
+      my $deprsrc = $xpfx . $one_file . "_DEPRSRCS";
+      my $nodist = ($prefix =~ /^nodist_/);
+      my $nodefine = ($prefix =~ /EXTRA_/);
+
+      my @distrsrcs = uniq sort map { s/^(.*),([^,]*)$/$1/; $_ } 
$var->value_as_list_recursive;
+      &push_dist_common (@distrsrcs)
+       unless (option ('no-dist') || $nodist);
+
+      $var->transform_variable_recursively
+       ($deprsrc, 'am__cli', $nodefine, $where,
+        sub {
+          my ($subvar, $val, $cond, $full_cond) = @_;
+          $val =~ s/^(.*),([^,]*)$/$1/;
+          $val =~ s/\.(resx|txt|po)$/.resources/;
+          return $val;
+        });
+
+      $output_rules .= "$unxformed: \$($deprsrc)\n"
+       unless $nodefine;
+
+      push @cmdrsrcs, "\$($cmdrsrc)";
+
+      $var->transform_variable_recursively
+       ($cmdrsrc, 'am__cli', $nodefine, $where,
+        sub {
+          my ($subvar, $val, $cond, $full_cond) = @_;
+          my $rsrc_name = ();
+          my $nosrcdir = $nodist;
+          if ($val =~ /^(.*),([^,]*)$/)
+            {
+              $val = $1;
+              $rsrc_name = $2;
+            }
+          if ($val =~ /\.(resx|txt|po)$/)
+            {
+              $val =~ s/\.(resx|txt|po)$/.resources/;
+              $nosrcdir = 1;
+              $cli_need_resgen = $where;
+            }
+          my $retval = "-resource:";
+          $retval .= '$(srcdir)/'
+            unless $nosrcdir;
+          $retval .= $val;
+          $retval .= ",$rsrc_name"
+            if $rsrc_name;
+          return $retval;
+        });
+    }
+
+  return 1
+    if scalar @cmdrsrcs == 0;
+
+  define_pretty_variable ($one_file . '_CMDRSRCS', TRUE, $where, sort 
@cmdrsrcs);
+
+  return 1;
+}
+
 sub handle_cli_assembly_references(\%)
 {
   my ($known_assemblies) = @_;
@@ -4807,6 +4880,14 @@ sub handle_cli_assembly_references(\%)
     }
 }
 
+sub handle_cli_assembly ($$$%)
+{
+  my ($one_file, $unxformed, $where, %transform) = @_;
+  my $sources_ok = handle_cli_assembly_sources $one_file, $unxformed, $where, 
%transform;
+  my $resources_ok = handle_cli_assembly_resources $one_file, $unxformed, 
$where, %transform;
+  return $sources_ok && $resources_ok;
+}
+
 # Handle Mono/.NET
 sub handle_cli
 {
@@ -4815,6 +4896,8 @@ sub handle_cli
 
   my %known_assemblies = ();
 
+  $cli_need_resgen = ();
+
   foreach my $target (keys %targets)
     {
       my @assemblies = &am_install_var ('cli', 'CLI' . $target . 'S',
@@ -4845,6 +4928,16 @@ sub handle_cli
        }
     }
 
+  if ($cli_need_resgen)
+    {
+      define_variable ('RESGEN', 'resgen', INTERNAL);
+      for my $ext ('.resx','.txt','.po')
+       {
+         register_suffix_rule (INTERNAL, $ext, '.resources');
+         $output_rules .= "$ext.resources:\n\t\$(RESGEN) \$< address@hidden";
+       }
+    }
+
   handle_cli_assembly_references %known_assemblies;
 }
 
diff --git a/lib/am/cli.am b/lib/am/cli.am
index 8ddbc4f..d3064b2 100644
--- a/lib/am/cli.am
+++ b/lib/am/cli.am
@@ -23,3 +23,4 @@ include data.am
 clean-%DIR%%PRIMARY%:
        -list='$(%DIR%_%PRIMARY%)'; for p in $$list; do \
          rm -f $$p $$p.mdb $$p.pdb; done
+       -rm -f *.resources
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8708b10..e725d87 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -93,6 +93,7 @@ clean.test \
 clean2.test \
 cli1.test \
 cli2.test \
+cli3.test \
 colneq.test \
 colneq2.test \
 colon.test \
diff --git a/tests/cli3.test b/tests/cli3.test
new file mode 100755
index 0000000..7f5ab4c
--- /dev/null
+++ b/tests/cli3.test
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Copyright (C) 2002, 2003, 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test that basic CLI functionality works.
+
+. ./defs || exit 1
+
+set -e
+
+cat >Makefile.am <<END
+CSC = mcs
+VBC = vbnc
+noinst_CLIEXES = foo1.exe foo2.exe foo3.exe
+foo1_exe_SOURCES = a.cs
+foo2_exe_SOURCES = a.cs
+foo3_exe_SOURCES = a.cs
+foo1_exe_RESOURCES = b.txt,Some.other.name
+foo2_exe_RESOURCES = c.resx
+foo3_exe_RESOURCES = d.ico
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+grep '^am_foo1_exe_CMDRSRCS =.*b.txt' Makefile.in && exit 1
+grep '^am_foo1_exe_CMDRSRCS =.*-resource:b.resources' Makefile.in
+grep '^am_foo2_exe_CMDRSRCS =.*c.resx' Makefile.in && exit 1
+grep '^am_foo2_exe_CMDRSRCS =.*-resource:c.resources' Makefile.in
+grep '^am_foo3_exe_CMDRSRCS =.*-resource:[^ ]*d.ico' Makefile.in
-- 
1.5.2.1.174.gcd03





reply via email to

[Prev in Thread] Current Thread [Next in Thread]