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: 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 68 @EXPECTED="-j1" $(MAKEPARALLEL_TEST) -j1 69 @EXPECTED="-j1" $(MAKEPARALLEL_TEST) 70 71 @EXPECTED="-j1234" $(MAKEPARALLEL_NINJA_TEST) -j1234 72 @EXPECTED="-j123" $(MAKEPARALLEL_NINJA_TEST) -j123 73 @EXPECTED="-j1" $(MAKEPARALLEL_NINJA_TEST) -j1 74 @EXPECTED="-j1" $(MAKEPARALLEL_NINJA_TEST) 75 @EXPECTED="" $(MAKEPARALLEL_NINJA_TEST) -j 76 @EXPECTED="" $(MAKEPARALLEL_NINJA_TEST) -j -l 77 78 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) --no-print-directory -j1234 79 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) --no-print-directory -k -j1234 80 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -k -j1234 81 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -j1234 -k 82 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) -kt -j1234 83 84 @EXPECTED="-j1234" $(MAKEPARALLEL_NINJA_TEST) --no-print-directory -j1234 85 @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) --no-print-directory -k -j1234 86 @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -k -j1234 87 @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -j1234 -k 88 @EXPECTED="-j1234 -k0" $(MAKEPARALLEL_NINJA_TEST) -kt -j1234 89 90 @EXPECTED="-j1" $(MAKEPARALLEL_TEST) A=-j1234 91 @EXPECTED="-j1" $(MAKEPARALLEL_TEST) A\ -j1234=-j1234 92 @EXPECTED="-j1234" $(MAKEPARALLEL_TEST) A\ -j1234=-j1234 -j1234 93 94 @EXPECTED="-j1234 args" ARGS="args" $(MAKEPARALLEL_TEST) -j1234 95