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