2 # Copyright (C) 2006-2008 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
10 all: $(if $(DUMP),dumpinfo,compile)
12 PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
13 PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
19 ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
20 MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
22 MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
25 ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
28 PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
29 $(if $(CONFIG_PKG_BUILD_PARALLEL),$(MAKE_J),-j1),-j1)
31 ifdef CONFIG_USE_MIPS16
32 ifeq ($(strip $(PKG_USE_MIPS16)),1)
33 TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
34 TARGET_CFLAGS += -mips16 -minterlink-mips16
37 ifeq ($(strip $(PKG_IREMAP)),1)
38 IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR)))
39 TARGET_CFLAGS += $(IREMAP_CFLAGS)
42 include $(INCLUDE_DIR)/hardening.mk
43 include $(INCLUDE_DIR)/prereq.mk
44 include $(INCLUDE_DIR)/host.mk
45 include $(INCLUDE_DIR)/unpack.mk
46 include $(INCLUDE_DIR)/depends.mk
48 find_library_dependencies = $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
49 $(filter-out $(BUILD_PACKAGES),$(foreach dep, \
50 $(filter-out @%, $(patsubst +%,%,$(1))), \
51 $(if $(findstring :,$(dep)), \
52 $(word 2,$(subst :,$(space),$(dep))), \
57 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
58 STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
59 PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
60 ifneq ($(PREV_STAMP_PREPARED),)
61 STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
64 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
66 STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
67 STAMP_CONFIGURED_WILDCARD=$(patsubst %_$(call confvar,$(PKG_CONFIG_DEPENDS)),%_*,$(STAMP_CONFIGURED))
68 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
69 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
71 STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
74 rm -f $(STAMP_INSTALLED)
76 cd "$(STAGING_DIR)"; \
77 if [ -f packages/$(STAGING_FILES_LIST) ]; then \
78 cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
83 ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
90 ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
94 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
96 include $(INCLUDE_DIR)/download.mk
97 include $(INCLUDE_DIR)/quilt.mk
98 include $(INCLUDE_DIR)/package-defaults.mk
99 include $(INCLUDE_DIR)/package-dumpinfo.mk
100 include $(INCLUDE_DIR)/package-ipkg.mk
101 include $(INCLUDE_DIR)/package-bin.mk
102 include $(INCLUDE_DIR)/autotools.mk
105 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
106 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
107 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
108 PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
109 unexport QUIET CONFIG_SITE
111 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
112 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
113 define Build/Autoclean
114 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
115 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
116 $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
121 define Download/default
123 URL:=$(PKG_SOURCE_URL)
124 SUBDIR:=$(PKG_SOURCE_SUBDIR)
125 PROTO:=$(PKG_SOURCE_PROTO)
126 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
127 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
128 VERSION:=$(PKG_SOURCE_VERSION)
129 MD5SUM:=$(PKG_MD5SUM)
133 define Build/Prepare/Default
134 mkdir -p $(PKG_BUILD_DIR)
135 ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
136 ( cd $(PKG_BUILD_DIR); git checkout .)
140 define Build/Prepare/Default
141 rm -rf $(PKG_BUILD_DIR)
142 $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
143 ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
144 touch $(PKG_BUILD_DIR)/.source_dir
148 define Build/Exports/Default
149 $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR)/usr/share/aclocal $$(STAGING_DIR)/usr/share/aclocal-* $$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*),-I $$(p))
150 $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
151 $(1) : export PATH=$$(TARGET_PATH_PKG)
152 $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
153 $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
154 $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
155 $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
157 Build/Exports=$(Build/Exports/Default)
159 define Build/DefaultTargets
160 $(if $(QUILT),$(Build/Quilt))
161 $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
162 $(call Build/Autoclean)
165 $(foreach hook,$(Hooks/Download),
166 $(call $(hook))$(sep)
169 $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
171 @-rm -rf $(PKG_BUILD_DIR)
172 @mkdir -p $(PKG_BUILD_DIR)
173 $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
175 $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
178 $(call Build/Exports,$(STAMP_CONFIGURED))
179 $(STAMP_CONFIGURED): $(STAMP_PREPARED)
181 $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
183 $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
184 rm -f $(STAMP_CONFIGURED_WILDCARD)
187 $(call Build/Exports,$(STAMP_BUILT))
188 $(STAMP_BUILT): $(STAMP_CONFIGURED)
189 $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
191 $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
193 $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
196 $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
197 $(STAMP_INSTALLED): $(STAMP_BUILT)
198 rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
199 mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
200 $(foreach hook,$(Hooks/InstallDev/Pre),\
201 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
203 $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
204 $(foreach hook,$(Hooks/InstallDev/Post),\
205 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
207 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
208 $(SCRIPT_DIR)/clean-package.sh \
209 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
212 if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
213 (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
215 mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
216 $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
219 rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
222 ifdef Build/InstallDev
223 compile: $(STAMP_INSTALLED)
226 define Build/DefaultTargets
229 prepare: $(STAMP_PREPARED)
230 configure: $(STAMP_CONFIGURED)
231 dist: $(STAMP_CONFIGURED)
232 distcheck: $(STAMP_CONFIGURED)
235 define Build/IncludeOverlay
236 $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_DIR_NAME).mk))
237 define Build/IncludeOverlay
242 $(Build/IncludeOverlay)
243 $(eval $(Package/Default))
244 $(eval $(Package/$(1)))
247 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
250 ifndef Package/$(1)/description
251 define Package/$(1)/description
256 BUILD_PACKAGES += $(1)
257 $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
259 $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
261 $$(error Package/$(1) is missing the $(FIELD) field)
266 $(Dumpinfo/Package), \
268 $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
269 $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
270 ), $(BuildTarget/$(target)) \
273 $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
276 define pkg_install_files
277 $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
280 define pkg_install_bin
281 $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
284 Build/Prepare=$(call Build/Prepare/Default,)
285 Build/Configure=$(call Build/Configure/Default,)
286 Build/Compile=$(call Build/Compile/Default,)
287 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
288 Build/Dist=$(call Build/Dist/Default,)
289 Build/DistCheck=$(call Build/DistCheck/Default,)
293 .PHONY: prepare-package-install
294 prepare-package-install:
295 @mkdir -p $(PKG_INFO_DIR)
296 @touch $(PKG_INSTALL_STAMP).clean
297 @echo "$(filter-out essential,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
306 compile: prepare-package-install
311 $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
313 rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
314 rm -rf $(PKG_BUILD_DIR)