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