1# Makefile for OpenWrt
2#
3# Copyright (C) 2007 OpenWrt.org
4#
5# This is free software, licensed under the GNU General Public License v2.
6# See /LICENSE for more information.
7#
8
9TOPDIR:=${CURDIR}
10LC_ALL:=C
11LANG:=C
12TZ:=UTC
13export TOPDIR LC_ALL LANG TZ
14
15empty:=
16space:= $(empty) $(empty)
17$(if $(findstring $(space),$(TOPDIR)),$(error ERROR: The path to the OpenWrt directory must not include any spaces))
18
19world:
20
21include $(TOPDIR)/include/host.mk
22
23ifneq ($(OPENWRT_BUILD),1)
24  _SINGLE=export MAKEFLAGS=$(space);
25
26  override OPENWRT_BUILD=1
27  export OPENWRT_BUILD
28  GREP_OPTIONS=
29  export GREP_OPTIONS
30  include $(TOPDIR)/include/debug.mk
31  include $(TOPDIR)/include/depends.mk
32  include $(TOPDIR)/include/toplevel.mk
33else
34  include rules.mk
35  include $(INCLUDE_DIR)/depends.mk
36  include $(INCLUDE_DIR)/subdir.mk
37  include target/Makefile
38  include package/Makefile
39  include tools/Makefile
40  include toolchain/Makefile
41
42$(toolchain/stamp-install): $(tools/stamp-install)
43$(target/stamp-compile): $(toolchain/stamp-install) $(tools/stamp-install) $(BUILD_DIR)/.prepared
44$(package/stamp-compile): $(target/stamp-compile) $(package/stamp-cleanup)
45$(package/stamp-install): $(package/stamp-compile)
46$(target/stamp-install): $(package/stamp-compile) $(package/stamp-install)
47
48printdb:
49	@true
50
51prepare: $(target/stamp-compile)
52
53clean: FORCE
54	rm -rf $(BUILD_DIR) $(STAGING_DIR) $(BIN_DIR) $(BUILD_LOG_DIR)
55
56dirclean: clean
57	rm -rf $(STAGING_DIR_HOST) $(TOOLCHAIN_DIR) $(BUILD_DIR_HOST) $(BUILD_DIR_TOOLCHAIN)
58	rm -rf $(TMP_DIR)
59
60ifndef DUMP_TARGET_DB
61$(BUILD_DIR)/.prepared: Makefile
62	@mkdir -p $$(dirname $@)
63	@touch $@
64
65tmp/.prereq_packages: .config
66	unset ERROR; \
67	for package in $(sort $(prereq-y) $(prereq-m)); do \
68		$(_SINGLE)$(NO_TRACE_MAKE) -s -r -C package/$$package prereq || ERROR=1; \
69	done; \
70	if [ -n "$$ERROR" ]; then \
71		echo "Package prerequisite check failed."; \
72		false; \
73	fi
74	touch $@
75endif
76
77# check prerequisites before starting to build
78prereq: $(target/stamp-prereq) tmp/.prereq_packages
79	@if [ ! -f "$(INCLUDE_DIR)/site/$(ARCH)" ]; then \
80		echo 'ERROR: Missing site config for architecture "$(ARCH)" !'; \
81		echo '       The missing file will cause configure scripts to fail during compilation.'; \
82		echo '       Please provide a "$(INCLUDE_DIR)/site/$(ARCH)" file and restart the build.'; \
83		exit 1; \
84	fi
85
86prepare: .config $(tools/stamp-install) $(toolchain/stamp-install)
87world: prepare $(target/stamp-compile) $(package/stamp-compile) $(package/stamp-install) $(target/stamp-install) FORCE
88	$(_SINGLE)$(SUBMAKE) -r package/index
89
90.PHONY: clean dirclean prereq prepare world package/symlinks package/symlinks-install package/symlinks-clean
91
92endif
93