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 | |
Colin Cross | 69047fa | 2015-09-18 14:50:26 -0700 | [diff] [blame] | 62 | .PHONY: makeparallel_test |
| 63 | MAKEPARALLEL_TEST := MAKEFLAGS= MAKELEVEL= MAKEPARALLEL=$(MAKEPARALLEL) $(MAKE) -f Makefile.test test |
| 64 | MAKEPARALLEL_NINJA_TEST := MAKEFLAGS= MAKELEVEL= MAKEPARALLEL="$(MAKEPARALLEL) --ninja" $(MAKE) -f Makefile.test test |
| 65 | makeparallel_test: $(MAKEPARALLEL) |
| 66 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -j1234 |
| 67 | @EXPECTED="-j123" $(MAKEPARALLEL_TEST) -j123 |
Colin Cross | ba55c62 | 2017-01-18 14:38:20 -0800 | [diff] [blame] | 68 | @EXPECTED="" $(MAKEPARALLEL_TEST) -j1 |
| 69 | @EXPECTED="-j$$(($$(nproc) + 2))" $(MAKEPARALLEL_TEST) -j |
| 70 | @EXPECTED="" $(MAKEPARALLEL_TEST) |
Colin Cross | 69047fa | 2015-09-18 14:50:26 -0700 | [diff] [blame] | 71 | |
| 72 | @EXPECTED="-j1234" $(MAKEPARALLEL_NINJA_TEST) -j1234 |
| 73 | @EXPECTED="-j123" $(MAKEPARALLEL_NINJA_TEST) -j123 |
| 74 | @EXPECTED="-j1" $(MAKEPARALLEL_NINJA_TEST) -j1 |
| 75 | @EXPECTED="-j1" $(MAKEPARALLEL_NINJA_TEST) |
| 76 | @EXPECTED="" $(MAKEPARALLEL_NINJA_TEST) -j |
| 77 | @EXPECTED="" $(MAKEPARALLEL_NINJA_TEST) -j -l |
| 78 | |
| 79 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) --no-print-directory -j1234 |
| 80 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) --no-print-directory -k -j1234 |
| 81 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -k -j1234 |
| 82 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -j1234 -k |
| 83 | @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -kt -j1234 |
| 84 | |
| 85 | @EXPECTED="-j1234" $(MAKEPARALLEL_NINJA_TEST) --no-print-directory -j1234 |
| 86 | @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) --no-print-directory -k -j1234 |
| 87 | @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -k -j1234 |
| 88 | @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -j1234 -k |
| 89 | @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -kt -j1234 |
| 90 | |
Colin Cross | ba55c62 | 2017-01-18 14:38:20 -0800 | [diff] [blame] | 91 | @EXPECTED="" $(MAKEPARALLEL_TEST) A=-j1234 |
Colin Cross | 466ea35 | 2015-10-20 15:41:05 -0700 | [diff] [blame] | 92 | |
| 93 | @EXPECTED="-j1234 args" ARGS="args" $(MAKEPARALLEL_TEST) -j1234 |