[erlang-questions] Erlang on Windows: Alternative to "make"

Joern opendev@REDACTED
Tue Nov 13 22:31:17 CET 2007


Hi Joe,

if you are comfortable using Ruby you should consider taking a look at
Rake which I use on win32 and -x to build OTP applications. A small
Rakefile (not tested, I just cut out a piece of our reasonably large
Rakefile) like this should get you started. The application uses the
package format and eunit for testing. There's also a native Erlang
alternative to plain make somewhere on google code if memory serves
right.

require 'rake/clean'
require 'find'

DBDIR = '\"c:/db\"'

VER = '1.0'
BASEDIR = "lib/myapp-#{VER}"

COOKIE = 'mycookie'

ABSOLUTE_DIR = File.expand_path('.')
SOURCE_DIR = "#{BASEDIR}/src"
BINARY_DIR = "#{BASEDIR}/ebin"
INCLUDE_DIR = "#{BASEDIR}/include"

SOURCES = Rake::FileList["#{SOURCE_DIR}/**/*.erl" ]
BINARIES = SOURCES.ext('beam').sub('/src/', '/ebin/')

CLASSPATH = Rake::FileList["#{BINARY_DIR}/**/*"].exclude { |f|
!File.directory?(f) }.sub(BASEDIR, '')

CLEAN.include(Rake::FileList["#{BINARY_DIR}/**"].exclude("**/*.app"))
CLOBBER.include('**/*.beam', '**/*.dump', '**/*.bak', 'log/*')

COMPILER_FLAGS = [ '+debug_info']
DEFAULT_OPTIONS = [ '+A256', "-mnesia dir #{DBDIR}", '-smp auto',
'-sname myapp', "-pz #{BINARY_DIR}", "-setcookie #{COOKIE}" ]
EXTRA_ARGUMENTS = [ "-cfg #{BASEDIR}/priv/myapp.cfg" ]

ENV['ERL_COMPILER_OPTIONS'] = %Q!{i, "#{ABSOLUTE_DIR}/#{INCLUDE_DIR}" }!

task :default => :test

rule '.beam' => lambda { |b| b.ext('erl').sub('/ebin/', '/src/') } do |t|
  current_package = t.name.pathmap('%d')
  directory(current_package)
  Rake::Task[current_package].invoke
  sh "erlc #{COMPILER_FLAGS.join(' ')} -o #{t.name.pathmap('%d')} #{t.source}"
end

desc 'Compile all sources.'
task :compile => BINARIES

desc 'Build the documentation.'
task :doc do
    erl :execute => 'ok = edoc:application(myapp, "lib/myapp-1.0", [ {
todo, true }, { packages, true } ]).'
end

desc 'Open a local console.'
task :console do
    erl :options => "-run c cd #{SOURCE_DIR}", :abort => false
end

desc 'Run all tests.'
task :test => [ :compile ] do
    erl :execute => 'ok = eunit:test().'
end

def erl(opts = {})

    defaults = {
        :execute => nil,
        :abort => true,
        :options => DEFAULT_OPTIONS
    }

    opts = defaults.merge(opts) { |k, ov, nv| ov.is_a?(Array) ? ov << nv : nv }
    opts[:options] << '-run init stop' if opts[:abort]

    win32 = RUBY_PLATFORM =~ /(win|w)32$/

    if !opts[:abort] && !opts[:execute] && win32
        shell = 'werl'
    else
        shell = 'erl'
    end

    execute = "start #{shell} #{opts[:options].join(' ')} #{EXTRA_ARGUMENTS}"
    execute = "echo #{opts[:execute]} | #{execute}" if opts[:execute]
    system execute

end


rgs/joern
--



More information about the erlang-questions mailing list