Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 1 | # 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 Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 15 | # Find source file location from path to this Makefile |
| 16 | KATI_SRC_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) |
Colin Cross | f479d54 | 2015-07-21 14:37:48 -0700 | [diff] [blame] | 17 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 18 | # Set defaults if they weren't set by the including Makefile |
| 19 | KATI_CXX ?= $(CXX) |
| 20 | KATI_LD ?= $(CXX) |
| 21 | KATI_INTERMEDIATES_PATH ?= . |
| 22 | KATI_BIN_PATH ?= . |
| 23 | |
| 24 | KATI_CXX_SRCS := \ |
Shinichiro Hamaji | 1a444a8 | 2016-02-16 13:49:49 +0900 | [diff] [blame] | 25 | affinity.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 26 | command.cc \ |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 27 | condvar.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 28 | dep.cc \ |
| 29 | eval.cc \ |
| 30 | exec.cc \ |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 31 | expr.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 32 | file.cc \ |
| 33 | file_cache.cc \ |
| 34 | fileutil.cc \ |
| 35 | find.cc \ |
| 36 | flags.cc \ |
| 37 | func.cc \ |
Shinichiro Hamaji | a4bb774 | 2015-07-31 11:27:30 +0900 | [diff] [blame] | 38 | io.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 39 | log.cc \ |
| 40 | main.cc \ |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 41 | mutex.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 42 | ninja.cc \ |
| 43 | parser.cc \ |
Shinichiro Hamaji | 8ef0ce5 | 2016-01-19 18:07:43 +0900 | [diff] [blame] | 44 | regen.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 45 | rule.cc \ |
| 46 | stats.cc \ |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 47 | stmt.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 48 | string_piece.cc \ |
| 49 | stringprintf.cc \ |
| 50 | strutil.cc \ |
| 51 | symtab.cc \ |
Shinichiro Hamaji | 6bbf9e2 | 2016-01-19 18:59:13 +0900 | [diff] [blame] | 52 | thread.cc \ |
Shinichiro Hamaji | 702befc | 2016-01-27 17:21:39 +0900 | [diff] [blame] | 53 | thread_pool.cc \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 54 | timeutil.cc \ |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 55 | var.cc |
| 56 | |
| 57 | KATI_CXX_GENERATED_SRCS := \ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 58 | version.cc |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 59 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 60 | KATI_CXX_SRCS := $(addprefix $(KATI_SRC_PATH)/,$(KATI_CXX_SRCS)) |
Shinichiro Hamaji | cba1fb4 | 2016-02-02 18:01:45 +0900 | [diff] [blame] | 61 | KATI_CXX_TEST_SRCS := \ |
| 62 | $(wildcard $(KATI_SRC_PATH)/*_test.cc) \ |
| 63 | $(wildcard $(KATI_SRC_PATH)/*_bench.cc) |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 64 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 65 | KATI_CXX_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\ |
| 66 | $(KATI_CXX_SRCS)) |
| 67 | KATI_CXX_GENERATED_OBJS := $(patsubst %.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\ |
| 68 | $(KATI_CXX_GENERATED_SRCS)) |
| 69 | KATI_CXX_TEST_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\ |
| 70 | $(KATI_CXX_TEST_SRCS)) |
| 71 | |
| 72 | KATI_CXX_TEST_EXES := $(patsubst $(KATI_INTERMEDIATES_PATH)/%.o,$(KATI_BIN_PATH)/%,\ |
| 73 | $(KATI_CXX_TEST_OBJS)) |
| 74 | |
| 75 | KATI_CXXFLAGS := -g -W -Wall -MMD -MP |
| 76 | KATI_CXXFLAGS += -O -DNOLOG |
Shinichiro Hamaji | 096bb4e | 2016-02-03 13:24:34 +0900 | [diff] [blame] | 77 | KATI_CXXFLAGS += -march=native |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 78 | #KATI_CXXFLAGS += -pg |
| 79 | |
Shinichiro Hamaji | 2966958 | 2015-08-17 16:32:00 +0900 | [diff] [blame] | 80 | ifeq ($(shell uname),Linux) |
Shinichiro Hamaji | 4197da6 | 2016-01-25 16:06:29 +0900 | [diff] [blame] | 81 | KATI_LIBS := -lrt -lpthread |
Shinichiro Hamaji | 2966958 | 2015-08-17 16:32:00 +0900 | [diff] [blame] | 82 | endif |
| 83 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 84 | # Rule to build ckati into KATI_BIN_PATH |
| 85 | $(KATI_BIN_PATH)/ckati: $(KATI_CXX_OBJS) $(KATI_CXX_GENERATED_OBJS) |
| 86 | @mkdir -p $(dir $@) |
Shinichiro Hamaji | 2966958 | 2015-08-17 16:32:00 +0900 | [diff] [blame] | 87 | $(KATI_LD) -std=c++11 $(KATI_CXXFLAGS) -o $@ $^ $(KATI_LIBS) |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 88 | |
| 89 | # Rule to build normal source files into object files in KATI_INTERMEDIATES_PATH |
| 90 | $(KATI_CXX_OBJS) $(KATI_CXX_TEST_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_SRC_PATH)/%.cc |
| 91 | @mkdir -p $(dir $@) |
| 92 | $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $< |
| 93 | |
| 94 | # Rule to build generated source files into object files in KATI_INTERMEDIATES_PATH |
| 95 | $(KATI_CXX_GENERATED_OBJS): $(KATI_INTERMEDIATES_PATH)/%.o: $(KATI_INTERMEDIATES_PATH)/%.cc |
| 96 | @mkdir -p $(dir $@) |
Colin Cross | f479d54 | 2015-07-21 14:37:48 -0700 | [diff] [blame] | 97 | $(KATI_CXX) -c -std=c++11 $(KATI_CXXFLAGS) -o $@ $< |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 98 | |
Colin Cross | f479d54 | 2015-07-21 14:37:48 -0700 | [diff] [blame] | 99 | ckati_tests: $(KATI_CXX_TEST_EXES) |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 100 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 101 | # Rule to build tests using *_test.cc and all normal *.cc files except main.cc |
| 102 | $(KATI_CXX_TEST_EXES): $(filter-out $(KATI_INTERMEDIATES_PATH)/main.o,$(KATI_CXX_OBJS)) $(KATI_CXX_GENERATED_OBJS) |
| 103 | $(KATI_CXX_TEST_EXES): $(KATI_BIN_PATH)/%: $(KATI_INTERMEDIATES_PATH)/%.o |
Shinichiro Hamaji | 2966958 | 2015-08-17 16:32:00 +0900 | [diff] [blame] | 104 | $(KATI_LD) $^ -o $@ $(KATI_LIBS) |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 105 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 106 | # Rule to generate version.cc |
Colin Cross | 358cda7 | 2015-09-02 16:03:14 -0700 | [diff] [blame] | 107 | KATI_GIT_DIR := $(shell git -C $(KATI_SRC_PATH) rev-parse --show-toplevel) |
| 108 | ifneq ($(KATI_GIT_DIR),) |
| 109 | KATI_VERSION_DEPS := $(KATI_GIT_DIR)/.git/HEAD $(KATI_GIT_DIR)/.git/index |
| 110 | KATI_VERSION := $(shell git -C $(KATI_GIT_DIR) rev-parse HEAD) |
| 111 | else |
| 112 | KATI_VERSION_DEPS := |
| 113 | KATI_VERSION := unknown |
| 114 | endif |
| 115 | $(KATI_INTERMEDIATES_PATH)/version.cc: $(KATI_VERSION_DEPS) |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 116 | @mkdir -p $(dir $@) |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 117 | echo '// +build ignore' > $@ |
| 118 | echo >> $@ |
Colin Cross | 358cda7 | 2015-09-02 16:03:14 -0700 | [diff] [blame] | 119 | echo 'const char* kGitVersion = "$(KATI_VERSION)";' >> $@ |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 120 | |
Shinichiro Hamaji | 844ff75 | 2016-01-27 18:02:58 +0900 | [diff] [blame] | 121 | tsan_ckati: |
| 122 | $(MAKE) clean |
| 123 | $(MAKE) all CXX='clang++-3.6 -fsanitize=thread' |
| 124 | cp ckati $@ |
| 125 | |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 126 | ckati_clean: |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 127 | rm -rf $(KATI_INTERMEDIATES_PATH)/ckati |
| 128 | rm -rf $(KATI_INTERMEDIATES_PATH)/*.o |
| 129 | rm -rf $(KATI_INTERMEDIATES_PATH)/*.d |
| 130 | rm -rf $(KATI_INTERMEDIATES_PATH)/version.cc |
| 131 | rm -rf $(KATI_CXX_TEST_EXES) |
Colin Cross | 43767ff | 2015-07-21 14:35:33 -0700 | [diff] [blame] | 132 | |
| 133 | .PHONY: ckati_clean |
| 134 | |
Colin Cross | 65b44b0 | 2015-07-21 15:36:08 -0700 | [diff] [blame] | 135 | -include $(KATI_INTERMEDIATES_PATH)/*.d |