Re: More on Actions, routes and builders in general

Lars Ivar Igesund <[email protected]> Mon, 21 Jun 2004 13:14:03 +0100
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Bram Moolenaar wrote:

> You already get these: $filetype is the input type, $targettype is the
> output type.

So why didn't you say so the last time I asked ;)

Anyway, it now works like a charm. Attached is the updated module and 
tool. :program, :dll and :lib work as well as before.

Diffs attached.

Lars Ivar Igesund
dmd.diff (text/plain, 8.5 KB)
Index: dmd.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/tools/dmd.py,v
retrieving revision 1.9
diff -u -r1.9 dmd.py
--- dmd.py	4 Mar 2004 18:38:12 -0000	1.9
+++ dmd.py	21 Jun 2004 11:09:49 -0000
@@ -1,6 +1,6 @@
 # Part of the A-A-P recipe executive 
 
-# Copyright (c) 2002-2003 Lars Ivar Igesund and stichting NLnet Labs
+# Copyright (c) 2002-2004 Lars Ivar Igesund and stichting NLnet Labs
 # Permission to copy and use this file is specified in the file COPYING.
 # If this file is missing you can find it here: http://www.a-a-p.org/COPYING
 
@@ -37,96 +37,123 @@
     """
     rd = Global.globals
     # Compile one sourcefile at the time
-    rpstack = [ RecPos("compile_dmd d action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "compile_dmd object,dllobject,libobject d"),
-            "opt =\n"
-            "@if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:\n"
-            "  opt = -O\n"
-            "dbg =\n"
-            "DEBUG ?=\n"
-            "@if _no.DEBUG == 'yes':\n"
-            "  dbg = -g\n"
-            ":sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT -of$target -c $source")
+    define_action("compile_dmd", 0, """
+        opt =
+        @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
+          opt = -O
+        dbg =
+        DEBUG ?=
+        @if _no.DEBUG == 'yes':
+          dbg = -g
+        :sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT -of$target 
+                -c $source
+        """,
+        outtypes = ["object", "libobject", "dllobject"],
+        intypes = ["d"])
+
     # Build a program from object files
-    rpstack = [ RecPos("build_dmd action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "build_dmd object"),
-            ":sys $DMD -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source")
+    define_action("build_dmd", 0, """
+        DLINKFLAGS += /DELEXECUTABLE
+        :sys $DMD -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source
+        """,
+        outtypes = ["default"],
+        intypes = ["object"])
+
     # Build a static lib from object files
-    rpstack = [ RecPos("buildlib_dmd action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "buildlib_dmd libobject"),
-            "@if os.name == \"nt\":\n"
-            "   :progsearch LIB lib\n"
-            "   :sys $LIB $?DLINKFLAGS -p512 -c $target $source\n"
-            "@else:\n"
-            "   :sys $DMD $?DLINKFLAGS -of$target $source")
+    define_action("buildlib_dmd", 0, """
+        @if os.name == "nt":
+            :progsearch LIB lib
+            :sys $LIB $?DLINKFLAGS -p512 -c $target $source
+        @else:
+            :sys $DMD $?DLINKFLAGS -of$target $source
+        """,
+        outtypes = ["default"],
+        intypes = ["libobject"])
+
     # Build a dll from object files  
-    rpstack = [ RecPos("builddll_dmd action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "builddll_dmd dllobject"),
-            "@exec \"import tools.dmd\"\n"
-            "@if os.name == \"nt\":\n"
-            "   @if _no.DIMPLIB and _no.DIMPLIB == \"yes\":\n"
-            "       DLINKFLAGS += /implib\n"
-            "@if not tools.dmd.find_dll_main_object(source):\n"
-            "   @f = file(\"aap_dllmain.d\", 'w')\n"
-            "   @f.write(tools.dmd.dll_main_source())\n"
-            "   @f.close()\n"
-            "   :do compile {target = aap_dllmain.obj} aap_dllmain.d\n"
-            "   source += aap_dllmain.obj\n"
-            ":sys $DMD -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source\n"
-            ":del {f} {q} aap_dllmain.*")
+    define_action("builddll_dmd", 0, """
+        DLINKFLAGS += /DELEXECUTABLE
+        @exec "import tools.dmd"
+        @if os.name == "nt":
+            DIMPLIB ?= 
+            @if DIMPLIB and DIMPLIB == "yes":
+                DLINKFLAGS += /implib
+        @if not tools.dmd.find_dll_main_object(source):
+            @f = file("aap_dllmain.d", 'w')
+            @f.write(tools.dmd.dll_main_source())
+            @f.close()
+            :do compile {target = aap_dllmain.obj} aap_dllmain.d
+            source += aap_dllmain.obj
+        :sys $DMD -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source
+        :del {f} {q} aap_dllmain.*
+        """,
+        outtypes = ["default"],
+        intypes = ["dllobject"])
+
     # Build a program directly from source
-    rpstack = [ RecPos("buildonestep_dmd d action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "buildonestep_dmd d"),
-            "opt =\n"
-            "@if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:\n"
-            "  opt = -O\n"
-            "dbg =\n"
-            "DEBUG ?=\n"
-            "@if _no.DEBUG == 'yes':\n"
-            "  dbg = -g\n"
-            ":sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT"
-            "       -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source\n"
-            ":del {f} {q} *.obj")
+    define_action("buildonestep_dmd", 0, """ 
+        DLINKFLAGS += /DELEXECUTABLE
+        opt =
+        @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
+            opt = -O
+        dbg =
+        DEBUG ?=
+        @if _no.DEBUG == 'yes':
+            dbg = -g
+        :sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT
+                -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source
+        :del {f} {q} *.obj
+        """,
+        outtypes = ["default"],
+        intypes = ["d"])
+
     # Build a static lib directly from source
-    rpstack = [ RecPos("buildlibonestep_dmd d action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "buildlibonestep_dmd d"),
-            "opt =\n"
-            "@if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:\n"
-            "  opt = -O\n"
-            "dbg =\n"
-            "DEBUG ?=\n"
-            "@if _no.DEBUG == 'yes':\n"
-            "  dbg = -g\n"
-            ":sys $DMD -c $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT"
-            "       -op $source\n"
-            ":progsearch LIB lib\n"
-            "BDIR = \n"
-            "objects = `src2obj(source)`\n"
-            ":sys $LIB $?DLINKFLAGS -p512 -c $target $objects\n"
-            ":del {f} {q} *.obj")
+    define_action("buildlibonestep_dmd", 0, """
+        opt =
+        @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
+            opt = -O
+        dbg =
+        DEBUG ?=
+        @if _no.DEBUG == 'yes':
+            dbg = -g
+        :sys $DMD -c $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT
+                -op $source
+        :progsearch LIB lib
+        BDIR = 
+        objects = `src2obj(source)`
+        :sys $LIB $?DLINKFLAGS -p512 -c $target $objects
+        :del {f} {q} *.obj
+        """,
+        outtypes = ["default"],
+        intypes = ["d"])
+
     # Build a dll directly from source
-    rpstack = [ RecPos("builddllonestep_dmd d action") ]
-    action_add(rpstack, rd, str2dictlist(rpstack, "builddllonestep_dmd d"),
-            "opt =\n"
-            "@if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:\n"
-            "  opt = -O\n"
-            "dbg =\n"
-            "DEBUG ?=\n"
-            "@if _no.DEBUG == 'yes':\n"
-            "  dbg = -g\n"
-            "@if os.name == \"nt\":\n"
-            "   @if _no.DIMPLIB and _no.DIMPLIB == \"yes\":\n"
-            "       DLINKFLAGS += -L/implib\n"
-            "@exec \"import tools.dmd\"\n"
-            "@if not tools.dmd.find_dll_main_source(source):\n"
-            "   @f = file(\"aap_dllmain.d\", 'w')\n"
-            "   @f.write(tools.dmd.dll_main_source())\n"
-            "   @f.close()\n"
-            "   source += aap_dllmain.d\n"
-            ":sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT"
-            "       -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source\n"
-            ":del {f} {q} aap_dllmain.d\n"
-            ":del {q} *.obj")
+    define_action("builddllonestep_dmd", 0, """
+        DLINKFLAGS += /DELEXECUTABLE
+        opt =
+        @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
+            opt = -O
+        dbg =
+        DEBUG ?=
+        @if _no.DEBUG == 'yes':
+            dbg = -g
+        @if os.name == "nt":
+            DIMPLIB ?= 
+            @if DIMPLIB and DIMPLIB == "yes":
+                DLINKFLAGS += -L/implib
+        @exec "import tools.dmd"
+        @if not tools.dmd.find_dll_main_source(source):
+            @f = file("aap_dllmain.d", 'w')
+            @f.write(tools.dmd.dll_main_source())
+            @f.close()
+            source += aap_dllmain.d
+        :sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT
+                -L$*?DLINKFLAGS -L+$*?LIBS -of$target $source
+        :del {f} {q} aap_dllmain.d
+        :del {q} *.obj
+        """,
+        outtypes = ["default"],
+        intypes = ["d"])
         
     if not rd["_top"].get("DMD"):
         rd["_top"]["DMD"] = "dmd"
d.diff (text/plain, 7.9 KB)
Index: d.aap
===================================================================
RCS file: /cvsroot/a-a-p/Exec/modules/d.aap,v
retrieving revision 1.14
diff -u -r1.14 d.aap
--- d.aap	15 Apr 2004 16:06:01 -0000	1.14
+++ d.aap	21 Jun 2004 11:09:34 -0000
@@ -1,11 +1,11 @@
 # Part of the A-A-P recipe executive: Module for the D Programming Language.
 
-# Copyright (c) 2002 - 2003 Lars Ivar Igesund and stichting NLnet Labs
+# Copyright (c) 2002 - 2004 Lars Ivar Igesund and stichting NLnet Labs
 # Permission to copy and use this file is specified in the file COPYING.
 # If this file is missing you can find it here: http://www.a-a-p.org/COPYING
 #
 
-# Last Change: 2004 Apr 14
+# Last Change: 2004 Jun 16
 
 # See also dmd.py in the tools directory for compiler specific info.
 
@@ -13,7 +13,8 @@
 # This is included in Filetype.py
 
 # (2) Default values
-DMD = dmd
+DCOMP = dmd
+SUPPORTED_TOOLS = "dmd"
 
 # (3) Object file suffixes
 # dll and lib objects are equal to normal objects.
@@ -77,111 +78,105 @@
 #
 
 :action depend {recursive} 
-        {buildcheck = $DMD $?DFLAGS $?DVERSION $?DDEBUG $?DIMPORT } d
+        {buildcheck = $DCOMP $?DFLAGS $?DVERSION $?DDEBUG $?DIMPORT } d
     :sys $_top.DDEPCHECK -m $?DIMPORT $source > $target
 
 # :do compile
 
-:action d_compile object,libobject,dllobject,default d
-    @if _no.get("D_COMPILE_ACTION"):
-        :do $D_COMPILE_ACTION {target = $target} $source
-    @else:
-        opt =
-        @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
-            opt = -O
-        dbg =
-        DEBUG ?=
-        @if _no.DEBUG == "yes":
-            dbg = -g
-        :sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT 
-                -of$target -c $source
-
-:action compile object,default d
-    @if not _no.get("target"):
-        target = `src2obj(fname)`
-    # Use the d_build action for building
-    :attr {buildaction = d_build} $target
-    :do d_compile {target = $target} $source
+:python
 
-:action compile dllobject d
-    @if _top.OSTYPE == "mswin":
+    define_action("compile", 1, """
         @if not _no.get("target"):
             target = `src2obj(fname)`
-        # Use the d_builddll action for building
-        :attr {buildaction = d_builddll} $target
-        :do d_compile {target = $target} $source
-    @else:
-        :print Dynamic link libraries aren't supported on non-win32 platforms.
-
-:action compile libobject d
-    @if not _no.get("target"):
-        target = `src2obj(fname)`
-    # Use the d_buildlib action for building
-    :attr {buildaction = d_buildlib} $target
-    :do d_compile {target = $target} $source
+        @if _no.targettype == "object":
+            :attr {buildaction = d_build} $target
+        @elif _no.targettype == "libobject":
+            :attr {buildaction = d_buildlib} $target
+        @elif _no.targettype == "dllobject":
+            :attr {buildaction = d_builddll} $target
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default compile action for D. Install one of the"
+            :print "supported tool chains(" + $SUPPORTED_TOOLS + ")"
+        """,
+        outtypes = ["object", "libobject", "dllobject"],
+        intypes = ["d"],
+        defer_var_names = ["D_COMPILE_ACTION"])
 
-:rule {global}{default} %$OBJSUF : {buildcheck = $DMD $?DFLAGS $?DVERSION $?DDEBUG $?DIMPORT } %.d
+:rule {global}{default} %$OBJSUF : {buildcheck = $DCOMP $?DFLAGS $?DVERSION $?DDEBUG $?DIMPORT } %.d
     :do compile {target = $target} $source
 
 # :do build for object files resulting from "d" source files.
 
-:action d_build default
-    @if _no.get("D_BUILD_ACTION"):
-        :do $D_BUILD_ACTION {target = $target} $source
-    @else:
-        :sys $DMD $?DLINKFLAGS -of$target $source
-
-:action d_builddll default
-    @if _no.get("D_BUILDDLL_ACTION"):
-        :do $D_BUILDDLL_ACTION {target = $target} $source
-    @else:
-        :print No default action for building dll's from D.
-
-:action d_buildlib default
-    @if _no.get("D_BUILDLIB_ACTION"):
-        :do $D_BUILDLIB_ACTION {target = $target} $source
+:python
+    define_action("d_build", 0, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default build action for D. Install one of the" 
+            :print "supported tool chains (" + $SUPPORTED_TOOLS + ")"
+        """,
+        outtypes = ["default"],
+        intypes = ["object"],
+        defer_var_names = ["D_BUILD_ACTION"])
+
+    define_action("d_builddll", 0, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default builddll action for D. Install one of the" 
+            :print "supported tool chains (" + $SUPPORTED_TOOLS + ")"
+        """,
+        outtypes = ["default"],
+        intypes = ["object"],
+        defer_var_names = ["D_BUILDDLL_ACTION"])
+
+    define_action("d_buildlib", 0, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default buildlib action for D. Install one of the" 
+            :print "supported tool chains (" + $SUPPORTED_TOOLS + ")"
+        """,
+        outtypes = ["default"],
+        intypes = ["object"],
+        defer_var_names = ["D_BUILDLIB_ACTION"])
 
 # :do buildonestep to build targets directly from "d" source
 
-:action d_buildonestep default d
-    opt =
-    @if _no.OPTIMIZE and int(_no.OPTIMIZE) > 0:
-      opt = -O
-    dbg =\n"
-    DEBUG ?=
-    @if _no.DEBUG == 'yes':
-      dbg = -g
-    :sys $DMD $?DFLAGS $?DVERSION $opt $dbg $?DDEBUG $?DIMPORT"
-              $?DLINKFLAGS -of$target $source")
-
-:action buildonestep default d
-    @if _no.get("D_BUILDONESTEP_ACTION"):
-        :do $D_BUILDONESTEP_ACTION {target = $target} $source
-    @else:
-        :do d_buildonestep {target = $target} $source
-
-:action builddllonestep default d
-    @if _top.OSTYPE == "mswin":
-        @if _no.get("D_BUILDDLLONESTEP_ACTION"):
-            :do $D_BUILDDLLONESTEP_ACTION {target = $target} $source
+:python
+    define_action("buildonestep", 1, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
         @else:
-            :do d_buildonestep {target = $target} $source
-    @else:
-        :print Dynamic link libraries aren't supported on non-win32 platforms.
-
-:action buildlibonestep default d
-    @if _no.get("D_BUILDLIBONESTEP_ACTION"):
-        :do $D_BUILDLIBONESTEP_ACTION {target = $target} $source
-
-# default route
-
-:route {default} d object {buildaction = d_build}
-     compile
-
-:route {default} d libobject {buildaction = d_buildlib}
-     compile
-
-:route {default} d dllobject {buildaction = d_builddll}
-     compile
+            :print "No default buildonestep action for D. Install on of the"
+            :print "supported tool chains (" + $SUPPORTED_TOOLS +")"
+        """,
+        outtypes = ["default"],
+        intypes = ["d"],
+        defer_var_names = ["D_BUILDONESTEP_ACTION"])
+
+    define_action("buildlibonestep", 1, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default buildlibonestep action for D. Install on of the"
+            :print "supported tool chains (" + $SUPPORTED_TOOLS +")"
+        """,
+        outtypes = ["default"],
+        intypes = ["d"],
+        defer_var_names = ["D_BUILDLIBONESTEP_ACTION"])
+
+    define_action("builddllonestep", 1, """
+        @if DEFER_ACTION_NAME:
+            :do $DEFER_ACTION_NAME {target = $target} $source
+        @else:
+            :print "No default builddllonestep action for D. Install on of the"
+            :print "supported tool chains (" + $SUPPORTED_TOOLS +")"
+        """,
+        outtypes = ["default"],
+        intypes = ["d"],
+        defer_var_names = ["D_BUILDDLLONESTEP_ACTION"])
 
 # vim: set sw=4 sts=4 tw=79 :