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