blob: ed8fdfc439aed65819460d9a2c3d8e3f13792a5c [file] [log] [blame]
Colin Crossa5554482015-09-05 21:16:19 -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
15# Find source file location from path to this Makefile
16MAKEPARALLEL_SRC_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
17ifndef MAKEPARALLEL_SRC_PATH
18 MAKEPARALLEL_SRC_PATH := .
19endif
20
21# Set defaults if they weren't set by the including Makefile
22MAKEPARALLEL_CXX ?= $(CXX)
23MAKEPARALLEL_LD ?= $(CXX)
24MAKEPARALLEL_INTERMEDIATES_PATH ?= .
25MAKEPARALLEL_BIN_PATH ?= .
26
27MAKEPARALLEL_CXX_SRCS := \
28 makeparallel.cpp
29
30MAKEPARALLEL_CXXFLAGS := -Wall -Werror -MMD -MP
31
32MAKEPARALLEL_CXX_SRCS := $(addprefix $(MAKEPARALLEL_SRC_PATH)/,\
33 $(MAKEPARALLEL_CXX_SRCS))
34
35MAKEPARALLEL_CXX_OBJS := $(patsubst $(MAKEPARALLEL_SRC_PATH)/%.cpp,$(MAKEPARALLEL_INTERMEDIATES_PATH)/%.o,$(MAKEPARALLEL_CXX_SRCS))
36
37MAKEPARALLEL := $(MAKEPARALLEL_BIN_PATH)/makeparallel
38
39ifeq ($(shell uname),Linux)
40MAKEPARALLEL_LIBS := -lrt -lpthread
41endif
42
43# Rule to build makeparallel into MAKEPARALLEL_BIN_PATH
44$(MAKEPARALLEL): $(MAKEPARALLEL_CXX_OBJS)
45 @mkdir -p $(dir $@)
46 $(MAKEPARALLEL_LD) -std=c++11 $(MAKEPARALLEL_CXXFLAGS) -o $@ $^ $(MAKEPARALLEL_LIBS)
47
48# Rule to build source files into object files in MAKEPARALLEL_INTERMEDIATES_PATH
49$(MAKEPARALLEL_CXX_OBJS): $(MAKEPARALLEL_INTERMEDIATES_PATH)/%.o: $(MAKEPARALLEL_SRC_PATH)/%.cpp
50 @mkdir -p $(dir $@)
51 $(MAKEPARALLEL_CXX) -c -std=c++11 $(MAKEPARALLEL_CXXFLAGS) -o $@ $<
52
53makeparallel_clean:
54 rm -rf $(MAKEPARALLEL)
55 rm -rf $(MAKEPARALLEL_INTERMEDIATES_PATH)/*.o
56 rm -rf $(MAKEPARALLEL_INTERMEDIATES_PATH)/*.d
57
58.PHONY: makeparallel_clean
59
60-include $(MAKEPARALLEL_INTERMEDIATES_PATH)/*.d
61
62.PHONY: test
63test: $(MAKEPARALLEL)
64 MAKEFLAGS= $(MAKE) -j1234 -C $(MAKEPARALLEL_SRC_PATH) -f Makefile.test MAKEPARALLEL=$(MAKEPARALLEL) test