forked from google/kati
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.ckati
121 lines (103 loc) · 3.66 KB
/
Makefile.ckati
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
# Copyright 2015 Google Inc. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Find source file location from path to this Makefile
KATI_SRC_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
# Set defaults if they weren't set by the including Makefile
KATI_CXX ?= $(CXX)
KATI_LD ?= $(CXX)
KATI_INTERMEDIATES_PATH ?= .
KATI_BIN_PATH ?= .
KATI_CXX_SRCS := \
command.cc \
dep.cc \
eval.cc \
exec.cc \
expr.cc \
file.cc \
file_cache.cc \
fileutil.cc \
find.cc \
flags.cc \
func.cc \
io.cc \
log.cc \
main.cc \
ninja.cc \
parser.cc \
rule.cc \
stats.cc \
stmt.cc \
string_piece.cc \
stringprintf.cc \
strutil.cc \
symtab.cc \
timeutil.cc \
var.cc
KATI_CXX_GENERATED_SRCS := \
version.cc
KATI_CXX_SRCS := $(addprefix $(KATI_SRC_PATH)/,$(KATI_CXX_SRCS))
KATI_CXX_TEST_SRCS:= $(wildcard $(KATI_SRC_PATH)/*_test.cc)
KATI_CXX_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
$(KATI_CXX_SRCS))
KATI_CXX_GENERATED_OBJS := $(patsubst %.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
$(KATI_CXX_GENERATED_SRCS))
KATI_CXX_TEST_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
$(KATI_CXX_TEST_SRCS))
KATI_CXX_TEST_EXES := $(patsubst $(KATI_INTERMEDIATES_PATH)/%.o,$(KATI_BIN_PATH)/%,\
$(KATI_CXX_TEST_OBJS))
KATI_CXXFLAGS := -g -W -Wall -MMD -MP
KATI_CXXFLAGS += -O -DNOLOG
#KATI_CXXFLAGS += -pg
ifeq ($(shell uname),Linux)
KATI_LIBS := -lrt
endif
# Rule to build ckati into KATI_BIN_PATH
$(KATI_BIN_PATH)/ckati: $(KATI_CXX_OBJS) $(KATI_CXX_GENERATED_OBJS)
@mkdir -p $(dir $@)
$(KATI_LD) -std=c++11 $(KATI_CXXFLAGS) -o $@ $^ $(KATI_LIBS)
# Rule to build normal source files into object files in KATI_INTERMEDIATES_PATH
$(KATI_CXX_OBJS) $(KATI_CXX_TEST_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_SRC_PATH)/%.cc
@mkdir -p $(dir $@)
$(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
# Rule to build generated source files into object files in KATI_INTERMEDIATES_PATH
$(KATI_CXX_GENERATED_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_INTERMEDIATES_PATH)/%.cc
@mkdir -p $(dir $@)
$(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
ckati_tests: $(KATI_CXX_TEST_EXES)
# Rule to build tests using *_test.cc and all normal *.cc files except main.cc
$(KATI_CXX_TEST_EXES): $(filter-out $(KATI_INTERMEDIATES_PATH)/main.o,$(KATI_CXX_OBJS)) $(KATI_CXX_GENERATED_OBJS)
$(KATI_CXX_TEST_EXES): $(KATI_BIN_PATH)/%: $(KATI_INTERMEDIATES_PATH)/%.o
$(KATI_LD) $^ -o $@ $(KATI_LIBS)
# Rule to generate version.cc
KATI_GIT_DIR := $(shell git -C $(KATI_SRC_PATH) rev-parse --show-toplevel)
ifneq ($(KATI_GIT_DIR),)
KATI_VERSION_DEPS := $(KATI_GIT_DIR)/.git/HEAD $(KATI_GIT_DIR)/.git/index
KATI_VERSION := $(shell git -C $(KATI_GIT_DIR) rev-parse HEAD)
else
KATI_VERSION_DEPS :=
KATI_VERSION := unknown
endif
$(KATI_INTERMEDIATES_PATH)/version.cc: $(KATI_VERSION_DEPS)
@mkdir -p $(dir $@)
echo '// +build ignore' > $@
echo >> $@
echo 'const char* kGitVersion = "$(KATI_VERSION)";' >> $@
ckati_clean:
rm -rf $(KATI_INTERMEDIATES_PATH)/ckati
rm -rf $(KATI_INTERMEDIATES_PATH)/*.o
rm -rf $(KATI_INTERMEDIATES_PATH)/*.d
rm -rf $(KATI_INTERMEDIATES_PATH)/version.cc
rm -rf $(KATI_CXX_TEST_EXES)
.PHONY: ckati_clean
-include $(KATI_INTERMEDIATES_PATH)/*.d