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