• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#    Top-level Makefile for LTP. See INSTALL for more info.
3#
4#    Copyright (C) 2009-2010, Cisco Systems Inc.
5#    Copyright (C) 2010-2011, Linux Test Project.
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
66# Don't want to nuke the original files if we're installing in-build-tree.
67ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL))
68INSTALL_TARGETS		+= runtest scenario_groups testscripts
69CLEAN_TARGETS		+= include runtest scenario_groups testscripts
70endif
71INSTALL_TARGETS		+= $(COMMON_TARGETS)
72CLEAN_TARGETS		+= $(COMMON_TARGETS) lib libs
73BOOTSTRAP_TARGETS	:= $(sort $(COMMON_TARGETS) $(CLEAN_TARGETS) $(INSTALL_TARGETS))
74
75CLEAN_TARGETS		:= $(addsuffix -clean,$(CLEAN_TARGETS))
76INSTALL_TARGETS		:= $(addsuffix -install,$(INSTALL_TARGETS))
77MAKE_TARGETS		:= $(addsuffix -all,$(filter-out lib,$(COMMON_TARGETS)))
78
79# There's no reason why we should run `all' twice. Otherwise we're just wasting
80# 3+ mins of useful CPU cycles on a modern machine, and even more time on an
81# overtaxed one, or one where -j => 1 was specified.
82all: $(addsuffix -all,$(COMMON_TARGETS)) Version
83
84$(MAKE_TARGETS): lib-all libs-all
85
86.PHONY: include-all include-install
87include-install: $(top_builddir)/include/config.h include/mk/config.mk include-all
88
89INSTALL_DIR		:= $(DESTDIR)/$(prefix)
90
91# DO NOT REMOVE THIS CALL (see clean_install_dir call below...)!!!!
92ifdef MAKE_3_80_COMPAT
93INSTALL_DIR		:= $(call MAKE_3_80_abspath,$(INSTALL_DIR))
94else
95INSTALL_DIR		:= $(abspath $(INSTALL_DIR))
96endif
97
98# build tree bootstrap targets and $(INSTALL_DIR) target.
99$(sort $(addprefix $(abs_top_builddir)/,$(BOOTSTRAP_TARGETS)) $(INSTALL_DIR) $(DESTDIR)/$(bindir)):
100	mkdir -m 00755 -p "$@"
101
102## Pattern based subtarget rules.
103lib-install: lib-all
104
105libs-all: $(abs_top_builddir)/libs
106
107$(MAKE_TARGETS) include-all lib-all libs-all:
108	$(MAKE) -C "$(subst -all,,$@)" \
109		-f "$(abs_top_srcdir)/$(subst -all,,$@)/Makefile" all
110
111# Let's not conflict with ac-clean, maintainer-clean, etc, so.
112$(filter-out include-clean,$(CLEAN_TARGETS))::
113	-$(MAKE) -C "$(subst -clean,,$@)" \
114		 -f "$(abs_top_srcdir)/$(subst -clean,,$@)/Makefile" clean
115
116# Just like everything depends on include-all / -install, we need to get rid
117# of include last to ensure that things won't be monkey screwed up. Only do
118# this if we're invoking clean or a subclean directly though.
119ifneq ($(filter clean,$(MAKECMDGOALS)),)
120INCLUDE_CLEAN_RDEP_SUBJECT	:= $(CLEAN_TARGETS)
121else
122ifneq ($(filter %clean,$(MAKECMDGOALS)),)
123INCLUDE_CLEAN_RDEP_SUBJECT	:= $(MAKECMDGOALS)
124endif
125endif
126
127# Remove potential for circular dependencies.
128INCLUDE_CLEAN_RDEPS		:= $(filter-out include-clean,$(INCLUDE_CLEAN_RDEP_SUBJECT))
129
130include-clean:: $(INCLUDE_CLEAN_RDEPS) | $(abs_top_builddir)/include
131	-$(MAKE) -C include -f "$(abs_top_srcdir)/include/Makefile" clean
132
133# include-install is separate to avoid creating a circular dependency below in
134# the install target.
135$(INSTALL_TARGETS) include-install lib-install:
136	$(MAKE) -C "$(subst -install,,$@)" \
137		-f "$(abs_top_srcdir)/$(subst -install,,$@)/Makefile" install
138
139# Just in case configure hasn't been run yet, let's not overambitiously remove
140# the $(INSTALL_DIR).
141.PHONY: clean_install_dir
142clean_install_dir::
143	$(RM) -Rf "$(INSTALL_DIR)"
144
145# Clean the directory if the build-tree is properly configured and not set to
146# the srcdir.
147ifeq ($(filter $(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL) $(BUILD_TREE_UNCONFIGURED)),)
148# Make sure that we don't whack `/'!!!!!
149ifneq ($(INSTALL_DIR),/)
150CLEAN_TARGETS	+= clean_install_dir
151endif
152endif
153
154clean:: $(CLEAN_TARGETS)
155	$(RM) -f Version
156
157$(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))))
158
159BINDIR_INSTALL_SCRIPTS	:= execltp
160SRCDIR_INSTALL_SCRIPTS	:= IDcheck.sh runltp ver_linux
161SRCDIR_INSTALL_READONLY	:= Version
162SRCDIR_INSTALL_TARGETS	:= $(SRCDIR_INSTALL_SCRIPTS) $(SRCDIR_INSTALL_READONLY)
163
164#
165# If we are in git repository, use git describe to indentify current version,
166# otherwise if downloaded as tarball use VERSION file.
167#
168.PHONY: Version
169Version:
170	if git describe >/dev/null 2>&1; then \
171		git describe > "$@"; \
172	else \
173		cp $(top_srcdir)/VERSION "$@"; \
174	fi
175
176$(INSTALL_DIR)/Version: Version
177	install -m 00644 "$(top_builddir)/$(@F)" "$@"
178
179$(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS)): %:
180	install -m 00755 "$(top_builddir)/$(@F)" "$@"
181
182$(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_SCRIPTS)): %:
183	install -m 00755 "$(top_srcdir)/$(@F)" "$@"
184
185ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL))
186INSTALL_TARGETS		+= $(addprefix $(INSTALL_DIR)/,$(SRCDIR_INSTALL_TARGETS))
187endif
188INSTALL_TARGETS		+= $(addprefix $(DESTDIR)/$(bindir)/,$(BINDIR_INSTALL_SCRIPTS))
189
190$(INSTALL_TARGETS): $(INSTALL_DIR) $(DESTDIR)/$(bindir)
191
192## Install
193install: $(INSTALL_TARGETS)
194
195## Help
196.PHONY: help
197help:
198	@echo "Please read the Configuration section in $(top_srcdir)/INSTALL"
199	@exit 1
200
201## Menuconfig
202menuconfig:
203	@$(SHELL) "$(top_srcdir)/ltpmenu"
204
205## End misc targets.
206