add Build/InstallDev template to install dev files in STAGING_DIR, introduce a NEEDS...
[openwrt/staging/mkresin.git] / openwrt / 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 echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
138 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
139 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
140 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
141 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
142 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
143 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
144 chmod 644 $$(IDIR_$(1))/CONTROL/control
145 for file in conffiles preinst postinst prerm postrm; do \
146 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
147 done
148
149 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
150 $(call Package/$(1)/install,$$(IDIR_$(1)))
151 mkdir -p $(PACKAGE_DIR)
152 $(RSTRIP) $$(IDIR_$(1))
153 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
154
155 $$(INFO_$(1)): $$(IPKG_$(1))
156 $(IPKG) install $$(IPKG_$(1))
157
158 compile-targets: $(PKG_BUILD_DIR)/.dev-installed
159
160 $(1)-clean:
161 rm -f $(PACKAGE_DIR)/$(1)_*
162
163 clean: $(1)-clean
164
165 $$(eval $$(call Build/DefaultTargets,$(1)))
166
167 endef
168
169 ifneq ($(strip $(PKG_SOURCE)),)
170 $(DL_DIR)/$(PKG_SOURCE):
171 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
172 endif
173
174 ifneq ($(strip $(PKG_CAT)),)
175 define Build/Prepare/Default
176 @if [ "$(PKG_CAT)" = "unzip" ]; then \
177 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
178 else \
179 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
180 fi
181 @if [ -d ./patches ]; then \
182 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
183 fi
184 endef
185 endif
186
187 define Build/Prepare
188 $(call Build/Prepare/Default)
189 endef
190
191 define Build/Configure/Default
192 @(cd $(PKG_BUILD_DIR); \
193 [ -x configure ] && \
194 $(TARGET_CONFIGURE_OPTS) \
195 CFLAGS="$(TARGET_CFLAGS)" \
196 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
197 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
198 ./configure \
199 --target=$(GNU_TARGET_NAME) \
200 --host=$(GNU_TARGET_NAME) \
201 --build=$(GNU_HOST_NAME) \
202 --program-prefix="" \
203 --program-suffix="" \
204 --prefix=/usr \
205 --exec-prefix=/usr \
206 --bindir=/usr/bin \
207 --sbindir=/usr/sbin \
208 --libexecdir=/usr/lib \
209 --sysconfdir=/etc \
210 --datadir=/usr/share \
211 --localstatedir=/var \
212 --mandir=/usr/man \
213 --infodir=/usr/info \
214 $(DISABLE_NLS) \
215 $(1); \
216 true; \
217 )
218 endef
219
220 define Build/Configure
221 $(call Build/Configure/Default,)
222 endef
223
224 define Build/Compile/Default
225 $(MAKE) -C $(PKG_BUILD_DIR) \
226 CC=$(TARGET_CC) \
227 CROSS="$(TARGET_CROSS)" \
228 PREFIX="$$(IDIR_$(1))" \
229 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
230 ARCH="$(ARCH)" \
231 DESTDIR="$$(IDIR_$(1))" \
232 $(1);
233 endef
234
235 define Build/Compile
236 $(call Build/Compile/Default,)
237 endef
238
239 define Build/InstallDev
240 endef
241
242 define Build/Clean
243 $(MAKE) clean
244 endef
245
246 define Build/UninstallDev
247 endef
248
249 ifneq ($(DUMP),)
250 dumpinfo: FORCE
251 @$(DUMPINFO)
252 else
253
254 $(PACKAGE_DIR):
255 mkdir -p $@
256
257 source: $(DL_DIR)/$(PKG_SOURCE)
258 prepare: $(PKG_BUILD_DIR)/.prepared
259 configure: $(PKG_BUILD_DIR)/.configured
260
261 compile-targets:
262 compile: compile-targets
263
264 install-targets:
265 install: install-targets
266
267 clean-targets:
268 clean: FORCE
269 @$(MAKE) clean-targets
270 rm -rf $(PKG_BUILD_DIR)
271 endif