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