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