1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
# Define autoconf style directory variables, for Libreswan.
#
# Copyright (C) 2015, 2021 Andrew Cagney
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
# From a source directory Makefile use:
#
# ifndef top_srcdir
# include ../../mk/dirs.mk
# endif
#
# (Since the Makefile is included from the build (OBJDIR) directory
# where the relative paths are different and dirs.mk has already been
# included, a guard is needed.)
#
# From a generated build (OBJDIR) directory Makefile use:
#
# include ../../../mk/dirs.mk
#
# To help testing there is the target ".dirs.mk". This will print out
# all defined variables. For instance:
#
# ( cd . && make -f mk/dirs.mk .dirs.mk )
# ( cd programs && make -f ../mk/dirs.mk .dirs.mk )
# ( cd programs/pluto && make -f ../../mk/dirs.mk .dirs.mk )
#
# ( cd OBJ.* && make -f ../mk/dirs.mk .dirs.mk )
# ( cd OBJ.*/programs && make -f ../../mk/dirs.mk .dirs.mk )
# ( cd OBJ.*/programs/pluto && make -f ../../../mk/dirs.mk .dirs.mk )
#
# Check for double include of mk/dirs.mk. This, as they say, will
# never happen.
#
# Unfortunately, given the presence of this test, you can guess that
# it has. Some broken Makefile code was effectively executing:
#
# cd $(abs_top_builddir) && OBJDIR=$(abs_top_builddir) make ...
#
# (i.e., a totally bogus OBJDIR was being pushed into the child make's
# environment). Either by luck, or poor design, the generated OBJDIR
# Makefiles would then "fix" OBJDIR forcing it to a correct value.
# Remove the "fix" and chaos ensues.
ifeq ($(.dirs.mk),)
.dirs.mk := $(MAKEFILE_LIST)
else
$(warning mk/dirs.mk included twice)
$(warning first include MAKEFILE_LIST: $(.dirs.mk))
$(warning second include MAKEFILE_LIST: $(MAKEFILE_LIST))
$(warning dirs.mk.in.srcdir: $(dirs.mk.in.srcdir))
$(warning srcdir: $(srcdir))
$(warning builddir: $(builddir))
$(warning OBJDIR: $(OBJDIR))
$(warning cwd: $(abspath .))
$(error this will never happen ...)
endif
#
# Determine top_srcdir
#
# The last item in the GNU make variable MAKEFILE_LIST is the relative
# path to the most recent included file (i.e., this file - dirs.mk).
# Since the location of dirs.mk is known relative to top_srcdir,
# top_srcdir can be determined. These variables are "simply expanded"
# so that they capture the current value. For more information see
# MAKEFILE_LIST and "simply expanded variables" in "info make".
# Extract the relative path to this file
dirs.mk.file := $(lastword $(MAKEFILE_LIST))
# Convert the relative path to this file into a relative path to this
# file's directory. Since $(dir) appends a trailing / (such as "mk/"
# or "../mk/") that needs to be stripped.
dirs.mk.dir := $(patsubst %/,%,$(dir $(dirs.mk.file)))
# Finally, drop the mk/ sub-directory. Again, since $(dir) appends a
# trailing / (such as "./" or "../") that needs to be stripped.
top_srcdir := $(patsubst %/,%,$(dir $(dirs.mk.dir)))
abs_top_srcdir := $(abspath $(top_srcdir))
# Pull in sufficient stuff to get a definition of OBJDIR. It might be
# set by local includes so pull that in first.
include $(top_srcdir)/mk/local.mk
include $(top_srcdir)/mk/objdir.mk
srcdir := .
abs_srcdir := $(abspath $(srcdir))
ifeq ($(patsubst /%,/,$(OBJDIR)),/)
# absolute
top_builddir := $(OBJDIR)
else ifeq ($(top_srcdir),.)
# avoid ./OBJDIR
top_builddir := $(OBJDIR)
else
top_builddir := $(top_srcdir)/$(OBJDIR)
endif
abs_top_builddir := $(abspath $(top_builddir))
# Path down from $(top_srcdir); Note that for non-top-level
# directories PATH_SRCDIR contains a leading / so that ${builddir} is
# built correctly.
path_srcdir := $(subst $(abs_top_srcdir),,$(abs_srcdir))
builddir := $(top_builddir)$(path_srcdir)
abs_builddir := $(abspath $(builddir))
# Always include the other directory in the search path.
#
# XXX: The VPATH+=$(srcdir) will hopefully go away and this will
# become unconditional.
ifeq ($(srcdir),.)
VPATH += $(builddir)
endif
ifeq ($(builddir),.)
VPATH += $(srcdir)
endif
# For compatibility with existing include files:
LIBRESWANSRCDIR?=$(abs_top_srcdir)
SRCDIR?=$(abs_srcdir)/
OBJDIRTOP?=$(abs_top_builddir)
# Dot targets are never the default.
.PHONY: .dirs.mk
.dirs.mk:
@echo ""
@echo For debugging:
@echo ""
@echo dirs.mk.file=$(dirs.mk.file)
@echo dirs.mk.dir=$(dirs.mk.dir)
@echo path_srcdir=$(path_srcdir)
@echo top_srcdir=$(top_srcdir)
@echo dirs.mk.included.from.srcdir="$(dirs.mk.included.from.srcdir)"
@echo ""
@echo Relative paths:
@echo ""
@echo srcdir=$(srcdir)
@echo top_srcdir=$(top_srcdir)
@echo builddir=$(builddir)
@echo top_builddir=$(top_builddir)
@echo ""
@echo Absolute paths:
@echo ""
@echo abs_srcdir=$(abs_srcdir)
@echo abs_top_srcdir=$(abs_top_srcdir)
@echo abs_builddir=$(abs_builddir)
@echo abs_top_builddir=$(abs_top_builddir)
@echo ""
@echo Backward compatibility:
@echo ""
@echo SRCDIR=$(SRCDIR)
@echo OBJDIRTOP=$(OBJDIRTOP)
@echo LIBRESWANSRCDIR=$(LIBRESWANSRCDIR)
|