OSDN Git Service

parser_testをDatumParserに対応。
[simplecms/utakata.git] / Rakefile
1 # -*- coding: utf-8 -*-
2 require "rake/clean"
3 require "rake/loaders/makefile"
4
5 CC = "g++"
6 cflags = "-g -O2 -fno-default-inline -Wall -g"
7
8 TOPDIR = "."
9
10 ldflags = "-DHAVE_CONFIG_H "
11 ldflags += "-L./test/gtest/gtest-all"
12
13 includes = " "
14 includes += "-I. -I."
15
16 # lists of compile dependency objects
17 TOP_DIR = File.expand_path "."
18 SRCS = FileList[File.join(TOP_DIR, "src/**/*.cpp"), File.join(TOP_DIR, "lib/**/*.cpp")]
19 SRCS_ALL = FileList[SRCS, File.join(TOP_DIR, "src/**/*.h"), File.join(TOP_DIR, "lib/**/*.h")]
20 OBJS = SRCS.ext("o")
21 DEPS = SRCS.ext("mf")
22 TEST_SRCS = FileList[File.join(TOP_DIR, "test/*.cpp")]
23 TEST_OBJECTS = TEST_SRCS.ext("o")
24 TEST_OBJECTS.include(OBJS)
25 TEST_DEPS = TEST_SRCS.ext("mf")
26 TEST_PROGRAMS = TEST_SRCS.ext("")
27
28 EXEEXT = ""
29
30 # lists of clean objects
31 CLEAN.include(OBJS, TEST_OBJECTS, DEPS)
32 CLOBBER.include(TEST_PROGRAMS)
33
34 task "default" => ["compile"]
35 task "test" => ["compile", "test_execute"]
36
37 desc "Compile all sources "
38 task "compile" => OBJS do |t|
39 end
40
41 DEPS.each { |f|
42   depname = File.split(f)
43   depname[1] = File.basename(depname[1], ".mf") + ".cpp"
44   desc "make #{f} dependencies"
45   file "#{f}" => [File.join(depname)]
46 }
47
48 DEPS.each { |f| import f}
49
50 rule "_test#{EXEEXT}" => TEST_OBJECTS do |t|
51   base = File.split(t.name);
52   base[1] = File.basename(base[1], EXEEXT) + ".o"
53   sh "#{CC} -o #{File.expand_path(t.name)} #{ldflags} #{cflags} #{includes} #{OBJS.join(' ')} ./test/gtest/gtest-all.o #{File.join(base)} "
54 end
55
56 rule '.o' => '.cpp' do |t|
57   depname = File.split(t.source)
58   depname[1] = File.basename(depname[1], ".cpp") + ".mf"
59   sh "#{CC} #{ldflags} #{cflags} #{includes} -c #{t.source} -o #{t.name}"
60 end
61
62 rule '.mf' => '.cpp' do |t|
63   depname = File.split(t.source)
64   depname[1] = File.basename(depname[1], ".cpp") + ".mf"
65   sh "#{CC} -MM -MF #{File.join(depname[0], depname[1])} #{ldflags} #{cflags} #{includes} #{t.source}"
66   import File.join(depname[0], depname[1])
67 end
68
69 desc "run all test program in `TEST_PROGRAMS`"
70 task :test_execute => TEST_PROGRAMS do |t|
71   t.prerequisites.each { |f|
72     sh "#{f} --gtest_color=yes"
73   }
74 end
75
76 # Makefile形式のデータを、複数行から一行形式に変換します。
77 def replace_make_to_rake(make_base_file, to_file)
78   file_data = File.read make_base_file
79
80   file_data = file_data.gsub(/\r\n|\r|\n/, "\n")
81   file_data = file_data.gsub(/\\\s+/, " ")
82   file_data = file_data.split "\n"
83   open(to_file, "a") do |d|
84     (file_data.select {|f| !f.empty? }).each { |x| d << x << "\n"}
85   end
86 end