-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
1,666 additions
and
1,684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
# We borrow heavily from the kernel build setup, though we are simpler since | ||
# we don't have Kconfig tweaking settings on us. | ||
|
||
# The implicit make rules have it looking for RCS files, among other things. | ||
# We instead explicitly write all the rules we care about. | ||
# It's even quicker (saves ~200ms) to pass -r on the command line. | ||
MAKEFLAGS=-r | ||
|
||
# The source directory tree. | ||
srcdir := %(srcdir)s | ||
abs_srcdir := $(abspath $(srcdir)) | ||
|
||
# The name of the builddir. | ||
builddir_name ?= %(builddir)s | ||
|
||
# The V=1 flag on command line makes us verbosely print command lines. | ||
ifdef V | ||
quiet= | ||
else | ||
quiet=quiet_ | ||
endif | ||
|
||
# Specify BUILDTYPE=Release on the command line for a release build. | ||
BUILDTYPE ?= %(default_configuration)s | ||
|
||
# Directory all our build output goes into. | ||
# Note that this must be two directories beneath src/ for unit tests to pass, | ||
# as they reach into the src/ directory for data with relative paths. | ||
builddir ?= $(builddir_name)/$(BUILDTYPE) | ||
abs_builddir := $(abspath $(builddir)) | ||
depsdir := $(builddir)/.deps | ||
|
||
# Object output directory. | ||
obj := $(builddir)/obj | ||
abs_obj := $(abspath $(obj)) | ||
|
||
# We build up a list of every single one of the targets so we can slurp in the | ||
# generated dependency rule Makefiles in one pass. | ||
all_deps := | ||
|
||
%(make_global_settings)s | ||
|
||
CC.target ?= %(CC.target)s | ||
CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS) | ||
CXX.target ?= %(CXX.target)s | ||
CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS) | ||
LINK.target ?= %(LINK.target)s | ||
LDFLAGS.target ?= $(LDFLAGS) | ||
AR.target ?= $(AR) | ||
|
||
# C++ apps need to be linked with g++. | ||
LINK ?= $(CXX.target) | ||
|
||
# TODO(evan): move all cross-compilation logic to gyp-time so we don't need | ||
# to replicate this environment fallback in make as well. | ||
CC.host ?= %(CC.host)s | ||
CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host) | ||
CXX.host ?= %(CXX.host)s | ||
CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host) | ||
LINK.host ?= %(LINK.host)s | ||
LDFLAGS.host ?= $(LDFLAGS_host) | ||
AR.host ?= %(AR.host)s | ||
|
||
# Define a dir function that can handle spaces. | ||
# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions | ||
# "leading spaces cannot appear in the text of the first argument as written. | ||
# These characters can be put into the argument value by variable substitution." | ||
empty := | ||
space := $(empty) $(empty) | ||
|
||
# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces | ||
replace_spaces = $(subst $(space),{SPACE_REPLACEMENT},$1) | ||
unreplace_spaces = $(subst {SPACE_REPLACEMENT},$(space),$1) | ||
dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1))) | ||
|
||
# Flags to make gcc output dependency info. Note that you need to be | ||
# careful here to use the flags that ccache and distcc can understand. | ||
# We write to a dep file on the side first and then rename at the end | ||
# so we can't end up with a broken dep file. | ||
depfile = $(depsdir)/$(call replace_spaces,$@).d | ||
DEPFLAGS = %(makedep_args)s -MF $(depfile).raw | ||
|
||
# We have to fixup the deps output in a few ways. | ||
# (1) the file output should mention the proper .o file. | ||
# ccache or distcc lose the path to the target, so we convert a rule of | ||
# the form: | ||
# foobar.o: DEP1 DEP2 | ||
# into | ||
# path/to/foobar.o: DEP1 DEP2 | ||
# (2) we want missing files not to cause us to fail to build. | ||
# We want to rewrite | ||
# foobar.o: DEP1 DEP2 \ | ||
# DEP3 | ||
# to | ||
# DEP1: | ||
# DEP2: | ||
# DEP3: | ||
# so if the files are missing, they're just considered phony rules. | ||
# We have to do some pretty insane escaping to get those backslashes | ||
# and dollar signs past make, the shell, and sed at the same time. | ||
# Doesn't work with spaces, but that's fine: .d files have spaces in | ||
# their names replaced with other characters. | ||
define fixup_dep | ||
# The depfile may not exist if the input file didn't have any #includes. | ||
touch $(depfile).raw | ||
# Fixup path as in (1). | ||
sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile) | ||
# Add extra rules as in (2). | ||
# We remove slashes and replace spaces with new lines; | ||
# remove blank lines; | ||
# delete the first line and append a colon to the remaining lines. | ||
sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\ | ||
grep -v '^$$' |\ | ||
sed -e 1d -e 's|$$|:|' \ | ||
>> $(depfile) | ||
rm $(depfile).raw | ||
endef | ||
# Command definitions: | ||
# - cmd_foo is the actual command to run; | ||
# - quiet_cmd_foo is the brief-output summary of the command. | ||
|
||
quiet_cmd_cc = CC($(TOOLSET)) $@ | ||
cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $< | ||
|
||
quiet_cmd_cxx = CXX($(TOOLSET)) $@ | ||
cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $< | ||
%(extra_commands)s | ||
quiet_cmd_touch = TOUCH $@ | ||
cmd_touch = touch $@ | ||
|
||
quiet_cmd_copy = COPY $@ | ||
# send stderr to /dev/null to ignore messages when linking directories. | ||
cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp %(copy_archive_args)s "$<" "$@") | ||
|
||
%(link_commands)s | ||
# Define an escape_quotes function to escape single quotes. | ||
# This allows us to handle quotes properly as long as we always use | ||
# use single quotes and escape_quotes. | ||
escape_quotes = $(subst ','\'',$(1)) | ||
# This comment is here just to include a ' to unconfuse syntax highlighting. | ||
# Define an escape_vars function to escape '$' variable syntax. | ||
# This allows us to read/write command lines with shell variables (e.g. | ||
# $LD_LIBRARY_PATH), without triggering make substitution. | ||
escape_vars = $(subst $$,$$$$,$(1)) | ||
# Helper that expands to a shell command to echo a string exactly as it is in | ||
# make. This uses printf instead of echo because printf's behaviour with respect | ||
# to escape sequences is more portable than echo's across different shells | ||
# (e.g., dash, bash). | ||
exact_echo = printf '%%s\n' '$(call escape_quotes,$(1))' | ||
# Helper to compare the command we're about to run against the command | ||
# we logged the last time we ran the command. Produces an empty | ||
# string (false) when the commands match. | ||
# Tricky point: Make has no string-equality test function. | ||
# The kernel uses the following, but it seems like it would have false | ||
# positives, where one string reordered its arguments. | ||
# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ | ||
# $(filter-out $(cmd_$@), $(cmd_$(1)))) | ||
# We instead substitute each for the empty string into the other, and | ||
# say they're equal if both substitutions produce the empty string. | ||
# .d files contain {SPACE_REPLACEMENT} instead of spaces, take that into account. | ||
command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))), $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1)))) | ||
|
||
# Helper that is non-empty when a prerequisite changes. | ||
# Normally make does this implicitly, but we force rules to always run | ||
# so we can check their command lines. | ||
# $? -- new prerequisites | ||
# $| -- order-only dependencies | ||
prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?)) | ||
|
||
# Helper that executes all postbuilds until one fails. | ||
define do_postbuilds | ||
@E=0;\ | ||
for p in $(POSTBUILDS); do\ | ||
eval $$p;\ | ||
E=$$?;\ | ||
if [ $$E -ne 0 ]; then\ | ||
break;\ | ||
fi;\ | ||
done;\ | ||
if [ $$E -ne 0 ]; then\ | ||
rm -rf "$@";\ | ||
exit $$E;\ | ||
fi | ||
endef | ||
|
||
# do_cmd: run a command via the above cmd_foo names, if necessary. | ||
# Should always run for a given target to handle command-line changes. | ||
# Second argument, if non-zero, makes it do asm/C/C++ dependency munging. | ||
# Third argument, if non-zero, makes it do POSTBUILDS processing. | ||
# Note: We intentionally do NOT call dirx for depfile, since it contains {SPACE_REPLACEMENT} for | ||
# spaces already and dirx strips the {SPACE_REPLACEMENT} characters. | ||
define do_cmd | ||
$(if $(or $(command_changed),$(prereq_changed)), | ||
@$(call exact_echo, $($(quiet)cmd_$(1))) | ||
@mkdir -p "$(call dirx,$@)" "$(dir $(depfile))" | ||
$(if $(findstring flock,$(word %(flock_index)d,$(cmd_$1))), | ||
@$(cmd_$(1)) | ||
@echo " $(quiet_cmd_$(1)): Finished", | ||
@$(cmd_$(1)) | ||
) | ||
@$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile) | ||
@$(if $(2),$(fixup_dep)) | ||
$(if $(and $(3), $(POSTBUILDS)), | ||
$(call do_postbuilds) | ||
) | ||
) | ||
endef | ||
|
||
# Declare the "%(default_target)s" target first so it is the default, | ||
# even though we don't have the deps yet. | ||
.PHONY: %(default_target)s | ||
%(default_target)s: | ||
|
||
# make looks for ways to re-generate included makefiles, but in our case, we | ||
# don't have a direct way. Explicitly telling make that it has nothing to do | ||
# for them makes it go faster. | ||
%%.d: ; | ||
|
||
# Use FORCE_DO_CMD to force a target to run. Should be coupled with | ||
# do_cmd. | ||
.PHONY: FORCE_DO_CMD | ||
FORCE_DO_CMD: | ||
|
Oops, something went wrong.