ramips: explicitly disable built-in switch when needed
[oweals/openwrt.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,$(if $(CHECK),check,compile))
11
12 include $(INCLUDE_DIR)/download.mk
13
14 PKG_BUILD_DIR ?= $(BUILD_DIR)/$(if $(BUILD_VARIANT),$(PKG_NAME)-$(BUILD_VARIANT)/)$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
15 PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
16 PKG_BUILD_PARALLEL ?=
17 PKG_USE_MIPS16 ?= 1
18 PKG_IREMAP ?= 1
19
20 MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
21
22 ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
23 PKG_JOBS?=-j1
24 else
25 PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL),$(MAKE_J),-j1)
26 endif
27 ifdef CONFIG_USE_MIPS16
28   ifeq ($(strip $(PKG_USE_MIPS16)),1)
29     TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
30     TARGET_CFLAGS += -mips16 -minterlink-mips16
31   endif
32 endif
33 ifeq ($(strip $(PKG_IREMAP)),1)
34   IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR)))
35   TARGET_CFLAGS += $(IREMAP_CFLAGS)
36 endif
37
38 include $(INCLUDE_DIR)/hardening.mk
39 include $(INCLUDE_DIR)/prereq.mk
40 include $(INCLUDE_DIR)/unpack.mk
41 include $(INCLUDE_DIR)/depends.mk
42
43 ifneq ($(wildcard $(TOPDIR)/git-src/$(PKG_NAME)/.git),)
44   USE_GIT_SRC_CHECKOUT:=1
45   QUILT:=1
46 endif
47 ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
48   USE_GIT_TREE:=1
49   QUILT:=1
50 endif
51 ifdef USE_SOURCE_DIR
52   QUILT:=1
53 endif
54 ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
55   QUILT:=1
56 endif
57
58 include $(INCLUDE_DIR)/quilt.mk
59
60 find_library_dependencies = \
61         $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
62                 $(sort $(foreach dep4, \
63                         $(sort $(foreach dep3, \
64                                 $(sort $(foreach dep2, \
65                                         $(sort $(foreach dep1, \
66                                                 $(sort $(foreach dep0, \
67                                                         $(Package/$(1)/depends), \
68                                                         $(Package/$(dep0)/depends) $(dep0) \
69                                                 )), \
70                                                 $(Package/$(dep1)/depends) $(dep1) \
71                                         )), \
72                                         $(Package/$(dep2)/depends) $(dep2) \
73                                 )), \
74                                 $(Package/$(dep3)/depends) $(dep3) \
75                         )), \
76                         $(Package/$(dep4)/depends) $(dep4) \
77                 )), \
78         ))
79
80
81 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
82 STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
83 PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
84 ifneq ($(PREV_STAMP_PREPARED),)
85   STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
86   CONFIG_AUTOREBUILD:=
87 else
88   STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
89 endif
90 STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
91 STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
92 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
93 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
94
95 STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
96
97 define CleanStaging
98         rm -f $(STAMP_INSTALLED)
99         @-(\
100                 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
101                         $(SCRIPT_DIR)/clean-package.sh \
102                                 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
103                                 "$(STAGING_DIR)"; \
104                 fi; \
105         )
106 endef
107
108
109 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
110
111 include $(INCLUDE_DIR)/package-defaults.mk
112 include $(INCLUDE_DIR)/package-dumpinfo.mk
113 include $(INCLUDE_DIR)/package-ipkg.mk
114 include $(INCLUDE_DIR)/package-bin.mk
115 include $(INCLUDE_DIR)/autotools.mk
116
117 _pkg_target:=$(if $(QUILT),,.)
118
119 override MAKEFLAGS=
120 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
121 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
122 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
123 PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
124 unexport QUIET CONFIG_SITE
125
126 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
127   ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
128     define Build/Autoclean
129       $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
130       $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
131       $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
132     endef
133   endif
134 endif
135
136 ifdef USE_GIT_SRC_CHECKOUT
137   define Build/Prepare/Default
138         mkdir -p $(PKG_BUILD_DIR)
139         ln -s $(TOPDIR)/git-src/$(PKG_NAME)/.git $(PKG_BUILD_DIR)/.git
140         ( cd $(PKG_BUILD_DIR); \
141                 git checkout .; \
142                 git submodule update --recursive; \
143                 git submodule foreach git config --unset core.worktree; \
144                 git submodule foreach git checkout .; \
145         )
146   endef
147 endif
148 ifdef USE_GIT_TREE
149   define Build/Prepare/Default
150         mkdir -p $(PKG_BUILD_DIR)
151         ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
152         ( cd $(PKG_BUILD_DIR); \
153                 git checkout .; \
154                 git submodule update --recursive; \
155                 git submodule foreach git config --unset core.worktree; \
156                 git submodule foreach git checkout .; \
157         )
158   endef
159 endif
160 ifdef USE_SOURCE_DIR
161   define Build/Prepare/Default
162         rm -rf $(PKG_BUILD_DIR)
163         $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
164         ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
165         touch $(PKG_BUILD_DIR)/.source_dir
166   endef
167 endif
168
169 define Build/Exports/Default
170   $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR)/usr/share/aclocal $$(STAGING_DIR)/usr/share/aclocal-* $$(STAGING_DIR_HOSTPKG)/share/aclocal $$(STAGING_DIR_HOSTPKG)/share/aclocal-* $$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*),-I $$(p))
171   $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
172   $(1) : export PATH=$$(TARGET_PATH_PKG)
173   $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
174   $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
175   $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
176   $(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache)
177 endef
178 Build/Exports=$(Build/Exports/Default)
179
180 define Build/CoreTargets
181   STAMP_PREPARED:=$$(STAMP_PREPARED)
182   STAMP_CONFIGURED:=$$(STAMP_CONFIGURED)
183
184   $(if $(QUILT),$(Build/Quilt))
185   $(call Build/Autoclean)
186   $(call DefaultTargets)
187
188   download:
189         $(foreach hook,$(Hooks/Download),
190                 $(call $(hook))$(sep)
191         )
192
193   $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
194   $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
195         @-rm -rf $(PKG_BUILD_DIR)
196         @mkdir -p $(PKG_BUILD_DIR)
197         touch $$@_check
198         $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
199         $(Build/Prepare)
200         $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
201         touch $$@
202
203   $(call Build/Exports,$(STAMP_CONFIGURED))
204   $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
205         rm -f $(STAMP_CONFIGURED_WILDCARD)
206         $(CleanStaging)
207         $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
208         $(Build/Configure)
209         $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
210         touch $$@
211
212   $(call Build/Exports,$(STAMP_BUILT))
213   $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
214         rm -f $$@
215         touch $$@_check
216         $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
217         $(Build/Compile)
218         $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
219         $(Build/Install)
220         $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
221         touch $$@
222
223   $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
224   $(STAMP_INSTALLED): $(STAMP_BUILT)
225         rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
226         mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages
227         $(foreach hook,$(Hooks/InstallDev/Pre),\
228                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
229         )
230         $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
231         $(foreach hook,$(Hooks/InstallDev/Post),\
232                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
233         )
234         if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
235                 $(SCRIPT_DIR)/clean-package.sh \
236                         "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
237                         "$(STAGING_DIR)"; \
238         fi
239         if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
240                 (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
241                 $(call locked, \
242                         mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
243                         $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
244                 ,staging-dir); \
245         fi
246         rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
247         touch $$@
248
249   ifdef Build/InstallDev
250     $(_pkg_target)compile: $(STAMP_INSTALLED)
251   endif
252
253   $(_pkg_target)prepare: $(STAMP_PREPARED)
254   $(_pkg_target)configure: $(STAMP_CONFIGURED)
255   $(_pkg_target)dist: $(STAMP_CONFIGURED)
256   $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
257
258   ifneq ($(CONFIG_AUTOREMOVE),)
259     compile:
260                 -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
261                 $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
262                         $(XARGS) rm -rf
263   endif
264 endef
265
266 define Build/DefaultTargets
267   $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE)$(USE_GIT_SRC_CHECKOUT),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
268   $(if $(DUMP),,$(Build/CoreTargets))
269
270   define Build/DefaultTargets
271   endef
272 endef
273
274 define BuildPackage
275   $(eval $(Package/Default))
276   $(eval $(Package/$(1)))
277
278 ifdef DESCRIPTION
279 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
280 endif
281
282 ifndef Package/$(1)/description
283 define Package/$(1)/description
284         $(TITLE)
285 endef
286 endif
287
288   BUILD_PACKAGES += $(1)
289   $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(1)))
290
291   $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
292     ifeq ($($(FIELD)),)
293       $$(error Package/$(1) is missing the $(FIELD) field)
294     endif
295   )
296
297   $(if $(DUMP), \
298     $(if $(CHECK),,$(Dumpinfo/Package)), \
299     $(foreach target, \
300       $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
301         $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
302       ), $(BuildTarget/$(target)) \
303     ) \
304   )
305   $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
306 endef
307
308 define pkg_install_files
309         $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
310 endef
311
312 define pkg_install_bin
313         $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
314 endef
315
316 Build/Prepare=$(call Build/Prepare/Default,)
317 Build/Configure=$(call Build/Configure/Default,)
318 Build/Compile=$(call Build/Compile/Default,)
319 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
320 Build/Dist=$(call Build/Dist/Default,)
321 Build/DistCheck=$(call Build/DistCheck/Default,)
322
323 .NOTPARALLEL:
324
325 .PHONY: prepare-package-install
326 prepare-package-install:
327         @mkdir -p $(PKG_INFO_DIR)
328         @rm -f $(PKG_INSTALL_STAMP)
329         @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
330
331 $(PACKAGE_DIR):
332         mkdir -p $@
333
334 compile:
335 .install: .compile
336 install: compile
337
338 force-clean-build: FORCE
339         rm -rf $(PKG_BUILD_DIR)
340
341 clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
342
343 clean: force-clean-build
344         $(CleanStaging)
345         $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR)/host)
346         $(Build/Clean)
347         rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST)
348
349 dist:
350         $(Build/Dist)
351
352 distcheck:
353         $(Build/DistCheck)