[backfire] backport host build hook support
[openwrt-10.03/.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 all: $(if $(DUMP),dumpinfo,compile)
9
10 PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
11 PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
12 PKG_MD5SUM ?= unknown
13
14 include $(INCLUDE_DIR)/prereq.mk
15 include $(INCLUDE_DIR)/host.mk
16 include $(INCLUDE_DIR)/unpack.mk
17 include $(INCLUDE_DIR)/depends.mk
18
19 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
20 STAMP_CONFIGURED:=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
21 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
22 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_NAME)_installed
23
24 STAGING_FILES_LIST:=$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
25
26 include $(INCLUDE_DIR)/download.mk
27 include $(INCLUDE_DIR)/quilt.mk
28 include $(INCLUDE_DIR)/package-defaults.mk
29 include $(INCLUDE_DIR)/package-dumpinfo.mk
30 include $(INCLUDE_DIR)/package-ipkg.mk
31 include $(INCLUDE_DIR)/package-bin.mk
32 include $(INCLUDE_DIR)/autotools.mk
33
34 override MAKEFLAGS=
35 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(REAL_GNU_TARGET_NAME)
36 ifneq ($(CONFIG_LINUX_2_4),)
37   CONFIG_SITE:=$(subst linux-,linux2.4-,$(CONFIG_SITE))
38 endif
39 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
40 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
41
42 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
43   ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
44     define Build/Autoclean
45       $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
46       $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
47       $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
48     endef
49   endif
50 endif
51
52 ifeq ($(CONFIG_$(PKG_NAME)_USE_CUSTOM_SOURCE_DIR),y)
53 # disable load stage
54 PKG_SOURCE_URL:=
55 # add hook to install a link to customer source path of dedicated package
56 Hooks/Prepare/Pre += prepare_custom_source_directory
57 # define empty default action
58 define Build/Prepare/Default
59         @: 
60 endef
61 endif
62
63 define Download/default
64   FILE:=$(PKG_SOURCE)
65   URL:=$(PKG_SOURCE_URL)
66   SUBDIR:=$(PKG_SOURCE_SUBDIR)
67   PROTO:=$(PKG_SOURCE_PROTO)
68   $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
69   VERSION:=$(PKG_SOURCE_VERSION)
70   MD5SUM:=$(PKG_MD5SUM)
71 endef
72
73 define Build/Exports/Default
74   $(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))
75   $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
76   $(1) : export PATH=$$(TARGET_PATH_PKG)
77   $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
78   $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR)/usr/lib/pkgconfig
79   $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR)/usr/lib/pkgconfig
80 endef
81 Build/Exports=$(Build/Exports/Default)
82
83 define Build/DefaultTargets
84   $(if $(QUILT),$(Build/Quilt))
85   $(if $(strip $(PKG_SOURCE_URL)),$(call Download,default))
86   $(call Build/Autoclean)
87
88   $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
89   $(STAMP_PREPARED):
90         @-rm -rf $(PKG_BUILD_DIR)
91         @mkdir -p $(PKG_BUILD_DIR)
92         $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
93         $(Build/Prepare)
94         $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
95         touch $$@
96
97   $(call Build/Exports,$(STAMP_CONFIGURED))
98   $(STAMP_CONFIGURED): $(STAMP_PREPARED)
99         $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
100         $(Build/Configure)
101         $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
102         touch $$@
103
104   $(call Build/Exports,$(STAMP_BUILT))
105   $(STAMP_BUILT): $(STAMP_CONFIGURED)
106         $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
107         $(Build/Compile)
108         $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
109         $(Build/Install)
110         $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
111         touch $$@
112
113   $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
114   $(STAMP_INSTALLED): $(STAMP_BUILT)
115         $(SUBMAKE) -j1 clean-staging
116         rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
117         mkdir -p $(TMP_DIR)/stage-$(PKG_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
118         $(foreach hook,$(Hooks/InstallDev/Pre),\
119                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
120         )
121         $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)
122         $(foreach hook,$(Hooks/InstallDev/Post),\
123                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
124         )
125         if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
126                 (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(STAGING_DIR)/packages/$(STAGING_FILES_LIST)); \
127                 $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
128         fi
129         rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
130         touch $$@
131
132   ifdef Build/InstallDev
133     compile: $(STAMP_INSTALLED)
134   endif
135
136   define Build/DefaultTargets
137   endef
138
139   prepare: $(STAMP_PREPARED)
140   configure: $(STAMP_CONFIGURED)
141   dist: $(STAMP_CONFIGURED)
142   distcheck: $(STAMP_CONFIGURED)
143 endef
144
145 define Build/IncludeOverlay
146   $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
147   define Build/IncludeOverlay
148   endef
149 endef
150
151 define BuildPackage
152   $(Build/IncludeOverlay)
153   $(eval $(Package/Default))
154   $(eval $(Package/$(1)))
155
156 ifdef DESCRIPTION
157 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
158 endif
159
160 ifndef Package/$(1)/description
161 define Package/$(1)/description
162         $(TITLE)
163 endef
164 endif
165
166   $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
167     ifeq ($($(FIELD)),)
168       $$(error Package/$(1) is missing the $(FIELD) field)
169     endif
170   )
171
172   $(call shexport,Package/$(1)/description)
173   $(call shexport,Package/$(1)/config)
174
175   $(if $(DUMP), \
176     $(Dumpinfo/Package), \
177     $(foreach target, \
178       $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
179         $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
180       ), $(BuildTarget/$(target)) \
181     ) \
182   )
183   $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
184 endef
185
186 define pkg_install_files
187         $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
188 endef
189
190 define pkg_install_bin
191         $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
192 endef
193
194 Build/Prepare=$(call Build/Prepare/Default,)
195 Build/Configure=$(call Build/Configure/Default,)
196 Build/Compile=$(call Build/Compile/Default,)
197 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
198 Build/Dist=$(call Build/Dist/Default,)
199 Build/DistCheck=$(call Build/DistCheck/Default,)
200
201 $(PACKAGE_DIR):
202         mkdir -p $@
203         
204 dumpinfo:
205 download:
206 prepare:
207 configure:
208 compile:
209 install:
210 clean-staging: FORCE
211         rm -f $(STAMP_INSTALLED)
212         @-(\
213                 cd "$(STAGING_DIR)"; \
214                 if [ -f packages/$(STAGING_FILES_LIST) ]; then \
215                         cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
216                 fi; \
217         )
218
219 clean: clean-staging FORCE
220         $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
221         $(Build/Clean)
222         rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
223         rm -rf $(PKG_BUILD_DIR)
224
225 dist:
226         $(Build/Dist)
227    
228 distcheck:
229         $(Build/DistCheck)