rpcd: iwinfo plugin fixes
[openwrt/svn-archive/archive.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_IREMAP ?= 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 ifeq ($(strip $(PKG_IREMAP)),1)
38 IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR)))
39 TARGET_CFLAGS += $(IREMAP_CFLAGS)
40 endif
41
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
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 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)
62 CONFIG_AUTOREBUILD:=
63 else
64 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
65 endif
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
70
71 STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
72
73 define CleanStaging
74 rm -f $(STAMP_INSTALLED)
75 @-(\
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; \
79 fi; \
80 )
81 endef
82
83 ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
84 USE_GIT_TREE:=1
85 QUILT:=1
86 endif
87 ifdef USE_SOURCE_DIR
88 QUILT:=1
89 endif
90 ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
91 QUILT:=1
92 endif
93
94 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
95
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
103
104 override MAKEFLAGS=
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
110
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*"))
117 endef
118 endif
119 endif
120
121 define Download/default
122 FILE:=$(PKG_SOURCE)
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)
130 endef
131
132 ifdef USE_GIT_TREE
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 .)
137 endef
138 endif
139 ifdef USE_SOURCE_DIR
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
145 endef
146 endif
147
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
156 endef
157 Build/Exports=$(Build/Exports/Default)
158
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)
163
164 download:
165 $(foreach hook,$(Hooks/Download),
166 $(call $(hook))$(sep)
167 )
168
169 $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
170 $(STAMP_PREPARED):
171 @-rm -rf $(PKG_BUILD_DIR)
172 @mkdir -p $(PKG_BUILD_DIR)
173 $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
174 $(Build/Prepare)
175 $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
176 touch $$@
177
178 $(call Build/Exports,$(STAMP_CONFIGURED))
179 $(STAMP_CONFIGURED): $(STAMP_PREPARED)
180 $(CleanStaging)
181 $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
182 $(Build/Configure)
183 $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
184 rm -f $(STAMP_CONFIGURED_WILDCARD)
185 touch $$@
186
187 $(call Build/Exports,$(STAMP_BUILT))
188 $(STAMP_BUILT): $(STAMP_CONFIGURED)
189 $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
190 $(Build/Compile)
191 $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
192 $(Build/Install)
193 $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
194 touch $$@
195
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)\
202 )
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)\
206 )
207 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
208 $(SCRIPT_DIR)/clean-package.sh \
209 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
210 "$(STAGING_DIR)"; \
211 fi
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); \
214 $(call locked, \
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)/; \
217 ,staging-dir); \
218 fi
219 rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
220 touch $$@
221
222 ifdef Build/InstallDev
223 compile: $(STAMP_INSTALLED)
224 endif
225
226 define Build/DefaultTargets
227 endef
228
229 prepare: $(STAMP_PREPARED)
230 configure: $(STAMP_CONFIGURED)
231 dist: $(STAMP_CONFIGURED)
232 distcheck: $(STAMP_CONFIGURED)
233 endef
234
235 define Build/IncludeOverlay
236 $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_DIR_NAME).mk))
237 define Build/IncludeOverlay
238 endef
239 endef
240
241 define BuildPackage
242 $(Build/IncludeOverlay)
243 $(eval $(Package/Default))
244 $(eval $(Package/$(1)))
245
246 ifdef DESCRIPTION
247 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
248 endif
249
250 ifndef Package/$(1)/description
251 define Package/$(1)/description
252 $(TITLE)
253 endef
254 endif
255
256 BUILD_PACKAGES += $(1)
257 $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
258
259 $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
260 ifeq ($($(FIELD)),)
261 $$(error Package/$(1) is missing the $(FIELD) field)
262 endif
263 )
264
265 $(if $(DUMP), \
266 $(Dumpinfo/Package), \
267 $(foreach target, \
268 $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
269 $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
270 ), $(BuildTarget/$(target)) \
271 ) \
272 )
273 $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
274 endef
275
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)`;)
278 endef
279
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)`;)
282 endef
283
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,)
290
291 .NOTPARALLEL:
292
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
298
299 $(PACKAGE_DIR):
300 mkdir -p $@
301
302 dumpinfo:
303 download:
304 prepare:
305 configure:
306 compile: prepare-package-install
307 install: compile
308
309 clean: FORCE
310 $(CleanStaging)
311 $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
312 $(Build/Clean)
313 rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
314 rm -rf $(PKG_BUILD_DIR)
315
316 dist:
317 $(Build/Dist)
318
319 distcheck:
320 $(Build/DistCheck)