38fd93df73355d5c6331260f325be19458889b62
[openwrt.git] / include / package.mk
1 #
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 ifneq ($(DUMP),)
8 all: dumpinfo
9 else
10 all: compile
11 endif
12
13 define Build/DefaultTargets
14 ifeq ($(DUMP),)
15 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p $(PKG_BUILD_DIR) .),$(PKG_BUILD_DIR))
16 ifeq ($(CONFIG_AUTOREBUILD),y)
17 $(PKG_BUILD_DIR)/.prepared: package-clean
18 endif
19 endif
20
21 ifneq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $(IPKG_$(1)) $(PKG_BUILD_DIR)),$(IPKG_$(1)))
22 ifeq ($(CONFIG_AUTOREBUILD),y)
23 $(PKG_BUILD_DIR)/.built: package-rebuild
24 endif
25 endif
26 endif
27
28
29 $(PKG_BUILD_DIR)/.prepared:
30 @-rm -rf $(PKG_BUILD_DIR)
31 @mkdir -p $(PKG_BUILD_DIR)
32 $(call Build/Prepare)
33 touch $$@
34
35 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
36 $(call Build/Configure)
37 touch $$@
38
39 $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/.configured
40 $(call Build/Compile)
41 touch $$@
42
43 $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed: $(PKG_BUILD_DIR)/.built
44 mkdir -p $(STAGING_DIR)/stampfiles
45 $(call Build/InstallDev)
46 touch $$@
47
48 ifdef Build/InstallDev
49 compile-targets: $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
50 endif
51
52 package-clean: FORCE
53 $(call Build/Clean)
54 $(call Build/UninstallDev)
55 rm -f $(STAGING_DIR)/stampfiles/.$(PKG_NAME)-installed
56
57 package-rebuild: FORCE
58 @-rm -f $(PKG_BUILD_DIR)/.built
59
60 define Build/DefaultTargets
61 endef
62 endef
63
64 define Package/Default
65 CONFIGFILE:=
66 SECTION:=opt
67 CATEGORY:=Extra packages
68 DEPENDS:=
69 EXTRA_DEPENDS:=
70 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
71 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
72 ifneq ($(PKG_VERSION),)
73 ifneq ($(PKG_RELEASE),)
74 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
75 else
76 VERSION:=$(PKG_VERSION)
77 endif
78 else
79 VERSION:=$(PKG_RELEASE)
80 endif
81 PKGARCH:=$(ARCH)
82 PRIORITY:=optional
83 DEFAULT:=
84 MENU:=
85 SUBMENU:=
86 TITLE:=
87 DESCRIPTION:=
88 endef
89
90 define BuildIPKGVariable
91 pkg_$(subst .,_,$(subst -,_,$(1)))_$(2) = $$(Package/$(1)/$(2))
92 export pkg_$(subst .,_,$(subst -,_,$(1))_$(2))
93 $(1)_COMMANDS += if [ -n "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" ]; then echo "$$$$$$$$pkg_$(subst .,_,$(subst -,_,$(1)))_$(2)" > $(2); fi;
94 endef
95
96 define BuildPackage
97 $(eval $(call Package/Default))
98 $(eval $(call Package/$(1)))
99
100 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
101 ifeq ($($(FIELD)),)
102 $$(error Package/$(1) is missing the $(FIELD) field)
103 endif
104 )
105
106 ifeq ($(PKGARCH),)
107 PKGARCH:=$(ARCH)
108 endif
109
110 ifeq ($(DESCRIPTION),)
111 $(eval DESCRIPTION:=$(TITLE))
112 endif
113
114 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
115 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
116 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
117
118 ifdef Package/$(1)/install
119 ifeq ($(CONFIG_PACKAGE_$(1)),y)
120 install-targets: $$(INFO_$(1))
121 endif
122
123 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
124 compile-targets: $$(IPKG_$(1))
125 endif
126 endif
127
128 ifeq ($(FORCEREBUILD),y)
129 $$(IPKG_$(1)): FORCE
130 endif
131
132 IDEPEND_$(1):=$$(strip $$(DEPENDS))
133
134 DUMPINFO += \
135 echo "Package: $(1)";
136
137 ifneq ($(MENU),)
138 DUMPINFO += \
139 echo "Menu: $(MENU)";
140 endif
141
142 ifneq ($(SUBMENU),)
143 DUMPINFO += \
144 echo "Submenu: $(SUBMENU)";
145 endif
146
147 ifneq ($(DEFAULT),)
148 DUMPINFO += \
149 echo "Default: $(DEFAULT)";
150 endif
151
152 DUMPINFO += \
153 echo "Version: $(VERSION)"; \
154 echo "Depends: $$(IDEPEND_$(1))"; \
155 echo "Build-Depends: $(PKG_BUILDDEP)"; \
156 echo "Category: $(CATEGORY)"; \
157 echo "Title: $(TITLE)"; \
158 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
159
160 ifneq ($(URL),)
161 DUMPINFO += \
162 echo; \
163 echo "$(URL)";
164 endif
165
166 DUMPINFO += \
167 echo "@@";
168
169 ifneq ($(CONFIG),)
170 DUMPINFO += \
171 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
172 echo "@@";
173 endif
174
175 $(eval $(call BuildIPKGVariable,$(1),conffiles))
176 $(eval $(call BuildIPKGVariable,$(1),preinst))
177 $(eval $(call BuildIPKGVariable,$(1),postinst))
178 $(eval $(call BuildIPKGVariable,$(1),prerm))
179 $(eval $(call BuildIPKGVariable,$(1),postrm))
180 $$(IDIR_$(1))/CONTROL/control: Makefile $(PKG_BUILD_DIR)/.prepared
181 mkdir -p $$(IDIR_$(1))/CONTROL
182 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
183 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
184 ( \
185 DEPENDS=; \
186 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
187 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
188 done; \
189 echo "Depends: $(EXTRA_DEPENDS) $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
190 )
191 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
192 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
193 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
194 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
195 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
196 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
197 chmod 644 $$(IDIR_$(1))/CONTROL/control
198 (cd $$(IDIR_$(1))/CONTROL; \
199 $($(1)_COMMANDS) \
200 )
201
202 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
203 $(call Package/$(1)/install,$$(IDIR_$(1)))
204 mkdir -p $(PACKAGE_DIR)
205 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
206 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
207 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
208 $(RSTRIP) $$(IDIR_$(1))
209 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
210
211 $$(INFO_$(1)): $$(IPKG_$(1))
212 $(IPKG) install $$(IPKG_$(1))
213
214 $(1)-clean:
215 rm -f $(PACKAGE_DIR)/$(1)_*
216
217 clean: $(1)-clean
218
219 $$(eval $$(call Build/DefaultTargets,$(1)))
220
221 endef
222
223 ifneq ($(strip $(PKG_CAT)),)
224 ifeq ($(PKG_CAT),unzip)
225 UNPACK=unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE)
226 else
227 UNPACK=$(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) -
228 endif
229 define Build/Prepare/Default
230 $(UNPACK)
231 @if [ -d ./patches ]; then \
232 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
233 fi
234 endef
235 endif
236
237 define Build/Prepare
238 $(call Build/Prepare/Default)
239 endef
240
241 define Build/Configure/Default
242 @(cd $(PKG_BUILD_DIR)/$(3); \
243 [ -x configure ] && \
244 $(2) \
245 $(TARGET_CONFIGURE_OPTS) \
246 CFLAGS="$(TARGET_CFLAGS)" \
247 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
248 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
249 ./configure \
250 --target=$(GNU_TARGET_NAME) \
251 --host=$(GNU_TARGET_NAME) \
252 --build=$(GNU_HOST_NAME) \
253 --program-prefix="" \
254 --program-suffix="" \
255 --prefix=/usr \
256 --exec-prefix=/usr \
257 --bindir=/usr/bin \
258 --sbindir=/usr/sbin \
259 --libexecdir=/usr/lib \
260 --sysconfdir=/etc \
261 --datadir=/usr/share \
262 --localstatedir=/var \
263 --mandir=/usr/man \
264 --infodir=/usr/info \
265 $(DISABLE_NLS) \
266 $(1); \
267 true; \
268 )
269 endef
270
271 define Build/Configure
272 $(call Build/Configure/Default,)
273 endef
274
275 define Build/Compile/Default
276 $(MAKE) -C $(PKG_BUILD_DIR) \
277 $(TARGET_CONFIGURE_OPTS) \
278 CC=$(TARGET_CC) \
279 CROSS="$(TARGET_CROSS)" \
280 EXTRA_CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/include -I$(STAGING_DIR)/usr/include" \
281 ARCH="$(ARCH)" \
282 $(1);
283 endef
284
285 define Build/Compile
286 $(call Build/Compile/Default,)
287 endef
288
289 ifneq ($(DUMP),)
290 dumpinfo: FORCE
291 @$(DUMPINFO)
292 else
293 $(PACKAGE_DIR):
294 mkdir -p $@
295
296 ifneq ($(strip $(PKG_SOURCE)),)
297 download: $(DL_DIR)/$(PKG_SOURCE)
298
299 $(DL_DIR)/$(PKG_SOURCE):
300 mkdir -p $(DL_DIR)
301 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
302
303 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
304 endif
305
306 download:
307 prepare: $(PKG_BUILD_DIR)/.prepared
308 configure: $(PKG_BUILD_DIR)/.configured
309
310 compile-targets:
311 compile: compile-targets
312
313 install-targets:
314 install: install-targets
315
316 clean-targets:
317 clean: FORCE
318 @$(MAKE) clean-targets
319 $(call Build/Clean)
320 rm -rf $(PKG_BUILD_DIR)
321 endif
This page took 0.057635 seconds and 3 git commands to generate.