e13cfe678c5bd3c589d667e85fbf8b3d9cd3fe71
[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 sep
74
75 endef
76
77 define Build/Exports/Default
78   $(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))
79   $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
80   $(1) : export PATH=$$(TARGET_PATH_PKG)
81   $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
82   $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR)/usr/lib/pkgconfig
83   $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR)/usr/lib/pkgconfig
84 endef
85 Build/Exports=$(Build/Exports/Default)
86
87 define Build/DefaultTargets
88   $(if $(QUILT),$(Build/Quilt))
89   $(if $(strip $(PKG_SOURCE_URL)),$(call Download,default))
90   $(call Build/Autoclean)
91
92   $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
93   $(STAMP_PREPARED):
94         @-rm -rf $(PKG_BUILD_DIR)
95         @mkdir -p $(PKG_BUILD_DIR)
96         $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
97         $(Build/Prepare)
98         $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
99         touch $$@
100
101   $(call Build/Exports,$(STAMP_CONFIGURED))
102   $(STAMP_CONFIGURED): $(STAMP_PREPARED)
103         $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
104         $(Build/Configure)
105         $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
106         touch $$@
107
108   $(call Build/Exports,$(STAMP_BUILT))
109   $(STAMP_BUILT): $(STAMP_CONFIGURED)
110         $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
111         $(Build/Compile)
112         $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
113         $(Build/Install)
114         $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
115         touch $$@
116
117   $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
118   $(STAMP_INSTALLED): $(STAMP_BUILT)
119         $(SUBMAKE) -j1 clean-staging
120         rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
121         mkdir -p $(TMP_DIR)/stage-$(PKG_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
122         $(foreach hook,$(Hooks/InstallDev/Pre),\
123                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
124         )
125         $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)
126         $(foreach hook,$(Hooks/InstallDev/Post),\
127                 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
128         )
129         if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
130                 (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(STAGING_DIR)/packages/$(STAGING_FILES_LIST)); \
131                 $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
132         fi
133         rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
134         touch $$@
135
136   ifdef Build/InstallDev
137     compile: $(STAMP_INSTALLED)
138   endif
139
140   define Build/DefaultTargets
141   endef
142
143   prepare: $(STAMP_PREPARED)
144   configure: $(STAMP_CONFIGURED)
145   dist: $(STAMP_CONFIGURED)
146   distcheck: $(STAMP_CONFIGURED)
147 endef
148
149 define Build/IncludeOverlay
150   $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
151   define Build/IncludeOverlay
152   endef
153 endef
154
155 define BuildPackage
156   $(Build/IncludeOverlay)
157   $(eval $(Package/Default))
158   $(eval $(Package/$(1)))
159
160 ifdef DESCRIPTION
161 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
162 endif
163
164 ifndef Package/$(1)/description
165 define Package/$(1)/description
166         $(TITLE)
167 endef
168 endif
169
170   $(foreach FIELD, TITLE CATEGORY PRIORITY SECTION VERSION,
171     ifeq ($($(FIELD)),)
172       $$(error Package/$(1) is missing the $(FIELD) field)
173     endif
174   )
175
176   $(call shexport,Package/$(1)/description)
177   $(call shexport,Package/$(1)/config)
178
179   $(if $(DUMP), \
180     $(Dumpinfo/Package), \
181     $(foreach target, \
182       $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
183         $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
184       ), $(BuildTarget/$(target)) \
185     ) \
186   )
187   $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
188 endef
189
190 define pkg_install_files
191         $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
192 endef
193
194 define pkg_install_bin
195         $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
196 endef
197
198 Build/Prepare=$(call Build/Prepare/Default,)
199 Build/Configure=$(call Build/Configure/Default,)
200 Build/Compile=$(call Build/Compile/Default,)
201 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
202 Build/Dist=$(call Build/Dist/Default,)
203 Build/DistCheck=$(call Build/DistCheck/Default,)
204
205 $(PACKAGE_DIR):
206         mkdir -p $@
207         
208 dumpinfo:
209 download:
210 prepare:
211 configure:
212 compile:
213 install:
214 clean-staging: FORCE
215         rm -f $(STAMP_INSTALLED)
216         @-(\
217                 cd "$(STAGING_DIR)"; \
218                 if [ -f packages/$(STAGING_FILES_LIST) ]; then \
219                         cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
220                 fi; \
221         )
222
223 clean: clean-staging FORCE
224         $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
225         $(Build/Clean)
226         rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
227         rm -rf $(PKG_BUILD_DIR)
228
229 dist:
230         $(Build/Dist)
231    
232 distcheck:
233         $(Build/DistCheck)