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