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