Root/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
8all: $(if $(DUMP),dumpinfo,compile)
9
10PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
11PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
12PKG_MD5SUM ?= unknown
13
14include $(INCLUDE_DIR)/prereq.mk
15include $(INCLUDE_DIR)/host.mk
16include $(INCLUDE_DIR)/unpack.mk
17include $(INCLUDE_DIR)/depends.mk
18
19STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
20STAMP_CONFIGURED:=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
21STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
22STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_NAME)_installed
23
24STAGING_FILES_LIST:=$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
25
26include $(INCLUDE_DIR)/download.mk
27include $(INCLUDE_DIR)/quilt.mk
28include $(INCLUDE_DIR)/package-defaults.mk
29include $(INCLUDE_DIR)/package-dumpinfo.mk
30include $(INCLUDE_DIR)/package-ipkg.mk
31include $(INCLUDE_DIR)/package-bin.mk
32include $(INCLUDE_DIR)/autotools.mk
33
34override MAKEFLAGS=
35CONFIG_SITE:=$(INCLUDE_DIR)/site/$(REAL_GNU_TARGET_NAME)
36ifneq ($(CONFIG_LINUX_2_4),)
37  CONFIG_SITE:=$(subst linux-,linux2.4-,$(CONFIG_SITE))
38endif
39CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
40SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
41
42ifeq ($(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
50endif
51
52ifeq ($(CONFIG_$(PKG_NAME)_USE_CUSTOM_SOURCE_DIR),y)
53# disable load stage
54PKG_SOURCE_URL:=
55# add hook to install a link to customer source path of dedicated package
56Hooks/Prepare/Pre += prepare_custom_source_directory
57# define empty default action
58define Build/Prepare/Default
59    @:
60endef
61endif
62
63define 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)
71endef
72
73define sep
74
75endef
76
77define 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
84endef
85Build/Exports=$(Build/Exports/Default)
86
87define 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)
147endef
148
149define Build/IncludeOverlay
150  $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
151  define Build/IncludeOverlay
152  endef
153endef
154
155define BuildPackage
156  $(Build/IncludeOverlay)
157  $(eval $(Package/Default))
158  $(eval $(Package/$(1)))
159
160ifdef DESCRIPTION
161$$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
162endif
163
164ifndef Package/$(1)/description
165define Package/$(1)/description
166    $(TITLE)
167endef
168endif
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)))
188endef
189
190define pkg_install_files
191    $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
192endef
193
194define pkg_install_bin
195    $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
196endef
197
198Build/Prepare=$(call Build/Prepare/Default,)
199Build/Configure=$(call Build/Configure/Default,)
200Build/Compile=$(call Build/Compile/Default,)
201Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
202Build/Dist=$(call Build/Dist/Default,)
203Build/DistCheck=$(call Build/DistCheck/Default,)
204
205$(PACKAGE_DIR):
206    mkdir -p $@
207    
208dumpinfo:
209download:
210prepare:
211configure:
212compile:
213install:
214clean-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
223clean: 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
229dist:
230    $(Build/Dist)
231   
232distcheck:
233    $(Build/DistCheck)
234

Archive Download this file



interactive