blob: e4067bb1d9028fef6b27169766579f42a9134c5b [file] [log] [blame]
Colin Cross43767ff2015-07-21 14:35:33 -07001# Copyright 2015 Google Inc. All rights reserved
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Colin Cross65b44b02015-07-21 15:36:08 -070015# Find source file location from path to this Makefile
16KATI_SRC_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
Colin Crossf479d542015-07-21 14:37:48 -070017
Colin Cross65b44b02015-07-21 15:36:08 -070018# Set defaults if they weren't set by the including Makefile
19KATI_CXX ?= $(CXX)
20KATI_LD ?= $(CXX)
21KATI_INTERMEDIATES_PATH ?= .
22KATI_BIN_PATH ?= .
23
24KATI_CXX_SRCS := \
Shinichiro Hamaji1a444a82016-02-16 13:49:49 +090025 affinity.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070026 command.cc \
27 dep.cc \
28 eval.cc \
29 exec.cc \
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090030 expr.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070031 file.cc \
32 file_cache.cc \
33 fileutil.cc \
34 find.cc \
35 flags.cc \
36 func.cc \
Shinichiro Hamajia4bb7742015-07-31 11:27:30 +090037 io.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070038 log.cc \
39 main.cc \
40 ninja.cc \
41 parser.cc \
Shinichiro Hamaji8ef0ce52016-01-19 18:07:43 +090042 regen.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070043 rule.cc \
44 stats.cc \
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090045 stmt.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070046 string_piece.cc \
47 stringprintf.cc \
48 strutil.cc \
49 symtab.cc \
Shinichiro Hamaji702befc2016-01-27 17:21:39 +090050 thread_pool.cc \
Colin Cross43767ff2015-07-21 14:35:33 -070051 timeutil.cc \
Colin Cross65b44b02015-07-21 15:36:08 -070052 var.cc
53
54KATI_CXX_GENERATED_SRCS := \
Colin Cross43767ff2015-07-21 14:35:33 -070055 version.cc
Colin Cross43767ff2015-07-21 14:35:33 -070056
Colin Cross65b44b02015-07-21 15:36:08 -070057KATI_CXX_SRCS := $(addprefix $(KATI_SRC_PATH)/,$(KATI_CXX_SRCS))
Shinichiro Hamajicba1fb42016-02-02 18:01:45 +090058KATI_CXX_TEST_SRCS := \
59 $(wildcard $(KATI_SRC_PATH)/*_test.cc) \
Dan Willemsen9862c2a2016-09-30 19:42:53 -070060 $(filter-out $(KATI_SRC_PATH)/fileutil_bench.cc,\
61 $(wildcard $(KATI_SRC_PATH)/*_bench.cc))
Colin Cross43767ff2015-07-21 14:35:33 -070062
Colin Cross65b44b02015-07-21 15:36:08 -070063KATI_CXX_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
64 $(KATI_CXX_SRCS))
65KATI_CXX_GENERATED_OBJS := $(patsubst %.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
66 $(KATI_CXX_GENERATED_SRCS))
67KATI_CXX_TEST_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
68 $(KATI_CXX_TEST_SRCS))
69
70KATI_CXX_TEST_EXES := $(patsubst $(KATI_INTERMEDIATES_PATH)/%.o,$(KATI_BIN_PATH)/%,\
71 $(KATI_CXX_TEST_OBJS))
72
73KATI_CXXFLAGS := -g -W -Wall -MMD -MP
74KATI_CXXFLAGS += -O -DNOLOG
Shinichiro Hamaji096bb4e2016-02-03 13:24:34 +090075KATI_CXXFLAGS += -march=native
Colin Cross65b44b02015-07-21 15:36:08 -070076#KATI_CXXFLAGS += -pg
77
Shinichiro Hamaji29669582015-08-17 16:32:00 +090078ifeq ($(shell uname),Linux)
Shinichiro Hamaji4197da62016-01-25 16:06:29 +090079KATI_LIBS := -lrt -lpthread
Shinichiro Hamaji29669582015-08-17 16:32:00 +090080endif
81
Colin Cross65b44b02015-07-21 15:36:08 -070082# Rule to build ckati into KATI_BIN_PATH
83$(KATI_BIN_PATH)/ckati: $(KATI_CXX_OBJS) $(KATI_CXX_GENERATED_OBJS)
84 @mkdir -p $(dir $@)
Shinichiro Hamaji29669582015-08-17 16:32:00 +090085 $(KATI_LD) -std=c++11 $(KATI_CXXFLAGS) -o $@ $^ $(KATI_LIBS)
Colin Cross65b44b02015-07-21 15:36:08 -070086
87# Rule to build normal source files into object files in KATI_INTERMEDIATES_PATH
88$(KATI_CXX_OBJS) $(KATI_CXX_TEST_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_SRC_PATH)/%.cc
89 @mkdir -p $(dir $@)
90 $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
91
92# Rule to build generated source files into object files in KATI_INTERMEDIATES_PATH
93$(KATI_CXX_GENERATED_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_INTERMEDIATES_PATH)/%.cc
94 @mkdir -p $(dir $@)
Colin Crossf479d542015-07-21 14:37:48 -070095 $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $<
Colin Cross43767ff2015-07-21 14:35:33 -070096
Colin Crossf479d542015-07-21 14:37:48 -070097ckati_tests: $(KATI_CXX_TEST_EXES)
Colin Cross43767ff2015-07-21 14:35:33 -070098
Colin Cross65b44b02015-07-21 15:36:08 -070099# Rule to build tests using *_test.cc and all normal *.cc files except main.cc
100$(KATI_CXX_TEST_EXES): $(filter-out $(KATI_INTERMEDIATES_PATH)/main.o,$(KATI_CXX_OBJS)) $(KATI_CXX_GENERATED_OBJS)
101$(KATI_CXX_TEST_EXES): $(KATI_BIN_PATH)/%: $(KATI_INTERMEDIATES_PATH)/%.o
Shinichiro Hamaji29669582015-08-17 16:32:00 +0900102 $(KATI_LD) $^ -o $@ $(KATI_LIBS)
Colin Cross43767ff2015-07-21 14:35:33 -0700103
Colin Cross65b44b02015-07-21 15:36:08 -0700104# Rule to generate version.cc
Colin Cross358cda72015-09-02 16:03:14 -0700105KATI_GIT_DIR := $(shell git -C $(KATI_SRC_PATH) rev-parse --show-toplevel)
106ifneq ($(KATI_GIT_DIR),)
107KATI_VERSION_DEPS := $(KATI_GIT_DIR)/.git/HEAD $(KATI_GIT_DIR)/.git/index
108KATI_VERSION := $(shell git -C $(KATI_GIT_DIR) rev-parse HEAD)
109else
110KATI_VERSION_DEPS :=
111KATI_VERSION := unknown
112endif
113$(KATI_INTERMEDIATES_PATH)/version.cc: $(KATI_VERSION_DEPS)
Colin Cross65b44b02015-07-21 15:36:08 -0700114 @mkdir -p $(dir $@)
Colin Cross43767ff2015-07-21 14:35:33 -0700115 echo '// +build ignore' > $@
116 echo >> $@
Colin Cross358cda72015-09-02 16:03:14 -0700117 echo 'const char* kGitVersion = "$(KATI_VERSION)";' >> $@
Colin Cross43767ff2015-07-21 14:35:33 -0700118
Shinichiro Hamaji844ff752016-01-27 18:02:58 +0900119tsan_ckati:
120 $(MAKE) clean
121 $(MAKE) all CXX='clang++-3.6 -fsanitize=thread'
122 cp ckati $@
123
Colin Cross43767ff2015-07-21 14:35:33 -0700124ckati_clean:
Colin Cross65b44b02015-07-21 15:36:08 -0700125 rm -rf $(KATI_INTERMEDIATES_PATH)/ckati
126 rm -rf $(KATI_INTERMEDIATES_PATH)/*.o
127 rm -rf $(KATI_INTERMEDIATES_PATH)/*.d
128 rm -rf $(KATI_INTERMEDIATES_PATH)/version.cc
129 rm -rf $(KATI_CXX_TEST_EXES)
Stefan Beckerbfae8102016-04-27 11:40:09 +0300130 rm -rf out
Colin Cross43767ff2015-07-21 14:35:33 -0700131
132.PHONY: ckati_clean
133
Colin Cross65b44b02015-07-21 15:36:08 -0700134-include $(KATI_INTERMEDIATES_PATH)/*.d