script for configuring dmd to work with phobos and tango on linux

eao197 eao197 at intervale.ru
Fri Mar 30 02:21:13 PDT 2007


On Fri, 30 Mar 2007 01:57:56 +0400, Andrei Alexandrescu (See Website for  
Email) <SeeWebsiteForEmail at 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



More information about the Digitalmars-d mailing list