Package: make
Version: 3.80-9
Severity: normal
Tags: patch

*** Please type your report below this line ***

I was playing with some rule generating functions (using the eval function of
GNU Make) and I hit a problem when inserting conditionals. Here is an example
where make says there is an error (also in attachment):

# Makefile begin
define other-rule
.PHONY: other-rule
other-rule:
        @ echo other-rule
endef

define other-rule2
.PHONY: other-rule2
other-rule:
        @ echo other-rule2
endef

define rule_test
.PHONY: rule-test
rule-test: other-rule
ifeq ($$(strip $$(VAR)),)
$$(eval $$(call other-rule))
else
$$(eval $$(call other-rule2))
endif
endef

$(eval $(rule_test))
# Makefile end

And then, running make with the above produces:

% make
Makefile:20: *** missing `endif'.  Stop.

I was actually working at school and there I had no problem (they are running
Fedora Core release 2 (Tettnang)). The base version of make is the same. Here
are some details of their package:

% rpm -q -i make
Name : make Relocations: /usr Version : 3.80 Vendor: Red Hat, Inc.
Release : 3 Build Date: Mon Feb 16 23:41:39 2004
Install Date: Thu Sep 23 14:59:04 2004 Build Host: loma.devel.redhat.com
Group : Development/Tools Source RPM: make-3.80-3.src.rpm
Size : 772995 License: GPL
Signature : DSA/SHA1, Thu May 6 18:56:20 2004, Key ID b44269d04f2a6fd2
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Summary : A GNU tool which simplifies the build process for users.
Description :
<snip description>

When I uploaded my stuff here at home, I had a surprise when make reported the
error above. So I fetched the sources codes of make for Debian (make 3.80-9)
and the Red Hat (make-3.80-3.src.rpm) and then I looked at the patched code.
In the Red Hat patch, they added something about conditionals when evaluating
a buffer, so I added the same thing and now make works well with the example
above. Here is a patch for the changes I made (a diff between the patch Debian
code for 3.80-9 and the RH modifications; also included in attachment):

diff -ru make-3.80-9/read.c make-3.80/read.c
--- make-3.80-9/read.c  2002-10-03 22:13:42.000000000 -0400
+++ make-3.80/read.c    2005-02-22 11:40:00.000000000 -0500
@@ -271,7 +271,7 @@

   return read_makefiles;
 }
-

+
 static int
 eval_makefile (filename, flags)
      char *filename;
@@ -386,11 +386,37 @@
   return r;
 }

+static struct conditionals *
+install_conditionals (struct conditionals *new)
+{
+  struct conditionals *save = conditionals;
+
+  bzero ((char *) new, sizeof (*new));
+  conditionals = new;
+
+  return save;
+}
+
+static void
+restore_conditionals (struct conditionals *saved)
+{
+  /* Free any space allocated by conditional_line.  */
+  if (conditionals->ignoring)
+    free (conditionals->ignoring);
+  if (conditionals->seen_else)
+    free (conditionals->seen_else);
+
+  /* Restore state.  */
+  conditionals = saved;
+}
+
 int
 eval_buffer (buffer)
      char *buffer;
 {
   struct ebuffer ebuf;
+  struct conditionals *saved;
+  struct conditionals new;
   const struct floc *curfile;
   int r;

@@ -405,8 +431,12 @@
   curfile = reading_file;
   reading_file = &ebuf.floc;

+  saved = install_conditionals (&new);
+
   r = eval (&ebuf, 1);

+  restore_conditionals (saved);
+
   reading_file = curfile;

   return r;


# Patch ends here

I don't know though if there is something written somewhere about make that
states that the behavior with the above Makefile is normal or no. To me, it
seems more like no.

Anyway, hope this helps.

-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (600, 'testing'), (50, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages make depends on:
ii  libc6                       2.3.2.ds1-20 GNU C Library: Shared libraries an

-- no debconf information
define other-rule
.PHONY: other-rule
other-rule:
        @ echo other-rule
endef

define other-rule2
.PHONY: other-rule2
other-rule:
        @ echo other-rule2
endef

define rule_test
.PHONY: rule-test
rule-test: other-rule
ifeq ($$(strip $$(VAR)),)
$$(eval $$(call other-rule))
else
$$(eval $$(call other-rule2))
endif
endef

$(eval $(rule_test))

Attachment: make_3.80-9cond.diff.gz
Description: The suggested patch

Reply via email to