1# SPDX-License-Identifier: GPL-2.0-or-later 2# Copyright (c) Linux Test Project, 2009-2024 3# Copyright (c) Cisco Systems Inc., 2009-2010 4# Ngie Cooper, July 2009 5 6# Avoid funny character set dependencies 7unexport LC_ALL 8LC_COLLATE=C 9LC_NUMERIC=C 10export LC_COLLATE LC_NUMERIC 11 12top_srcdir ?= $(CURDIR) 13 14include $(top_srcdir)/include/mk/env_pre.mk 15include $(top_srcdir)/include/mk/automake.mk 16 17.SUFFIXES: 18.SUFFIXES: .am .default .h .in .m4 .mk 19 20vpath %.am $(top_srcdir)/m4 21vpath %.default $(top_srcdir)/include 22vpath %.h $(top_srcdir)/include:$(top_builddir)/include 23vpath %.in $(top_srcdir)/include 24vpath %.m4 $(top_srcdir)/m4 25vpath %.mk $(top_srcdir)/mk:$(top_srcdir)/mk/include 26 27# CLEAN_TARGETS: Targets which exist solely in clean. 28# COMMON_TARGETS: Targets which exist in all, clean, and install. 29# INSTALL_TARGETS: Targets which exist in clean and install (contains 30# COMMON_TARGETS). 31# BOOTSTRAP_TARGETS: Directories required to bootstrap out-of-build-tree 32# support. 33 34COMMON_TARGETS := pan utils 35 36define target_to_dir_dep_mapping 37ifeq ($$(filter %-clean,$(1)),) # not *-clean 38$(1): | $$(abs_top_builddir)/$$(basename $$(subst -,.,$(1))) 39else # clean 40$(1):: | $$(abs_top_builddir)/$$(basename $$(subst -,.,$(1))) 41endif 42endef 43 44COMMON_TARGETS += testcases tools metadata 45 46# Don't want to nuke the original files if we're installing in-build-tree. 47ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL)) 48INSTALL_TARGETS += runtest scenario_groups testscripts 49CLEAN_TARGETS += include runtest scenario_groups testscripts 50endif 51INSTALL_TARGETS += $(COMMON_TARGETS) 52CLEAN_TARGETS += $(COMMON_TARGETS) lib libs 53BOOTSTRAP_TARGETS := $(sort $(COMMON_TARGETS) $(CLEAN_TARGETS) $(INSTALL_TARGETS)) 54 55CLEAN_TARGETS := $(addsuffix -clean,$(CLEAN_TARGETS)) 56INSTALL_TARGETS := $(addsuffix -install,$(INSTALL_TARGETS)) 57MAKE_TARGETS := $(addsuffix -all,$(filter-out lib,$(COMMON_TARGETS))) 58CHECK_TARGETS := $(addsuffix -check,testcases lib) 59 60# There's no reason why we should run `all' twice. Otherwise we're just wasting 61# 3+ mins of useful CPU cycles on a modern machine, and even more time on an 62# overtaxed one, or one where -j => 1 was specified. 63all: $(addsuffix -all,$(COMMON_TARGETS)) Version 64 65$(MAKE_TARGETS): lib-all libs-all 66 67.PHONY: include-all include-install 68include-install: $(top_builddir)/include/config.h include/mk/config.mk include-all 69 70INSTALL_DIR := $(DESTDIR)/$(prefix) 71 72# DO NOT REMOVE THIS CALL (see clean_install_dir call below...)!!!! 73INSTALL_DIR := $(abspath $(INSTALL_DIR)) 74 75# build tree bootstrap targets and $(INSTALL_DIR) target. 76$(sort $(addprefix $(abs_top_builddir)/,$(BOOTSTRAP_TARGETS)) $(INSTALL_DIR) $(DESTDIR)/$(bindir)): 77 mkdir -m 00755 -p "$@" 78 79## Pattern based subtarget rules. 80lib-install: lib-all 81 82libs-all: $(abs_top_builddir)/libs 83 84$(MAKE_TARGETS) include-all lib-all libs-all: 85 $(MAKE) -C "$(subst -all,,$@)" \ 86 -f "$(abs_top_srcdir)/$(subst -all,,$@)/Makefile" all 87 88$(CHECK_TARGETS): tools-all 89 $(MAKE) -C "$(subst -check,,$@)" \ 90 -f "$(abs_top_srcdir)/$(subst -check,,$@)/Makefile" check 91 92# Let's not conflict with ac-clean, maintainer-clean, etc, so. 93$(filter-out include-clean,$(CLEAN_TARGETS)):: 94 -$(MAKE) -C "$(subst -clean,,$@)" \ 95 -f "$(abs_top_srcdir)/$(subst -clean,,$@)/Makefile" clean 96 97# Just like everything depends on include-all / -install, we need to get rid 98# of include last to ensure that things won't be monkey screwed up. Only do 99# this if we're invoking clean or a subclean directly though. 100ifneq ($(filter clean,$(MAKECMDGOALS)),) 101INCLUDE_CLEAN_RDEP_SUBJECT := $(CLEAN_TARGETS) 102else 103ifneq ($(filter %clean,$(MAKECMDGOALS)),) 104INCLUDE_CLEAN_RDEP_SUBJECT := $(MAKECMDGOALS) 105endif 106endif 107 108# Remove potential for circular dependencies. 109INCLUDE_CLEAN_RDEPS := $(filter-out include-clean,$(INCLUDE_CLEAN_RDEP_SUBJECT)) 110 111include-clean:: $(INCLUDE_CLEAN_RDEPS) | $(abs_top_builddir)/include 112 -$(MAKE) -C include -f "$(abs_top_srcdir)/include/Makefile" clean 113 114# include-install is separate to avoid creating a circular dependency below in 115# the install target. 116$(INSTALL_TARGETS) include-install lib-install: 117 $(MAKE) -C "$(subst -install,,$@)" \ 118 -f "$(abs_top_srcdir)/$(subst -install,,$@)/Makefile" install 119 120# Just in case configure hasn't been run yet, let's not overambitiously remove 121# the $(INSTALL_DIR). 122.PHONY: clean_install_dir 123clean_install_dir:: 124 $(RM) -Rf "$(INSTALL_DIR)" 125 126# Clean the directory if the build-tree is properly configured and not set to 127# the srcdir. 128ifeq ($(filter $(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL) $(BUILD_TREE_UNCONFIGURED)),) 129# Make sure that we don't whack `/'!!!!! 130ifneq ($(INSTALL_DIR),/) 131CLEAN_TARGETS += clean_install_dir 132endif 133endif 134 135clean:: $(CLEAN_TARGETS) 136 $(RM) -f Version 137 138$(foreach tgt,$(MAKE_TARGETS) include-all lib-all $(filter-out clean_install_dir,$(CLEAN_TARGETS)) $(INSTALL_TARGETS) include-install lib-install,$(eval $(call target_to_dir_dep_mapping,$(tgt)))) 139 140SRCDIR_INSTALL_SCRIPTS := IDcheck.sh runltp ver_linux 141SRCDIR_INSTALL_READONLY := Version 142SRCDIR_INSTALL_TARGETS := $(SRCDIR_INSTALL_SCRIPTS) $(SRCDIR_INSTALL_READONLY) 143 144# 145# If we are in git repository, use git describe to indentify current version, 146# otherwise if downloaded as tarball use VERSION file. 147# 148.PHONY: Version 149Version: 150 if git describe >/dev/null 2>&1; then \ 151 git describe > "$@"; \ 152 else \ 153 cp $(top_srcdir)/VERSION "$@"; \ 154 fi 155 156$(INSTALL_DIR)/Version: Version 157 install -m 00644 "$(top_builddir)/$(@F)" "$@" 158 159$(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS)): %: 160 install -m 00755 "$(top_builddir)/$(@F)" "$@" 161 162$(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_SCRIPTS)): %: 163 install -m 00755 "$(top_srcdir)/$(@F)" "$@" 164 165ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL)) 166INSTALL_TARGETS += $(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_TARGETS)) 167endif 168INSTALL_TARGETS += $(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS)) 169 170$(INSTALL_TARGETS): $(INSTALL_DIR) $(DESTDIR)/$(bindir) 171 172.PHONY: doc 173doc: metadata-all 174 175.PHONY: check 176check: $(CHECK_TARGETS) 177 178## Install 179install: $(INSTALL_TARGETS) 180 181## Test 182define _test 183 @set -e; $(top_srcdir)/lib/newlib_tests/runtest.sh -b $(abs_builddir) $(1) 184endef 185 186test: lib-all 187ifneq ($(build),$(host)) 188 $(error running tests on cross-compile build not supported) 189endif 190 $(call _test) 191 $(MAKE) test-metadata 192 193test-c: lib-all 194ifneq ($(build),$(host)) 195 $(error running tests on cross-compile build not supported) 196endif 197 $(call _test,-c) 198 199test-shell: lib-all 200ifneq ($(build),$(host)) 201 $(error running tests on cross-compile build not supported) 202endif 203 $(call _test,-s) 204 205test-metadata: metadata-all 206 $(MAKE) -C $(abs_srcdir)/metadata test 207 208## Help 209.PHONY: help 210help: 211 @echo "Please read the Configuration section in $(top_srcdir)/INSTALL" 212 @exit 1 213 214## Menuconfig 215menuconfig: 216 @$(SHELL) "$(top_srcdir)/ltpmenu" 217 218## End misc targets. 219