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