build: decouple the mips16 support flag from the toolchain
[openwrt/staging/wigyori.git] / include / package.mk
1 #
2 # Copyright (C) 2006-2008 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 __package_mk:=1
9
10 all: $(if $(DUMP),dumpinfo,compile)
11
12 PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
13 PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
14 PKG_MD5SUM ?= unknown
15 PKG_BUILD_PARALLEL ?=
16 PKG_USE_MIPS16 ?= 1
17
18 ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
19 MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
20 else
21 MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
22 endif
23
24 ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
25 PKG_JOBS?=-j1
26 else
27 PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
28 $(if $(CONFIG_PKG_BUILD_PARALLEL),$(MAKE_J),-j1),-j1)
29 endif
30 ifdef CONFIG_HAS_MIPS16
31 ifeq ($(strip $(PKG_USE_MIPS16)),1)
32 TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
33 TARGET_CFLAGS += -mips16 -minterlink-mips16
34 endif
35 endif
36
37 include $(INCLUDE_DIR)/prereq.mk
38 include $(INCLUDE_DIR)/host.mk
39 include $(INCLUDE_DIR)/unpack.mk
40 include $(INCLUDE_DIR)/depends.mk
41
42 STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
43 PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
44 ifneq ($(PREV_STAMP_PREPARED),)
45 STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
46 CONFIG_AUTOREBUILD:=
47 else
48 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
49 endif
50 STAMP_CONFIGURED:=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
51 STAMP_CONFIGURED_WILDCARD=$(patsubst %_$(call confvar,$(PKG_CONFIG_DEPENDS)),%_*,$(STAMP_CONFIGURED))
52 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
53 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_NAME)_installed
54
55 STAGING_FILES_LIST:=$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
56 ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
57 USE_GIT_TREE:=1
58 QUILT:=1
59 endif
60
61 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
62 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
63
64 include $(INCLUDE_DIR)/download.mk
65 include $(INCLUDE_DIR)/quilt.mk
66 include $(INCLUDE_DIR)/package-defaults.mk
67 include $(INCLUDE_DIR)/package-dumpinfo.mk
68 include $(INCLUDE_DIR)/package-ipkg.mk
69 include $(INCLUDE_DIR)/package-bin.mk
70 include $(INCLUDE_DIR)/autotools.mk
71
72 override MAKEFLAGS=
73 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(REAL_GNU_TARGET_NAME)
74 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
75 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
76 PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig
77 unexport QUIET
78
79 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
80 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
81 define Build/Autoclean
82 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
83 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
84 $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
85 endef
86 endif
87 endif
88
89 ifeq ($(CONFIG_$(PKG_NAME)_USE_CUSTOM_SOURCE_DIR),y)
90 # disable load stage
91 PKG_SOURCE_URL:=
92 # add hook to install a link to customer source path of dedicated package
93 Hooks/Prepare/Pre += prepare_custom_source_directory
94 ifeq ($(filter autoreconf,$(Hooks/Configure/Pre)),)
95 Hooks/Configure/Pre += autoreconf_target
96 endif
97 # define empty default action
98 define Build/Prepare/Default
99 @:
100 endef
101 endif
102
103 define Download/default
104 FILE:=$(PKG_SOURCE)
105 URL:=$(PKG_SOURCE_URL)
106 SUBDIR:=$(PKG_SOURCE_SUBDIR)
107 PROTO:=$(PKG_SOURCE_PROTO)
108 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
109 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
110 VERSION:=$(PKG_SOURCE_VERSION)
111 MD5SUM:=$(PKG_MD5SUM)
112 endef
113
114 ifdef USE_GIT_TREE
115 define Build/Prepare/Default
116 mkdir -p $(PKG_BUILD_DIR)
117 ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
118 ( cd $(PKG_BUILD_DIR); git checkout .)
119 endef
120 endif
121
122 define Build/Exports/Default
123 $(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))
124 $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
125 $(1) : export PATH=$$(TARGET_PATH_PKG)
126 $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
127 $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
128 $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
129 $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
130 endef
131 Build/Exports=$(Build/Exports/Default)
132
133 define Build/DefaultTargets
134 $(if $(QUILT),$(Build/Quilt))
135 $(if $(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
136 $(call Build/Autoclean)
137
138 download:
139 $(foreach hook,$(Hooks/Download),
140 $(call $(hook))$(sep)
141 )
142
143 $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
144 $(STAMP_PREPARED):
145 @-rm -rf $(PKG_BUILD_DIR)
146 @mkdir -p $(PKG_BUILD_DIR)
147 $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
148 $(Build/Prepare)
149 $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
150 touch $$@
151
152 $(call Build/Exports,$(STAMP_CONFIGURED))
153 $(STAMP_CONFIGURED): $(STAMP_PREPARED)
154 $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
155 $(Build/Configure)
156 $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
157 rm -f $(STAMP_CONFIGURED_WILDCARD)
158 touch $$@
159
160 $(call Build/Exports,$(STAMP_BUILT))
161 $(STAMP_BUILT): $(STAMP_CONFIGURED)
162 $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
163 $(Build/Compile)
164 $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
165 $(Build/Install)
166 $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
167 touch $$@
168
169 $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
170 $(STAMP_INSTALLED): $(STAMP_BUILT)
171 $(SUBMAKE) -j1 clean-staging
172 rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
173 mkdir -p $(TMP_DIR)/stage-$(PKG_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
174 $(foreach hook,$(Hooks/InstallDev/Pre),\
175 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
176 )
177 $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)
178 $(foreach hook,$(Hooks/InstallDev/Post),\
179 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
180 )
181 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
182 $(SCRIPT_DIR)/clean-package.sh \
183 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
184 "$(STAGING_DIR)"; \
185 fi
186 if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
187 (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_NAME).files); \
188 $(call locked, \
189 mv $(TMP_DIR)/stage-$(PKG_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
190 $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
191 ,staging-dir); \
192 fi
193 rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
194 touch $$@
195
196 ifdef Build/InstallDev
197 compile: $(STAMP_INSTALLED)
198 endif
199
200 define Build/DefaultTargets
201 endef
202
203 prepare: $(STAMP_PREPARED)
204 configure: $(STAMP_CONFIGURED)
205 dist: $(STAMP_CONFIGURED)
206 distcheck: $(STAMP_CONFIGURED)
207 endef
208
209 define Build/IncludeOverlay
210 $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
211 define Build/IncludeOverlay
212 endef
213 endef
214
215 define BuildPackage
216 $(Build/IncludeOverlay)
217 $(eval $(Package/Default))
218 $(eval $(Package/$(1)))
219
220 ifdef DESCRIPTION
221 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
222 endif
223
224 ifndef Package/$(1)/description
225 define Package/$(1)/description
226 $(TITLE)
227 endef
228 endif
229
230 $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
231 ifeq ($($(FIELD)),)
232 $$(error Package/$(1) is missing the $(FIELD) field)
233 endif
234 )
235
236 $(call shexport,Package/$(1)/description)
237 $(call shexport,Package/$(1)/config)
238
239 $(if $(DUMP), \
240 $(Dumpinfo/Package), \
241 $(foreach target, \
242 $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
243 $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
244 ), $(BuildTarget/$(target)) \
245 ) \
246 )
247 $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
248 endef
249
250 define pkg_install_files
251 $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
252 endef
253
254 define pkg_install_bin
255 $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
256 endef
257
258 Build/Prepare=$(call Build/Prepare/Default,)
259 Build/Configure=$(call Build/Configure/Default,)
260 Build/Compile=$(call Build/Compile/Default,)
261 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
262 Build/Dist=$(call Build/Dist/Default,)
263 Build/DistCheck=$(call Build/DistCheck/Default,)
264
265 .NOTPARALLEL:
266
267 .PHONY: prepare-package-install
268 prepare-package-install:
269 @mkdir -p $(PKG_INFO_DIR)
270 @touch $(PKG_INSTALL_STAMP).clean
271 @echo "$(filter-out essential,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
272
273 $(PACKAGE_DIR):
274 mkdir -p $@
275
276 dumpinfo:
277 download:
278 prepare:
279 configure:
280 compile: prepare-package-install
281 install: compile
282 clean-staging: FORCE
283 rm -f $(STAMP_INSTALLED)
284 @-(\
285 cd "$(STAGING_DIR)"; \
286 if [ -f packages/$(STAGING_FILES_LIST) ]; then \
287 cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
288 fi; \
289 )
290
291 clean: clean-staging FORCE
292 $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
293 $(Build/Clean)
294 rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
295 rm -rf $(PKG_BUILD_DIR)
296
297 dist:
298 $(Build/Dist)
299
300 distcheck:
301 $(Build/DistCheck)