import 'autoclean' gen AutoClean , :clean var[ :clean ].include( [ '*~' , '*.pyc' , '*.hi' , '*.hc' , '*.o' , '*.cmi' , '*.cmo' , '*.cmx' , 'test-output' , 'TestResult.xml' , '*.class' ] ) ccflags = '-O3 -W -Wall -Wundef -Wcast-align -Wno-unused-parameter -Wshadow -Wredundant-decls' ######## C Stuff ################################################### CRoot = 'factorial' CFiles = [ CRoot + '.c' , CRoot + '_test.c' ] CExecutable = CRoot + '_c' file CExecutable => CFiles do | t | sys( "gcc #{ccflags} -o #{t.name} #{t.prerequisites.join( ' ' )} -lcheck" ) end desc 'Test the C implementation that uses primitive types.' task :c => CExecutable do | t | sys( "#{t.prerequisites}" ) end ######## C GMP Stuff ############################################### CGMPRoot = 'factorial_gmp' CGMPFiles = [ CGMPRoot + '.c' , CGMPRoot + '_test.c' ] CGMPExecutable = CGMPRoot + '_c' file CGMPExecutable => CGMPFiles do | t | sys( "gcc #{ccflags} -o #{t.name} #{t.prerequisites.join( ' ' )} -lcheck -lgmp" ) end desc 'Test the C implementation that uses the GMP types.' task :c_gmp => CGMPExecutable do | t | sys( "#{t.prerequisites}" ) end ######## C++ Stuff ################################################# LibraryPath = "#{ENV['HOME']}/lib.Linux.ix86" CppRoot = 'factorial' CppFiles = [ CppRoot + '.cpp' , CppRoot + '_test.cpp' ] CppExecutable = CppRoot + '_cpp' file CppExecutable => CppFiles do | t | sys( "g++ #{ccflags} -I#{ENV['HOME']}/include -o #{t.name} #{t.prerequisites.join( ' ' )} -L#{LibraryPath} -laeryn_core" ) end desc 'Test the C++ implementation that uses primitive types.' task :cpp => CppExecutable do | t | sys.sh( "export LD_LIBRARY_PATH=#{LibraryPath} && #{t.prerequisites}" ) end ######## C++ GMP Stuff ############################################# CppGMPRoot = 'factorial_gmp' CppGMPFiles = [ CppGMPRoot + '.cpp' , CppGMPRoot + '_test.cpp' ] CppGMPExecutable = CppGMPRoot + '_cpp' file CppGMPExecutable => CppGMPFiles do | t | sys( "g++ #{ccflags} -I#{ENV['HOME']}/include -o #{t.name} #{t.prerequisites.join( ' ' )} -L#{LibraryPath} -lgmpxx -lgmp -laeryn_core" ) end desc 'Test the C++ implementation that uses the GMP types.' task :cpp_gmp => CppGMPExecutable do | t | sys.sh( "export LD_LIBRARY_PATH=#{LibraryPath} && #{t.prerequisites}" ) end ######## C# Stuff ################################################## CSharpRoot = 'Factorial' CSharpTestRoot = CSharpRoot + '_Test' CSharpFiles = [ CSharpRoot + '.cs' , CSharpTestRoot + '.cs' ] CSharpAssembly = CSharpTestRoot + '.exe' file CSharpAssembly => CSharpFiles do | t | sys( "mcs -pkg:nunit -out:#{t.name} #{t.prerequisites.join( ' ' )}" ) end desc 'Test the C# implementation that uses primtive types.' task :csharp => CSharpAssembly do sys( "nunit-console #{CSharpAssembly}" ) end ######## C# BigInteger Stuff ####################################### CSharpBigIntegerRoot = 'Factorial_BigInteger' CSharpBigIntegerTestRoot = CSharpBigIntegerRoot + '_Test' CSharpBigIntegerFiles = [ CSharpBigIntegerRoot + '.cs' , CSharpBigIntegerTestRoot + '.cs' ] CSharpBigIntegerAssembly = CSharpBigIntegerTestRoot + '.exe' file CSharpBigIntegerAssembly => CSharpBigIntegerFiles do | t | sys( "mcs -pkg:nunit -r:Mono.Security -out:#{t.name} #{t.prerequisites.join( ' ' )}" ) end desc 'Test the C# implementation that uses BigInteger.' task :csharp_biginteger => CSharpBigIntegerAssembly do sys( "nunit-console #{CSharpBigIntegerAssembly}" ) end ######## Java Stuff ################################################ JavaRoot = 'Factorial_J' JavaTestClassName = JavaRoot + '_Test' JavaFiles = [ JavaRoot + '.java' , JavaTestClassName + '.java' , 'FactorialIllegalArgumentException.java' ] TestNGJar = ENV[ 'HOME' ] + '/lib/Java/testng/testng.jar' def classFileOf( x ) x.sub( '.java' , '.class' ) end JavaFiles.each { | name | file classFileOf( name ) => name do | t | sys( "javac -g -cp .:#{TestNGJar} #{t.prerequisites}" ) end } desc 'Test the Java implementation that uses primtive types.' task :java => JavaFiles.map { | name | classFileOf( name ) } do sys( "java -cp .:#{TestNGJar} org.testng.TestNG -testclass #{JavaTestClassName}" ) end ######## Java BigInteger Stuff ##################################### JavaBigIntegerRoot = 'Factorial_J_BigInteger' JavaBigIntegerTestClassName = JavaBigIntegerRoot + '_Test' JavaBigIntegerFiles = [ JavaBigIntegerRoot + '.java' , JavaBigIntegerTestClassName + '.java' , 'FactorialIllegalArgumentException.java' ] JavaBigIntegerFiles.each { | name | file classFileOf( name ) => name do | t | sys( "javac -g -cp .:#{TestNGJar} #{t.prerequisites}" ) end } desc 'Test the Java implementation that uses BigInteger.' task :java_biginteger => JavaBigIntegerFiles.map { | name | classFileOf( name ) } do sys( "java -cp .:#{TestNGJar} org.testng.TestNG -testclass #{JavaBigIntegerTestClassName}" ) end ######## Groovy Test of Java ####################################### JavaClassesNeeded = [ JavaBigIntegerRoot + '.class' , 'FactorialIllegalArgumentException.class' ] desc 'Test the Java BigInteger implementation using Groovy with Junit.' task :java_groovy_junit => JavaClassesNeeded do sys( './Factorial_J_BigInteger_Test_JUnit.groovy' ) end desc 'Test the Java BigInteger implementation using Groovy with TestNGroove.' task :java_groovy_testngroove => JavaClassesNeeded do sys( './Factorial_J_BigInteger_TestNGroove.groovy' ) end ######## Scala Stuff ############################################### ScalaRoot = 'Factorial_S' ScalaTestClassName = ScalaRoot + '_Test' ScalaFiles = [ ScalaRoot + '.scala' , ScalaTestClassName + '.scala' ] def classFileOf( x ) x.sub( '.scala' , '.class' ) end ScalaFiles.each { | name | file classFileOf( name ) => name do | t | sys( "scalac #{t.prerequisites}" ) end } desc 'Test the Scala implementation that uses primtive types.' task :scala => ScalaFiles.map { | name | classFileOf( name ) } do sys( "scala #{ScalaTestClassName}" ) end ######## Groovy #################################################### # Temporarily there is a problem with using source file, so we must create the class file. file 'Factorial_G.class' => 'Factorial_G.groovy' do | t | sys( "groovyc #{t.prerequisites}" ) end file 'Factorial_memoized.class' => 'Factorial_memoized.groovy' do | t | sys( "groovyc #{t.prerequisites}" ) end desc 'Test the Groovy implementation with Junit.' task :groovy_junit => 'Factorial_G.class' do sys( './Factorial_G_Test_JUnit.groovy' ) end desc 'Test the Groovy implementation with TestNGroove.' task :groovy_testngroove => 'Factorial_G.class' do sys( './Factorial_G_TestNGroove.groovy' ) end desc 'Test the memoized Groovy implementation with Junit.' task :groovy_memoized_junit => 'Factorial_memoized.class' do sys( './Factorial_memoized_Test_JUnit.groovy' ) end desc 'Test the memoized Groovy implementation with TestNGroove.' task :groovy_memoized_testngroove => 'Factorial_memoized.class' do sys( './Factorial_memoized_TestNGroove.groovy' ) end ######## Python #################################################### desc 'Test the Python implementation.' task :python do sys( './factorial_test.py' ) end ######## Ruby ###################################################### desc 'Test the Ruby implementation.' task :ruby do sys( './factorial_test.rb' ) end ######## Haskell ################################################### HaskellRoot = 'factorial_test' HaskellMain = HaskellRoot + '.hs' HaskellFiles = [ HaskellMain , 'Factorial.hs' ] HaskellExecutable = HaskellRoot + '_haskell' file HaskellExecutable => HaskellFiles do | t | sys( "ghc --make -o #{HaskellExecutable} #{HaskellMain}" ) end desc 'Test the Haskell implementation.' task :haskell => HaskellExecutable do sys( HaskellExecutable ) end ######## Objective Caml ############################################ OCamlModuleRoot = 'factorial' OCamlModule = OCamlModuleRoot + '.ml' OCamlRoot = OCamlModuleRoot + '_test' OCamlMain = OCamlRoot + '.ml' OCamlFiles = [ OCamlModule , OCamlMain ] # Order is critical here. OCamlExecutable = OCamlRoot + '_ocaml' file OCamlExecutable => OCamlFiles do | t | sys( "ocamlfind ocamlopt -package oUnit -package num -linkpkg -o #{OCamlExecutable} #{OCamlFiles.join( ' ' ) }" ) end desc 'Test the O Caml implementation.' task :ocaml => OCamlExecutable do sys( OCamlExecutable ) end ######## Erlang ##################################################### ErlangModuleRoot = 'factorial' ErlangModule = ErlangModuleRoot + '.erl' ErlangExecutable = ErlangModuleRoot + '.beam' file ErlangExecutable => ErlangModule do | t | sys( "erlc -DTEST #{ErlangModule}" ) end desc 'Test the Erlang implementation' task :erlang => ErlangExecutable do | t | sys( "erl -noshell -eval #{ErlangModuleRoot}:test\\(\\) -run init stop" ) end ###################################################################### task :default => [ :c , :c_gmp , :cpp , :cpp_gmp , :csharp , :csharp_biginteger , :java , :java_biginteger , :groovy_java_junit , :groovy_java_testngroove , :groovy_junit , :groovy_testngroove , :groovy_memoized_junit , :groovy_memoized_testngroove , :python , :ruby , :haskell , :ocaml , :erlang ]