Thread overview
script for configuring dmd to work with phobos and tango on linux
Mar 30, 2007
ideage
Mar 30, 2007
ideage
Mar 30, 2007
eao197
Mar 30, 2007
Kirk McDonald
March 29, 2007
I previously sent a little script that configured the environment
variable DFLAGS, but then I figured that it's best to mess with the
config file directly. This way the advantage of different consoles with
different dmd configuration is lost, but then there is the advantage
that the configuration is persistent, which help certain modus operandi.
YMMV.

Paste the code below into a file e.g. dmdc, make it executable, and then
run either "dmdc phobos" or "dmdc tango". Adding more parameters after
that invokes the compiler, temporarily overriding the .conf file with
the requested environment; the old environment is then restored


HTH,

Andrei

#!/bin/sh

D_BIN=$(dirname $(which dmd))
WHICH=$1

if [ "$WHICH" = "phobos" ]; then
    DFLAGS="-I$D_BIN/../src/phobos -L-L$D_BIN/../lib
-L-L$D_BIN/../../dm/lib"
elif [ "$WHICH" = "tango" ]; then
    DFLAGS="-I$D_BIN/../../tango-0.96-bin -version=Tango -version=Posix"
    DFLAGS="$DFLAGS -L-L$D_BIN/../../tango-0.96-bin/lib libtango.a"
else
    echo "Please pass either phobos or tango as the first argument"
    WHICH=""
fi

if [ ! -z "$WHICH" ]; then
    shift
    mv $D_BIN/dmd.conf $D_BIN/dmd.conf.bak
    if [ "$*" != "" ]; then
	dmd $*
	mv $D_BIN/dmd.conf.bak $D_BIN/dmd.conf
    else
	echo "[Environment]" >$D_BIN/dmd.conf
	echo "DFLAGS=$DFLAGS" >>$D_BIN/dmd.conf
    fi
fi

March 30, 2007
Greet Andrei Alexandrescu  , Thank you! you are a adept; a highly skilled person; an expert, in my mind.

Why write a book <<Modern D Design>> ,it will resolve D template program!


March 30, 2007
ideage wrote:
> Greet Andrei Alexandrescu  , Thank you! you are a adept; a highly skilled person; an expert, in my mind.

Note to self: never underestimate the seductive power of a little trivial shell script :o).


Andrei
March 30, 2007
Thank you again. i will try it's power.

Expect your book! Do you think write it?

> Note to self: never underestimate the seductive power of a little trivial shell script :o).
>
>
> Andrei


March 30, 2007
On Fri, 30 Mar 2007 01:57:56 +0400, Andrei Alexandrescu (See Website for Email) <SeeWebsiteForEmail@erdani.org> wrote:

> I previously sent a little script that configured the environment
> variable DFLAGS, but then I figured that it's best to mess with the
> config file directly. This way the advantage of different consoles with
> different dmd configuration is lost, but then there is the advantage
> that the configuration is persistent, which help certain modus operandi.
> YMMV.
>
> Paste the code below into a file e.g. dmdc, make it executable, and then
> run either "dmdc phobos" or "dmdc tango". Adding more parameters after
> that invokes the compiler, temporarily overriding the .conf file with
> the requested environment; the old environment is then restored

Thanks for a great idea!

There is a my attempt to create such script for Windows version of dmd. I've used Ruby because I'm a big fun of Ruby.

Paste the code below into a file dmdc.rb and place the file in the directory with dmd.exe (it is necessary because the script assumes that sc.ini is in the same directory). Then change definition of constant TANGO_PATH to your tango's directory name.

When dmdc.rb started with 'tango' arguments it moves sc.ini to sc.ini.original then makes sc.ini with original content of sc.ini.original except for lines which start from LIB= or DFLAGS= (those are being changed).

This is the first (created on the knee) version :)
It have been tested on Ruby 1.8.6 on Windows with dmd.1.009 and tango.0.96 (it may be necessary to add '.rb' into PATHEXT environment variable).


require 'fileutils'

# Set path to your tango directory here.
TANGO_PATH = 'd:/usr/tango'

DMD_PATH = File.dirname( $0 )
SC = 'sc.ini'
SC_INI = File.join( DMD_PATH, SC )
SC_COPY = SC_INI + '.original'

if ARGV.size < 2 || /(tango|phobos)/i !~ ARGV[0]
  $stderr.puts "#{File.basename($0)} <tango|phobos> args..."
  exit 1
end

if /tango/i =~ ARGV[0]
  # It is necessary to change 'sc.ini' file.
  FileUtils.mv( SC_INI, SC_COPY )
  # Return 'sc.int' at the end
  at_exit do
    FileUtils.mv( SC_COPY, SC_INI )
  end

  # Make transformation of sc.ini.original content.
  File.open( SC_INI, 'w' ) do |dest|
    IO.readlines( SC_COPY ).each do |cfg_line|
      updated_line = case cfg_line
        when /^LIB=/
          %{LIB="#{TANGO_PATH}/lib;%@P%/../lib;%@P%/../../dm/lib"}
        when /^DFLAGS=/
          %{DFLAGS="-I#{TANGO_PATH}" -version=Tango tango.lib}
        else
          cfg_line
      end
      dest.puts updated_line
    end
  end
end

# Prepare command line and run dmd with arguments.
# Change all occurences of \" into \\".
# Enclose each argument in quotes to defend arguments with spaces inside.
guarded_args = ARGV[1..-1].map { |a| a.gsub( /(")/, '\\"' ) }
cmd_line = %{dmd "#{guarded_args.join('" "')}"}

system( cmd_line )
exit $? ? $?.exitstatus : 1

# vim:ts=2:sts=2:sw=2:expandtab



-- 
Regards,
Yauheni Akhotnikau
March 30, 2007
Andrei Alexandrescu (See Website for Email) wrote:
> I previously sent a little script that configured the environment
> variable DFLAGS, but then I figured that it's best to mess with the
> config file directly. This way the advantage of different consoles with
> different dmd configuration is lost, but then there is the advantage
> that the configuration is persistent, which help certain modus operandi.
> YMMV.
> 
> Paste the code below into a file e.g. dmdc, make it executable, and then
> run either "dmdc phobos" or "dmdc tango". Adding more parameters after
> that invokes the compiler, temporarily overriding the .conf file with
> the requested environment; the old environment is then restored
> 
> 
> HTH,
> 
> Andrei
> 
> #!/bin/sh
> 
> D_BIN=$(dirname $(which dmd))
> WHICH=$1
> 
> if [ "$WHICH" = "phobos" ]; then
>     DFLAGS="-I$D_BIN/../src/phobos -L-L$D_BIN/../lib
> -L-L$D_BIN/../../dm/lib"
> elif [ "$WHICH" = "tango" ]; then
>     DFLAGS="-I$D_BIN/../../tango-0.96-bin -version=Tango -version=Posix"
>     DFLAGS="$DFLAGS -L-L$D_BIN/../../tango-0.96-bin/lib libtango.a"
> else
>     echo "Please pass either phobos or tango as the first argument"
>     WHICH=""
> fi
> 
> if [ ! -z "$WHICH" ]; then
>     shift
>     mv $D_BIN/dmd.conf $D_BIN/dmd.conf.bak
>     if [ "$*" != "" ]; then
>     dmd $*
>     mv $D_BIN/dmd.conf.bak $D_BIN/dmd.conf
>     else
>     echo "[Environment]" >$D_BIN/dmd.conf
>     echo "DFLAGS=$DFLAGS" >>$D_BIN/dmd.conf
>     fi
> fi
> 

I little while back I came up with a scheme for DMD/Windows, which I placed on the Tango wiki:

http://dsource.org/projects/tango/wiki/PhobosTangoCooperation

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org