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