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