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