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