OSDN Git Service

sublexer.cppに定義されていたlexerの再定義が完了したため、削除。
[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 SRCS = FileList["./src/**/*.cpp", "./lib/**/*.cpp"]
18 SRCS_ALL = FileList[SRCS, "./src/**/*.h", "./lib/**/*.h"]
19 OBJS = SRCS.ext("o")
20 DEPS = SRCS.ext("mf")
21 TEST_SRCS = FileList["./test/*.cpp"]
22 TEST_OBJECTS = TEST_SRCS.ext("o")
23 TEST_OBJECTS.include(OBJS)
24 TEST_DEPS = TEST_SRCS.ext("mf")
25 TEST_PROGRAMS = TEST_SRCS.ext(".exe")
26
27 EXEEXT = ".exe"
28
29 # lists of clean objects
30 CLEAN.include(OBJS, TEST_OBJECTS)
31 CLEAN.include(".depend.mf")
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 rule "_test#{EXEEXT}" => TEST_OBJECTS do |t|
42   fullpath = File.expand_path t.name
43   base = File.split(t.name);
44   base[1] = File.basename(base[1], EXEEXT) + ".o"
45   sh "#{CC} -o #{File.expand_path(t.name)} #{ldflags} #{cflags} #{includes} #{OBJS.join(' ')} ./test/gtest/gtest-all.o #{File.join(base)} "
46 end
47
48 rule '.o' => '.cpp' do |t|
49   fullpath = File.expand_path t.source
50   depname = File.split(t.source)
51   depname[1] = File.basename(depname[1], ".cpp") + ".mf"
52   sh "#{CC} #{ldflags} #{cflags} #{includes} -c #{fullpath} -o #{t.name}"
53 end
54
55 # -MM による依存性の抽出を行います。既存の依存性については、
56 file ".depend.mf" => SRCS do |t|
57   rm t.name if File.exists? t.name
58
59   t.prerequisites.each do |f|
60     depname = File.split(f)
61     depname[1] = File.basename(depname[1], ".cpp") + ".mf"
62     sh "#{CC} -MM -MF #{File.join(depname[0], depname[1])} #{ldflags} #{cflags} #{includes} #{f}"
63
64     replace_make_to_rake File.join(depname[0], depname[1]), t.name
65     # sh "cat #{File.join(depname[0], depname[1])} >> #{t.name}"
66     rm File.join(depname[0], depname[1])
67   end
68 end
69
70 import ".depend.mf"
71
72 desc "run all test program in `TEST_PROGRAMS`"
73 task :test_execute => TEST_PROGRAMS do |t|
74   t.prerequisites.each { |f|
75     sh "#{f} --gtest_color=yes"
76   }
77 end
78
79 # Makefile形式のデータを、複数行から一行形式に変換します。
80 def replace_make_to_rake(make_base_file, to_file)
81   file_data = File.read make_base_file
82
83   file_data = file_data.gsub(/\r\n|\r|\n/, "\n")
84   file_data = file_data.gsub(/\\\s+/, " ")
85   file_data = file_data.split "\n"
86   open(to_file, "a") do |d|
87     (file_data.select {|f| !f.empty? }).each { |x| d << x << "\n"}
88   end
89 end