Dear All,

I created a patch for ozmake that makes it possible to use macros in Oz code and still use ozmake to compile it. It simply adds a new option "--environment" to ozmake and propagates its value to the compiler.

Maybe this is useful for somebody else as well.

Base version: 1.3.2
Apply like this:
cd mozart-1.3.2.20060615-std/ozmake
patch -p1 <../ozmake_20070911.patch


Wolfgang
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/Attribs.oz ozmake/Attribs.oz
--- ozmake0/Attribs.oz  2004-05-14 17:21:43.000000000 +0200
+++ ozmake/Attribs.oz   2007-09-11 19:23:18.437500000 +0200
@@ -130,6 +130,7 @@
         Binary      : unit
         Platform    : unit
         PlatformGiven : false
+         Environment : nil
 
       meth set_platform(V)
         PlatformGiven<-true
@@ -993,5 +994,8 @@
 
       meth set_autodepend(B) AutoDepend<-B end
       meth get_autodepend($) @AutoDepend end
+
+      meth set_environment(W) Environment<-W end
+      meth get_environment($) @Environment end
    end
 end
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/Errors.oz ozmake/Errors.oz
--- ozmake0/Errors.oz   2004-05-18 19:20:31.000000000 +0200
+++ ozmake/Errors.oz    2007-09-11 21:13:31.500000000 +0200
@@ -108,6 +108,10 @@
         error(kind : TITLE_BUILD
               msg  : 'shell command failed'
               items: [hint(l:'Shell command' m:CMD)])
+      [] ozmake(build:illegalvariable(VAR)) then
+        error(kind : TITLE_BUILD
+              msg  : 'illegal variable identifier for \'environment\' option'
+              items: [hint(l:'Variable' m:VAR)])
       [] ozmake(mkdir:S) then
         error(kind : TITLE
               msg  : 'cannot create directory'
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/Executor.oz ozmake/Executor.oz
--- ozmake0/Executor.oz 2004-03-10 21:05:06.000000000 +0100
+++ ozmake/Executor.oz  2007-09-11 20:16:39.640625000 +0200
@@ -182,14 +182,16 @@
                     of 'define'(S) then {C '-D'#S}
                     else skip end
                  end}
+           Env = {self get_environment($)}
+           L6 = if Env \= nil then '--environment='#Env|L5 else L5 end
         in
-           {self xtrace({Utils.listToVS ozc|L5})}
+           {self xtrace({Utils.listToVS ozc|L6})}
            if {self get_justprint($)} then
               %% record time of simulated build
               Executor,SimulatedTouch(DST)
            else
               try {Shell.executeProgram
-                   {self get_oz_engine($)}|{self get_oz_ozc($)}|L5}
+                   {self get_oz_engine($)}|{self get_oz_ozc($)}|L6}
               catch shell(CMD) then
                  raise ozmake(build:shell(CMD)) end
               end
@@ -258,7 +260,9 @@
                                   defines    : Defines
                                   debug      : ArgDebug
                                   executable : ArgExecutable
-                                  gumpdir    : ArgGumpdir)}
+                                  gumpdir    : ArgGumpdir
+                                  environment: {self get_environment($)}
+                                 )}
            end
         finally
            if {Not HaveGumpdir} /*andthen DIR\=nil*/ andthen DSTDir\=nil then
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/ExecutorFast.oz 
ozmake/ExecutorFast.oz
--- ozmake0/ExecutorFast.oz     2004-02-12 15:03:47.000000000 +0100
+++ ozmake/ExecutorFast.oz      2007-09-11 21:14:29.250000000 +0200
@@ -6,6 +6,7 @@
    'class' : ExecutorFast
 import
    Compiler
+   Module
    Windows at 'Windows.ozf'
    Path    at 'Path.ozf'
 define
@@ -15,10 +16,13 @@
                         debug      : Debug      <= false
                         executable : Executable <= false
                         gumpdir    : Gumpdir    <= unit
-                        baseURL    : BaseURL    <= unit)
+                        baseURL    : BaseURL    <= unit
+                        environment: Env        <= nil)
         BatchCompiler = {New Compiler.engine init()}
         UI = {New Compiler.interface init(BatchCompiler auto)}
       in
+        {ForAll {String.tokens Env &,}
+         proc {$ S} {IncludeFunctor S BatchCompiler} end}
         for D in Defines do
            {BatchCompiler enqueue(macroDefine(D))}
         end
@@ -55,4 +59,55 @@
         end
       end
    end
+
+   %% This code is copied from /share/lib/ozbatch/compile.oz
+   local
+      fun {IsIDChar C}
+        {Char.isAlNum C} orelse C == &_
+      end
+
+      fun {IsQuotedVariable S}
+        case S of C1|Cr then
+           if C1 == &` andthen Cr == nil then true
+           elseif C1 == 0 then false
+           else {IsQuotedVariable Cr}
+           end
+        [] nil then false
+        end
+      end
+
+      fun {IsPrintName X}
+        {IsAtom X} andthen
+        local
+           S = {Atom.toString X}
+        in
+           case S of C|Cr then
+              case C of &` then
+                 {IsQuotedVariable Cr}
+              else
+                 {Char.isUpper C} andthen {All Cr IsIDChar}
+              end
+           [] nil then false
+           end
+        end
+      end
+
+      ModMan = {New Module.manager init()}
+   in
+      proc {IncludeFunctor S Compiler} Var URL VarAtom Export in
+        {String.token S &= ?Var ?URL}
+        VarAtom = {String.toAtom Var}
+        Export = case URL of nil then {ModMan link(name: Var $)}
+                 else {ModMan link(url: URL $)}
+                 end
+        if {IsPrintName VarAtom} then
+           {Compiler enqueue(mergeEnv(env(VarAtom: Export)))}
+        else
+           raise ozmake(build:illegalvariable(Var)) end
+        end
+        {Compiler enqueue(mergeEnv({Record.filterInd Export
+                                    fun {$ P _} {IsPrintName P} end}))}
+      end
+   end
+
 end
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/HELP.txt ozmake/HELP.txt
--- ozmake0/HELP.txt    2005-06-04 15:47:45.000000000 +0200
+++ ozmake/HELP.txt     2007-09-11 20:28:13.359375000 +0200
@@ -212,6 +212,15 @@
           located in the global installation directory and in the user's
           private ~/.oz area.
 
+   --environment=MODULES
+          Makes MODULES, a comma-separated list of pairs VAR=URL,
+          available in the compiler environment. For each VAR=URL,
+          the module available through the functor at URL is obtained
+          and VAR is bound to it. The source files then compiled can
+          reference variable VAR.
+         Useful if you want to use macros in your Oz code.
+          See also option --environment of the ozc batch compiler.
+
   Install
 
    ozmake --install
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/HELP.xml ozmake/HELP.xml
--- ozmake0/HELP.xml    2004-07-30 09:43:15.000000000 +0200
+++ ozmake/HELP.xml     2007-09-11 19:17:23.375000000 +0200
@@ -406,6 +406,19 @@
   directories located in the global installation directory and in the
   user's private <file>~/.oz</file> area.</item>
 </optentry>
+<optentry>
+  <option>
+    <opt>--environment=MODULES</opt>
+  </option>
+  <item>Makes MODULES, a comma-separated list of pairs VAR=URL,
+        available in the compiler environment. For each VAR=URL,
+        the module available through the functor at URL is obtained
+        and VAR is bound to it. The source files then compiled can
+        reference variable VAR.
+       Useful if you want to use macros in your Oz code.
+        See also option --environment of the ozc batch compiler.
+  </item>
+</optentry>
 </optlist>
 
 </subsection>
diff -Naur -x '*.exe*' -x '*~' -x '*.ozf' ozmake0/Main.oz ozmake/Main.oz
--- ozmake0/Main.oz     2004-03-09 18:11:28.000000000 +0100
+++ ozmake/Main.oz      2007-09-11 20:03:31.843750000 +0200
@@ -111,6 +111,8 @@
       binary(single bool)
 
       autodepend(single type:bool)
+
+      environment(single type: string)
       )
 
    OPTLIST =
@@ -173,6 +175,7 @@
     autodepend     # set_autodepend       # true               # true
     requires       # set_dorequires       # false               # true
     binary         # set_binary           # false               # false
+    environment    # set_environment      # false               # false
    ]
       
 define
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to