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