1 # -*- coding: utf-8 -*-
3 require "rake/loaders/makefile"
6 cflags = "-g -O2 -fno-default-inline -Wall -g"
10 ldflags = "-DHAVE_CONFIG_H "
11 ldflags += "-L./test/gtest/gtest-all"
16 # lists of compile dependency objects
17 SRCS = FileList["./src/**/*.cpp", "./lib/**/*.cpp"]
20 TEST_SRCS = FileList["./test/*.cpp"]
21 TEST_OBJECTS = TEST_SRCS.ext("o")
22 TEST_OBJECTS.include(OBJS)
23 TEST_DEPS = TEST_SRCS.ext("po")
24 TEST_PROGRAMS = TEST_SRCS.ext("")
28 # lists of clean objects
29 CLEAN.include(OBJS, TEST_OBJECTS)
30 CLOBBER.include(TEST_PROGRAMS)
32 task "default" => ["compile"]
33 task "test" => ["compile", "test_execute"]
35 desc "Compile all sources "
36 task "compile" => OBJS do |t|
39 rule "_test#{EXEEXT}" => TEST_OBJECTS do |t|
40 base = File.split(t.name);
41 base[1] = File.basename(base[1], EXEEXT) + ".o"
42 sh "#{CC} -o #{t.name} #{ldflags} #{cflags} #{includes} #{OBJS.join(' ')} ./test/gtest/gtest-all.o #{File.join(base)} "
45 rule '.o' => '.cpp' do |t|
46 depname = File.split(t.source)
47 depname[1] = File.basename(depname[1], ".cpp") + ".po"
48 sh "#{CC} -MD -MF #{File.join(depname[0], depname[1])} #{ldflags} #{cflags} #{includes} -c #{t.source} -o #{t.name}"
51 rule '.h' => '.cpp' do |t|
54 loader = Rake::MakefileLoader.new
56 loader.load(f) if File.exists? f
60 loader.load(f) if File.exists? f
63 desc "run all test program in `TEST_PROGRAMS`"
64 task :test_execute => TEST_PROGRAMS do |t|
65 t.prerequisites.each { |f|
66 sh "#{f} --gtest_color=yes"