From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user,gmane.comp.gnu.make.devel Subject: Re: Guile support in GNU make Date: Thu, 19 Jan 2012 23:14:14 +0100 Message-ID: <87obtzqr0p.fsf@gnu.org> References: <1326570905.3482.136.camel@homebase> <87boq5jqmc.fsf@gnuvola.org> <1326643949.3482.241.camel@homebase> <8762gchbf8.fsf@gnu.org> <1326722878.3482.334.camel@homebase> <87y5t6x875.fsf@gnu.org> <1326842761.4484.5.camel@psmith-ubeta> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1327011282 10255 80.91.229.12 (19 Jan 2012 22:14:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 19 Jan 2012 22:14:42 +0000 (UTC) Cc: guile-user@gnu.org, make-alpha@gnu.org To: psmith@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jan 19 23:14:37 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ro0Fd-0002Lc-MR for guile-user@m.gmane.org; Thu, 19 Jan 2012 23:14:33 +0100 Original-Received: from localhost ([::1]:53983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ro0Fc-0004ZW-PV for guile-user@m.gmane.org; Thu, 19 Jan 2012 17:14:32 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:49025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ro0FY-0004Z2-0E for guile-user@gnu.org; Thu, 19 Jan 2012 17:14:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ro0FW-0007vi-Jc for guile-user@gnu.org; Thu, 19 Jan 2012 17:14:27 -0500 Original-Received: from mail1-relais-roc.national.inria.fr ([192.134.164.82]:43236) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ro0FP-0007uX-Rp; Thu, 19 Jan 2012 17:14:20 -0500 X-IronPort-AV: E=Sophos;i="4.71,538,1320620400"; d="scan'208";a="140636721" Original-Received: from reverse-83.fdn.fr (HELO pluto) ([80.67.176.83]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 19 Jan 2012 23:14:15 +0100 Mail-Followup-To: make-alpha@gnu.org X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 30 =?iso-8859-1?Q?Niv=F4se?= an 220 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <1326842761.4484.5.camel@psmith-ubeta> (Paul Smith's message of "Tue, 17 Jan 2012 18:26:00 -0500") User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.82 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9168 gmane.comp.gnu.make.devel:726 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Paul, With all my enthusiasm (and repulsion for an ugly Guile 2.0 bug on SPARC waiting to be fixed), I came up with the following patch to illustrate an addition that could be worthwhile. One can write stuff like: --8<---------------cut here---------------start------------->8--- %.y: %.z false $(guile (pk (pattern-rules) #f)) $(guile (pk (map rule-targets (pattern-rules)) #f)) --8<---------------cut here---------------end--------------->8--- and it prints out: --8<---------------cut here---------------start------------->8--- ;;; ((#) #f) ;;; ((("%.y")) #f) --8<---------------cut here---------------end--------------->8--- SMOBS for =E2=80=98dep=E2=80=99 and =E2=80=98commands=E2=80=99 could be add= ed similarly, allowing for nice makefile introspection and debugging. WDYT? Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=smobs.patch Content-Description: the patch Index: Makefile.am =================================================================== RCS file: /sources/make/make/Makefile.am,v retrieving revision 2.62 diff -u -r2.62 Makefile.am --- Makefile.am 16 Jan 2012 02:29:20 -0000 2.62 +++ Makefile.am 19 Jan 2012 22:06:58 -0000 @@ -46,7 +46,12 @@ $(remote) if HAVE_GUILE + BUILT_SOURCES = guile.x make_SOURCES += guile.c + +.c.x: + $(GUILE_SNARF) -o $@ $< $(AM_CPPFLAGS) -I$(builddir) -I$(srcdir) \ + $(GUILE_CFLAGS) endif EXTRA_make_SOURCES = vmsjobs.c remote-stub.c remote-cstms.c Index: configure.in =================================================================== RCS file: /sources/make/make/configure.in,v retrieving revision 1.161 diff -u -r1.161 configure.in --- configure.in 16 Jan 2012 02:29:22 -0000 1.161 +++ configure.in 19 Jan 2012 22:06:58 -0000 @@ -185,7 +185,8 @@ ]) AS_IF([test "$have_guile" = yes], - [AC_DEFINE([HAVE_GUILE], [1], [Embed GNU Guile support])]) + [AC_PATH_PROG([GUILE_SNARF], [guile-snarf]) + AC_DEFINE([HAVE_GUILE], [1], [Embed GNU Guile support])]) AM_CONDITIONAL([HAVE_GUILE], [test "$have_guile" = yes]) Index: guile.c =================================================================== RCS file: /sources/make/make/guile.c,v retrieving revision 2.4 diff -u -r2.4 guile.c --- guile.c 18 Jan 2012 13:31:11 -0000 2.4 +++ guile.c 19 Jan 2012 22:06:58 -0000 @@ -14,13 +14,103 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +# include +#endif + #include "make.h" #include "debug.h" #include "dep.h" +#include "rule.h" #include "variable.h" #include + + +SCM_SMOB (dependency, "dependency", 0); + +SCM_SMOB (rule, "rule", 0); + + +SCM gmk_rule_targets (SCM); + +SCM_SMOB_PRINT (rule, print_rule, obj, port, pstate) +{ + /* XXX: On Guile < 2.0, use `scm_from_locale_string'. */ + scm_simple_format (port, scm_from_latin1_string ("#"), + scm_list_2 (scm_number_to_string + (scm_object_address (obj), + scm_from_int (16)), + gmk_rule_targets (obj))); + return 1; +} + +/* Return the SMOB corresponding to RULE. */ +static SCM +gmk_from_rule (struct rule *r) +{ + if (scm_is_false (r->smob)) + /* Associate the new SMOB with R so that R only ever one associated SMOB, + which allows rules to be compared with `eq?'. */ + SCM_NEWSMOB (r->smob, rule, r); + + return r->smob; +} + +/* Return the C rule struct corresponding to OBJ. */ +static struct rule * +gmk_to_rule (SCM obj) +{ + SCM_ASSERT (SCM_SMOB_PREDICATE (rule, obj), obj, 0, "gmk_to_rule"); + + return (struct rule *) SCM_SMOB_DATA (obj); +} + +SCM_DEFINE (gmk_rule_p, "rule?", 1, 0, 0, + (SCM obj), + "Return #t when @var{obj} is a rule.") +#define FUNC_NAME s_gmk_rule_p +{ + return SCM_SMOB_PREDICATE (rule, obj); +} +#undef FUNC_NAME + +SCM_DEFINE (gmk_all_rules, "pattern-rules", 0, 0, 0, + (void), + "Return all the pattern rules of the current makefile.") +#define FUNC_NAME s_gmk_all_rules +{ + SCM lst; + struct rule *r; + + for (r = pattern_rules, lst = SCM_EOL; + r != NULL; + r = r->next) + lst = scm_cons (gmk_from_rule (r), lst); + + return scm_reverse (lst); +} +#undef FUNC_NAME + +SCM_DEFINE (gmk_rule_targets, "rule-targets", 1, 0, 0, + (SCM obj), + "Return the list of targets of @var{rule}.") +#define FUNC_NAME s_gmk_rule_targets +{ + int i; + SCM lst; + struct rule *r; + + r = gmk_to_rule (obj); + for (i = 0, lst = SCM_EOL; i < r->num; i++) + lst = scm_cons (scm_from_locale_string (r->targets[i]), lst); + + return scm_reverse (lst); +} +#undef FUNC_NAME + + static SCM make_mod = SCM_EOL; static SCM obj_to_str = SCM_EOL; @@ -76,6 +166,8 @@ /* Import the GNU make module exports into the generic space. */ scm_c_eval_string ("(use-modules (gnu make))"); +#include "guile.x" + return NULL; } Index: rule.c =================================================================== RCS file: /sources/make/make/rule.c,v retrieving revision 1.55 diff -u -r1.55 rule.c --- rule.c 16 Jan 2012 02:29:23 -0000 1.55 +++ rule.c 19 Jan 2012 22:06:58 -0000 @@ -458,6 +458,9 @@ r->targets = targets; r->suffixes = target_percents; r->lens = xmalloc (n * sizeof (unsigned int)); +#ifdef HAVE_GUILE + r->smob = SCM_BOOL_F; +#endif for (i = 0; i < n; ++i) { Index: rule.h =================================================================== RCS file: /sources/make/make/rule.h,v retrieving revision 1.19 diff -u -r1.19 rule.h --- rule.h 16 Jan 2012 02:29:24 -0000 1.19 +++ rule.h 19 Jan 2012 22:06:58 -0000 @@ -17,6 +17,10 @@ this program. If not, see . */ +#ifdef HAVE_GUILE +# include +#endif + /* Structure used for pattern (implicit) rules. */ struct rule @@ -30,6 +34,9 @@ unsigned short num; /* Number of targets. */ char terminal; /* If terminal (double-colon). */ char in_use; /* If in use by a parent pattern_search. */ +#ifdef HAVE_GUILE + SCM smob; /* The corresponding SMOB or #f. */ +#endif }; /* For calling install_pattern_rule. */ --=-=-=--