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