View mode: basic / threaded / horizontal-split · Log in · Help
March 31, 2004
[HOWTO](MN001) Augmenting dmd with the ability to acess the environment
Howto extend dmd 0.82 for accessing the environment under windows

I assume, that you have
a) a fresh install of dmd/dm into the root directory of your hard drive,
and
b) \dmd\bin as well as \dm\bin are in the front of your path


Let's start:

1) Enter the directory \dmd\src\phobos:
  cd \dmd\src\phobos

2) Make a new subdirectory called usr:
  mkdir usr

4) Create the file "usr\environ.d" with your preferred editor having the
on line content:
  public char[][ char[]] environ;

6) With your preferred editor edit the file win32.mak and

6a) add the characters "environ.obj" to the end of the "OBJS= " section.

6b) add the following two lines at the end of the file

environ.obj : usr\environ.d
       $(DMD) -c $(DFLAGS) usr\environ.d

6c) change the the line "DMD=..\dmd" to "DMD=dmd"

6d) delete the characters " mmfile.obj" form the "OBJS= " section

7) touch the file "minit.obj":
  copy /b minit.obj+

8) enter the directory \dmd\src\phobos\internal\gc:
  cd internal\gc

9) with your preferred editor edit the file win32.mak and

9a)change the line "DMD=..\..\..\dmd" to "DMD=dmd"

10)compile the gc library:
  make -f win32.mak

11)Go back to \dmd\src\phobos:
  cd ..\..

12) With your preferred editor edit the file internal\dmain2.d and
12a) before the line containing "result = main(args);" add the seven lines:

       for( i= 0; env[ i] != null ; i++){
           int len = strlen(env[i]);
           char[] s= env[i][0 .. len];
           int j;
           for( j= 0; s[j] != '='; j++){};
           environ[ s[0 .. j]]= s[ j+1 .. len];
       }

12b) as the very first line add the line
    
    import usr.environ;

12c) change the line
   "extern (C) int main(int argc, char **argv)"
to
   "extern (C) int main(int argc, char **argv, char **env)"

14) compile and build phobos.lib:
   make -f win32.mak phobos.lib

15) Enter the directory \dmd\lib:
   cd \dmd\lib

16) Rename old phobos.lib to phobos.org:
   ren phobos.lib phobos.org

17) Install new phobos.lib:
   move \dmd\src\phobos\phobos.lib .

18) Enter a directory somewhere in your file hierarchie and create the
file test.d containing the four lines:

import usr.environ;
void main(){
 printf("%.*s\n", environ["PATH"]);
}

19) Compile it and run it:
   dmd test.d
   .\test

20) Compare the output with the output of the system command for output of
the path:
   path

Now you should be all done. Have fun.

So long!
Top | Discussion index | About this forum | D home