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