• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
149BINDIR_INSTALL_SCRIPTS	:= execltp
150SRCDIR_INSTALL_SCRIPTS	:= IDcheck.sh runltp ver_linux
151SRCDIR_INSTALL_READONLY	:= Version
152SRCDIR_INSTALL_TARGETS	:= $(SRCDIR_INSTALL_SCRIPTS) $(SRCDIR_INSTALL_READONLY)
153
154#
155# If we are in git repository, use git describe to indentify current version,
156# otherwise if downloaded as tarball use VERSION file.
157#
158.PHONY: Version
159Version:
160	if git describe >/dev/null 2>&1; then \
161		git describe > "$@"; \
162	else \
163		cp $(top_srcdir)/VERSION "$@"; \
164	fi
165
166$(INSTALL_DIR)/Version: Version
167	install -m 00644 "$(top_builddir)/$(@F)" "$@"
168
169$(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS)): %:
170	install -m 00755 "$(top_builddir)/$(@F)" "$@"
171
172$(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_SCRIPTS)): %:
173	install -m 00755 "$(top_srcdir)/$(@F)" "$@"
174
175ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL))
176INSTALL_TARGETS		+= $(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_TARGETS))
177endif
178INSTALL_TARGETS		+= $(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS))
179
180$(INSTALL_TARGETS): $(INSTALL_DIR) $(DESTDIR)/$(bindir)
181
182.PHONY: check
183check: $(CHECK_TARGETS)
184
185## Install
186install: $(INSTALL_TARGETS)
187
188## Test
189define _test
190	@set -e; $(top_srcdir)/lib/newlib_tests/runtest.sh -b $(abs_builddir) $(1)
191endef
192
193test: lib-all
194ifneq ($(build),$(host))
195	$(error running tests on cross-compile build not supported)
196endif
197	$(call _test)
198	$(MAKE) test-metadata
199
200test-c: lib-all
201ifneq ($(build),$(host))
202	$(error running tests on cross-compile build not supported)
203endif
204	$(call _test,-c)
205
206test-shell: lib-all
207ifneq ($(build),$(host))
208	$(error running tests on cross-compile build not supported)
209endif
210	$(call _test,-s)
211
212test-metadata: metadata-all
213	$(MAKE) -C $(abs_srcdir)/metadata/ test
214
215## Help
216.PHONY: help
217help:
218	@echo "Please read the Configuration section in $(top_srcdir)/INSTALL"
219	@exit 1
220
221## Menuconfig
222menuconfig:
223	@$(SHELL) "$(top_srcdir)/ltpmenu"
224
225## End misc targets.
226