Colin Cross | a555448 | 2015-09-05 21:16:19 -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 | |
| 15 | # Find source file location from path to this Makefile |
| 16 | MAKEPARALLEL_SRC_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) |
| 17 | ifndef MAKEPARALLEL_SRC_PATH |
| 18 | MAKEPARALLEL_SRC_PATH := . |
| 19 | endif |
| 20 | |
| 21 | # Set defaults if they weren't set by the including Makefile |
| 22 | MAKEPARALLEL_CXX ?= $(CXX) |
| 23 | MAKEPARALLEL_LD ?= $(CXX) |
| 24 | MAKEPARALLEL_INTERMEDIATES_PATH ?= . |
| 25 | MAKEPARALLEL_BIN_PATH ?= . |
| 26 | |
| 27 | MAKEPARALLEL_CXX_SRCS := \ |
| 28 | makeparallel.cpp |
| 29 | |
| 30 | MAKEPARALLEL_CXXFLAGS := -Wall -Werror -MMD -MP |
| 31 | |
| 32 | MAKEPARALLEL_CXX_SRCS := $(addprefix $(MAKEPARALLEL_SRC_PATH)/,\ |
| 33 | $(MAKEPARALLEL_CXX_SRCS)) |
| 34 | |
| 35 | MAKEPARALLEL_CXX_OBJS := $(patsubst $(MAKEPARALLEL_SRC_PATH)/%.cpp,$(MAKEPARALLEL_INTERMEDIATES_PATH)/%.o,$(MAKEPARALLEL_CXX_SRCS)) |
| 36 | |
| 37 | MAKEPARALLEL := $(MAKEPARALLEL_BIN_PATH)/makeparallel |
| 38 | |
| 39 | ifeq ($(shell uname),Linux) |
| 40 | MAKEPARALLEL_LIBS := -lrt -lpthread |
| 41 | endif |
| 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 | |
| 53 | makeparallel_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 |
| 63 | test: $(MAKEPARALLEL) |
| 64 | MAKEFLAGS= $(MAKE) -j1234 -C $(MAKEPARALLEL_SRC_PATH) -f Makefile.test MAKEPARALLEL=$(MAKEPARALLEL) test |