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