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