1*49cdfc7eSAndroid Build Coastguard Worker# 2*49cdfc7eSAndroid Build Coastguard Worker# Make pre-include environment Makefile. 3*49cdfc7eSAndroid Build Coastguard Worker# 4*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) Linux Test Project, 2009-2020 5*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) Cisco Systems Inc., 2009 6*49cdfc7eSAndroid Build Coastguard Worker# 7*49cdfc7eSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or modify 8*49cdfc7eSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by 9*49cdfc7eSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2 of the License, or 10*49cdfc7eSAndroid Build Coastguard Worker# (at your option) any later version. 11*49cdfc7eSAndroid Build Coastguard Worker# 12*49cdfc7eSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful, 13*49cdfc7eSAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*49cdfc7eSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*49cdfc7eSAndroid Build Coastguard Worker# GNU General Public License for more details. 16*49cdfc7eSAndroid Build Coastguard Worker# 17*49cdfc7eSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License along 18*49cdfc7eSAndroid Build Coastguard Worker# with this program; if not, write to the Free Software Foundation, Inc., 19*49cdfc7eSAndroid Build Coastguard Worker# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20*49cdfc7eSAndroid Build Coastguard Worker# 21*49cdfc7eSAndroid Build Coastguard Worker# Ngie Cooper, September 2009 22*49cdfc7eSAndroid Build Coastguard Worker# 23*49cdfc7eSAndroid Build Coastguard Worker# This Makefile must be included first. NO IF'S, AND'S, OR BUT'S. 24*49cdfc7eSAndroid Build Coastguard Worker# 25*49cdfc7eSAndroid Build Coastguard Worker# This sets the stage for all operations required within Makefiles. 26*49cdfc7eSAndroid Build Coastguard Worker# 27*49cdfc7eSAndroid Build Coastguard Worker 28*49cdfc7eSAndroid Build Coastguard Workerifndef ENV_PRE_LOADED 29*49cdfc7eSAndroid Build Coastguard WorkerENV_PRE_LOADED = 1 30*49cdfc7eSAndroid Build Coastguard Worker 31*49cdfc7eSAndroid Build Coastguard Worker# "out-of-build-tree" build. 32*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_BUILDDIR_INSTALL := 1 33*49cdfc7eSAndroid Build Coastguard Worker# "in-srcdir" build / install. 34*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_SRCDIR_INSTALL := 2 35*49cdfc7eSAndroid Build Coastguard Worker# "in-srcdir" build, non-srcdir install. 36*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_NONSRCDIR_INSTALL := 3 37*49cdfc7eSAndroid Build Coastguard Worker# configure not run. 38*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_UNCONFIGURED := 4 39*49cdfc7eSAndroid Build Coastguard Worker 40*49cdfc7eSAndroid Build Coastguard Worker# Get the absolute path for the source directory. 41*49cdfc7eSAndroid Build Coastguard Workertop_srcdir ?= $(error You must define top_srcdir before including this file) 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Workerinclude $(top_srcdir)/include/mk/functions.mk 44*49cdfc7eSAndroid Build Coastguard Worker 45*49cdfc7eSAndroid Build Coastguard Worker# Where's the root source directory? 46*49cdfc7eSAndroid Build Coastguard Workerabs_top_srcdir := $(abspath $(top_srcdir)) 47*49cdfc7eSAndroid Build Coastguard Worker 48*49cdfc7eSAndroid Build Coastguard Worker# 49*49cdfc7eSAndroid Build Coastguard Worker# Where's the root object directory? 50*49cdfc7eSAndroid Build Coastguard Worker# 51*49cdfc7eSAndroid Build Coastguard Worker# Just in case it's not specified, set it to the top srcdir (because the user 52*49cdfc7eSAndroid Build Coastguard Worker# must not have wanted out of build tree support)... 53*49cdfc7eSAndroid Build Coastguard Worker# 54*49cdfc7eSAndroid Build Coastguard Workertop_builddir ?= $(top_srcdir) 55*49cdfc7eSAndroid Build Coastguard Worker 56*49cdfc7eSAndroid Build Coastguard Worker# We need the absolute path 57*49cdfc7eSAndroid Build Coastguard Workerabs_top_builddir := $(abspath $(top_builddir)) 58*49cdfc7eSAndroid Build Coastguard Worker 59*49cdfc7eSAndroid Build Coastguard Worker# Where's the root object directory? 60*49cdfc7eSAndroid Build Coastguard Workerbuilddir := . 61*49cdfc7eSAndroid Build Coastguard Worker 62*49cdfc7eSAndroid Build Coastguard Workerabs_builddir := $(CURDIR) 63*49cdfc7eSAndroid Build Coastguard Worker 64*49cdfc7eSAndroid Build Coastguard Workercwd_rel1 := $(subst $(abs_top_builddir),,$(abs_builddir)) 65*49cdfc7eSAndroid Build Coastguard Workercwd_rel2 := $(subst $(abs_top_builddir)/,,$(abs_builddir)) 66*49cdfc7eSAndroid Build Coastguard Workercwd_rel_from_top := $(if $(cwd_rel1),$(cwd_rel2),$(cwd_rel1)) 67*49cdfc7eSAndroid Build Coastguard Worker 68*49cdfc7eSAndroid Build Coastguard Worker# Where's the source located at? Squish all of the / away by using abspath 69*49cdfc7eSAndroid Build Coastguard Workerabs_srcdir := $(abspath $(abs_top_srcdir)/$(cwd_rel_from_top)) 70*49cdfc7eSAndroid Build Coastguard Worker 71*49cdfc7eSAndroid Build Coastguard Workersrcdir := $(strip $(subst $(abs_top_srcdir)/,,$(abs_srcdir))) 72*49cdfc7eSAndroid Build Coastguard Worker 73*49cdfc7eSAndroid Build Coastguard Workerifeq ($(srcdir),) 74*49cdfc7eSAndroid Build Coastguard Workersrcdir := . 75*49cdfc7eSAndroid Build Coastguard Workerendif 76*49cdfc7eSAndroid Build Coastguard Worker 77*49cdfc7eSAndroid Build Coastguard Worker# If config.mk or features.mk doesn't exist it's not an error for some targets 78*49cdfc7eSAndroid Build Coastguard Worker# which are filtered below (e.g. clean). However these config files may be 79*49cdfc7eSAndroid Build Coastguard Worker# needed for those targets (eg. the open posix testsuite is not cleaned even if 80*49cdfc7eSAndroid Build Coastguard Worker# it's enabled by configure) thus it would be wise to do silent inclusion. 81*49cdfc7eSAndroid Build Coastguard Workerifneq ("$(wildcard $(abs_top_builddir)/include/mk/config.mk)","") 82*49cdfc7eSAndroid Build Coastguard Workerinclude $(abs_top_builddir)/include/mk/config.mk 83*49cdfc7eSAndroid Build Coastguard Workerendif 84*49cdfc7eSAndroid Build Coastguard Workerifneq ("$(wildcard $(abs_top_builddir)/include/mk/features.mk)","") 85*49cdfc7eSAndroid Build Coastguard Workerinclude $(abs_top_builddir)/include/mk/features.mk 86*49cdfc7eSAndroid Build Coastguard Workerendif 87*49cdfc7eSAndroid Build Coastguard Worker 88*49cdfc7eSAndroid Build Coastguard Worker# autotools, *clean, and help don't require config.mk, features.mk, etc... 89*49cdfc7eSAndroid Build Coastguard Workerifeq ($(filter autotools %clean .gitignore gitignore.% help,$(MAKECMDGOALS)),) 90*49cdfc7eSAndroid Build Coastguard Worker 91*49cdfc7eSAndroid Build Coastguard Workerinclude $(abs_top_builddir)/include/mk/config.mk 92*49cdfc7eSAndroid Build Coastguard Workerinclude $(abs_top_builddir)/include/mk/features.mk 93*49cdfc7eSAndroid Build Coastguard Worker 94*49cdfc7eSAndroid Build Coastguard Worker# START out-of-build-tree check. 95*49cdfc7eSAndroid Build Coastguard Workerifneq ($(abs_builddir),$(abs_srcdir)) 96*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_STATE := $(BUILD_TREE_BUILDDIR_INSTALL) 97*49cdfc7eSAndroid Build Coastguard Workerelse 98*49cdfc7eSAndroid Build Coastguard Worker# Else, not out of build tree.. 99*49cdfc7eSAndroid Build Coastguard Worker 100*49cdfc7eSAndroid Build Coastguard Worker# START srcdir build-tree install checks 101*49cdfc7eSAndroid Build Coastguard Workerifeq ($(strip $(DESTDIR)$(prefix)),) 102*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_STATE := $(BUILD_TREE_SRCDIR_INSTALL) 103*49cdfc7eSAndroid Build Coastguard Workerelse # Empty $(DESTDIR)$(prefix) 104*49cdfc7eSAndroid Build Coastguard Workerifeq ($(abs_top_srcdir),$(prefix)) 105*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_STATE := $(BUILD_TREE_SRCDIR_INSTALL) 106*49cdfc7eSAndroid Build Coastguard Workerendif 107*49cdfc7eSAndroid Build Coastguard Worker# END srcdir build-tree install checks 108*49cdfc7eSAndroid Build Coastguard Workerendif 109*49cdfc7eSAndroid Build Coastguard Worker# END out-of-build-tree check. 110*49cdfc7eSAndroid Build Coastguard Workerendif 111*49cdfc7eSAndroid Build Coastguard Worker 112*49cdfc7eSAndroid Build Coastguard Worker# Is the build-tree configured yet? 113*49cdfc7eSAndroid Build Coastguard Workerifeq ($(BUILD_TREE_STATE),) 114*49cdfc7eSAndroid Build Coastguard Workerifneq ($(wildcard $(abs_top_builddir)/include/mk/config.mk),) 115*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_STATE := $(BUILD_TREE_NONSRCDIR_INSTALL) 116*49cdfc7eSAndroid Build Coastguard Workerendif 117*49cdfc7eSAndroid Build Coastguard Workerendif 118*49cdfc7eSAndroid Build Coastguard Worker 119*49cdfc7eSAndroid Build Coastguard Worker.DEFAULT_GOAL := all 120*49cdfc7eSAndroid Build Coastguard Worker 121*49cdfc7eSAndroid Build Coastguard Workerendif # END autotools, *clean... 122*49cdfc7eSAndroid Build Coastguard Worker 123*49cdfc7eSAndroid Build Coastguard WorkerBUILD_TREE_STATE ?= $(BUILD_TREE_UNCONFIGURED) 124*49cdfc7eSAndroid Build Coastguard Worker 125*49cdfc7eSAndroid Build Coastguard Worker# We can piece together where we're located in the source and object trees with 126*49cdfc7eSAndroid Build Coastguard Worker# just these two vars and $(CURDIR). 127*49cdfc7eSAndroid Build Coastguard Workerexport abs_top_srcdir abs_top_builddir BUILD_TREE_STATE 128*49cdfc7eSAndroid Build Coastguard Worker 129*49cdfc7eSAndroid Build Coastguard Workerifeq ($V,1) 130*49cdfc7eSAndroid Build Coastguard WorkerVERBOSE=1 131*49cdfc7eSAndroid Build Coastguard Workerendif 132*49cdfc7eSAndroid Build Coastguard Worker 133*49cdfc7eSAndroid Build Coastguard Workerendif 134