This repository was archived by the owner on Sep 30, 2025. It is now read-only.
forked from mrtazz/plustache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrakefile
More file actions
148 lines (120 loc) · 3.72 KB
/
rakefile
File metadata and controls
148 lines (120 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# rakefile for compiling plustache and tests
require 'rake/clean'
require 'rake/loaders/makefile'
# install prefix
PREFIX = "./"
# binaries
APPLICATION = "bin/plustache"
TEST = "bin/plustache_tests"
STATIC_LIB = "lib/libplustache.a"
DYNAMIC_LIB = ""
# directories
BINDIR = "bin"
OBJDIR = "build"
LIBDIR = "lib"
# main plustache files
SRC_FILES = FileList['src/template.cpp', 'src/context.cpp']
SRC_OBJECTS = SRC_FILES.collect { |fn|
File.join(OBJDIR, File.basename(fn).ext('o'))
}
# files for unit testing
TEST_FILES = FileList["tests/*.cpp"]
TEST_OBJECTS = TEST_FILES.collect { |fn|
File.join(OBJDIR, File.basename(fn).ext('o'))
}
# files for the plustache binary
BIN_FILES = FileList['src/main.cpp']
BIN_OBJECTS = BIN_FILES.collect { |fn|
File.join(OBJDIR, File.basename(fn).ext('o'))
}
# include dirs
INCLUDE_DIRS = [".", "/usr/local/include"]
LDFLAGS = ["-L /usr/local/lib"]
res = %x[uname].chomp
if res == "Darwin"
DYNFLAGS = ["-dynamiclib"]
DYNAMIC_LIB = "lib/libplustache.dylib"
elsif res == "Linux"
INCLUDE_DIRS.push("/usr/include")
LDFLAGS.push("-L/usr/lib")
end
# compiler/linker stuff
CC = "g++"
LD = "g++"
CCFLAGS = ["-O3","-Wall", "-fPIC", "-I #{INCLUDE_DIRS.join(" -I ")}"]
# task definitions
task :default => "test:unit"
namespace :test do
desc "task for compiling and executing unit tests"
task :unit => TEST do
sh "./#{TEST}"
end
desc "task for style and error checking with cppcheck"
task :style do
sh "cppcheck -I #{INCLUDE_DIRS.join(" -I ")} --enable=all src/"
end
end
desc "install plustache as dynamic library"
task :install => :dynamic do
prefix = ENV['PREFIX'] || ENV['prefix'] || PREFIX
FileUtils.mkdir_p "#{prefix}/include"
FileUtils.cp "include/template.hpp", "#{prefix}/include"
FileUtils.cp "include/context.hpp", "#{prefix}/include"
FileUtils.cp "include/plustache_types.hpp", "#{prefix}/include"
FileUtils.mkdir_p "#{prefix}/lib"
FileUtils.cp "#{DYNAMIC_LIB}", "#{prefix}/lib"
end
desc "task compiling plustache binary"
task :app => APPLICATION do
sh "./#{APPLICATION}"
end
desc "task for compiling static plustache library"
task :static => STATIC_LIB do
end
desc "task for compiling dynamic plustache library"
task :dynamic => DYNAMIC_LIB do
end
# generate dependencies
file '.depend.mf' do
sh "g++ -M -MF .depend.mf -I #{INCLUDE_DIRS.join(' -I')} \
#{SRC_FILES} #{TEST_FILES}"
end
import ".depend.mf"
# main binary rules
directory BINDIR
file APPLICATION => BINDIR
file APPLICATION => SRC_OBJECTS + BIN_OBJECTS do |t|
sh "#{LD} #{SRC_OBJECTS} #{BIN_OBJECTS} -o #{t.name} #{LDFLAGS.join(" ")} \
-lboost_regex"
end
# rules for unit testing
directory BINDIR
file TEST => BINDIR
file TEST => SRC_OBJECTS + TEST_OBJECTS do |t|
sh "#{LD} #{TEST_OBJECTS} #{SRC_OBJECTS} -o #{t.name} #{LDFLAGS.join(" ")} \
-lboost_regex -lgtest"
end
# rules for static library
directory LIBDIR
file STATIC_LIB => LIBDIR
file STATIC_LIB => SRC_OBJECTS do |t|
sh "ar rcs #{STATIC_LIB} #{SRC_OBJECTS}"
end
#
# rules for static library
directory LIBDIR
file DYNAMIC_LIB => LIBDIR
file DYNAMIC_LIB => SRC_OBJECTS do |t|
sh "#{LD} #{DYNFLAGS.join(" ")} -o #{DYNAMIC_LIB} #{SRC_OBJECTS} -lboost_regex"
end
# compile rules for object files
directory OBJDIR
(TEST_FILES+SRC_FILES+BIN_FILES).each do |srcfile|
objfile = File.join(OBJDIR, File.basename(srcfile).ext('o'))
file objfile => [srcfile, OBJDIR] do
sh "#{CC} #{CCFLAGS.join(" ")} -c #{srcfile} -o #{objfile}"
end
end
# cleaning tasks
CLEAN.include("**/*.o", ".depend.mf", OBJDIR)
CLOBBER.include("**/*.o", APPLICATION, TEST, ".depend.mf", OBJDIR, BINDIR, LIBDIR)