blob: 936f323c9ef106535e071e1e6b1106148d254c68 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001# SPDX-License-Identifier: GPL-2.0-only
2#
3# Copyright (C) 2007 OpenWrt.org
4
5TOPDIR:=${CURDIR}
6MRVLDIR:=$(TOPDIR)/marvell
7LC_ALL:=C
8LANG:=C
9TZ:=UTC
10export TOPDIR MRVLDIR LC_ALL LANG TZ
11
12empty:=
13space:= $(empty) $(empty)
14$(if $(findstring $(space),$(TOPDIR)),$(error ERROR: The path to the OpenWrt directory must not include any spaces))
15
16world:
17
18DISTRO_PKG_CONFIG:=$(shell $(TOPDIR)/scripts/command_all.sh pkg-config | grep -e '/usr' -e '/nix/store' -m 1)
19
20export ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
21export PATH:=$(if $(STAGING_DIR),$(abspath $(STAGING_DIR)/../host/bin),$(TOPDIR)/staging_dir/host/bin):$(PATH)
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 CDPATH=
31 export CDPATH
32 include $(TOPDIR)/include/debug.mk
33 include $(TOPDIR)/include/depends.mk
34 include $(TOPDIR)/include/toplevel.mk
35else
36 include rules.mk
37 include $(INCLUDE_DIR)/depends.mk
38 include $(INCLUDE_DIR)/subdir.mk
39 include target/Makefile
40 include package/Makefile
41 include tools/Makefile
42 include toolchain/Makefile
43
44# Include the test suite Makefile if it exists
45-include tests/Makefile
46
47$(toolchain/stamp-compile): $(tools/stamp-compile) $(if $(CONFIG_BUILDBOT),toolchain_rebuild_check)
48$(target/stamp-compile): $(toolchain/stamp-compile) $(tools/stamp-compile) $(BUILD_DIR)/.prepared
49$(package/stamp-compile): $(target/stamp-compile) $(package/stamp-cleanup)
50$(package/stamp-install): $(package/stamp-compile)
51$(target/stamp-install): $(package/stamp-compile) $(package/stamp-install)
52check: $(tools/stamp-check) $(toolchain/stamp-check) $(package/stamp-check)
53
54printdb:
55 @true
56
57prepare: $(target/stamp-compile)
58
59_clean: FORCE
60 rm -rf $(BUILD_DIR) $(STAGING_DIR) $(BIN_DIR) $(OUTPUT_DIR)/packages/$(ARCH_PACKAGES) $(TOPDIR)/staging_dir/packages
61
62clean: _clean
63 rm -rf $(BUILD_LOG_DIR)
64
65targetclean: _clean
66 rm -rf $(TOOLCHAIN_DIR) $(BUILD_DIR_BASE)/hostpkg $(BUILD_DIR_TOOLCHAIN)
67
68dirclean: targetclean clean
69 rm -rf $(STAGING_DIR_HOST) $(STAGING_DIR_HOSTPKG) $(BUILD_DIR_BASE)/host
70 rm -rf $(TMP_DIR)
71 $(MAKE) -C $(TOPDIR)/scripts/config clean
72
73toolchain_rebuild_check:
74 $(SCRIPT_DIR)/check-toolchain-clean.sh
75
76cacheclean:
77ifneq ($(CONFIG_CCACHE),)
78 $(STAGING_DIR_HOST)/bin/ccache -C
79endif
80
81ifndef DUMP_TARGET_DB
82$(BUILD_DIR)/.prepared: Makefile
83 @mkdir -p $$(dirname $@)
84 @touch $@
85
86tmp/.prereq_packages: .config
87 unset ERROR; \
88 for package in $(sort $(prereq-y) $(prereq-m)); do \
89 $(_SINGLE)$(NO_TRACE_MAKE) -s -r -C package/$$package prereq || ERROR=1; \
90 done; \
91 if [ -n "$$ERROR" ]; then \
92 echo "Package prerequisite check failed."; \
93 false; \
94 fi
95 touch $@
96endif
97
98# check prerequisites before starting to build
99prereq: $(target/stamp-prereq) tmp/.prereq_packages
100 @if [ ! -f "$(INCLUDE_DIR)/site/$(ARCH)" ]; then \
101 echo 'ERROR: Missing site config for architecture "$(ARCH)" !'; \
102 echo ' The missing file will cause configure scripts to fail during compilation.'; \
103 echo ' Please provide a "$(INCLUDE_DIR)/site/$(ARCH)" file and restart the build.'; \
104 exit 1; \
105 fi
106ifneq ($(NONEXIST),1)
107 @mkdir -p $(STAGING_DIR)
108 @rm -rf $(STAGING_DIR_HOST)
109 @ln -sf $(TOPDIR)/host/linux$(BITNUM) $(STAGING_DIR_HOST)
110 @rm -rf $(TOOLCHAIN_DIR)
111 @ln -sf $(TOPDIR)/owtoolchain/linux$(BITNUM) $(TOOLCHAIN_DIR)
112endif
113
114$(BIN_DIR)/profiles.json: FORCE
115 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
116 WORK_DIR=$(BUILD_DIR)/json_info_files \
117 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
118 )
119
120json_overview_image_info: $(BIN_DIR)/profiles.json
121
122checksum: FORCE
123 $(call sha256sums,$(BIN_DIR),$(CONFIG_BUILDBOT))
124
125buildversion: FORCE
126 $(SCRIPT_DIR)/getver.sh > $(BIN_DIR)/version.buildinfo
127
128feedsversion: FORCE
129 $(SCRIPT_DIR)/feeds list -fs > $(BIN_DIR)/feeds.buildinfo
130
131diffconfig: FORCE
132 mkdir -p $(BIN_DIR)
133 $(SCRIPT_DIR)/diffconfig.sh > $(BIN_DIR)/config.buildinfo
134
135buildinfo: FORCE
136 $(_SINGLE)$(SUBMAKE) -r diffconfig buildversion feedsversion
137
138prepare: .config $(tools/stamp-compile) $(toolchain/stamp-compile)
139 $(_SINGLE)$(SUBMAKE) -r buildinfo
140
141world: prepare $(target/stamp-compile) $(package/stamp-compile) $(package/stamp-install) $(target/stamp-install) FORCE
142 $(_SINGLE)$(SUBMAKE) -r package/index
143 $(_SINGLE)$(SUBMAKE) -r json_overview_image_info
144 $(_SINGLE)$(SUBMAKE) -r checksum
145ifneq ($(CONFIG_CCACHE),)
146 $(STAGING_DIR_HOST)/bin/ccache -s
147endif
148ifeq ($(NONEXIST),1)
149 @mkdir -p $(TOPDIR)/owtoolchain
150 @mkdir -p $(TOPDIR)/host
151 @mv $(TOOLCHAIN_DIR) $(TOPDIR)/owtoolchain/linux$(BITNUM)
152 @mv $(STAGING_DIR_HOST) $(TOPDIR)/host/linux$(BITNUM)
153 @ln -sf $(TOPDIR)/owtoolchain/linux$(BITNUM) $(TOOLCHAIN_DIR)
154 @ln -sf $(TOPDIR)/host/linux$(BITNUM) $(STAGING_DIR_HOST)
155endif
156
157
158.PHONY: clean dirclean prereq prepare world package/symlinks package/symlinks-install package/symlinks-clean
159
160endif