partial cleanup
[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: $(PKG_BUILD_DIR)/.configured
21 $(call Build/Compile)
22 touch $$@
23
24 package-clean:
25 $(call Build/Clean)
26 rm -f $(PKG_BUILD_DIR)/.built
27
28 package-recompile:
29 rm -f $(PKG_BUILD_DIR)/.built
30
31 .PHONY: package-clean package-recompile
32
33 # define Build/DefaultTargets
34 # endef
35 endef
36
37 define Package/Default
38 CONFIGFILE:=
39 SECTION:=opt
40 CATEGORY:=Extra packages
41 DEPENDS:=
42 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
43 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
44 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
45 PKGARCH:=$(ARCH)
46 PRIORITY:=optional
47 DEFAULT:=
48 MENU:=
49 TITLE:=
50 DESCRIPTION:=
51 endef
52
53 define RequiredField
54 ifeq ($$($(1)),)
55 $$(error Package/$$(1) is missing the $(1) field)
56 endif
57 endef
58
59 define BuildPackage
60 $(eval $(call Package/Default))
61 $(eval $(call Package/$(1)))
62
63 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION, $(eval $(call RequiredField,$(FIELD))))
64
65 ifeq ($(PKGARCH),)
66 PKGARCH:=$(ARCH)
67 endif
68 $(eval
69 ifeq ($(DESCRIPTION),)
70 DESCRIPTION:=$(TITLE)
71 endif
72 )
73
74 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
75 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
76 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
77
78 ifneq ($(CONFIG_PACKAGE_$(1)),)
79 COMPILE_$(1):=1
80 endif
81 ifneq ($(DEVELOPER),)
82 COMPILE_$(1):=1
83 endif
84 ifeq ($(CONFIG_PACKAGE_$(1)),y)
85 install-targets: $$(INFO_$(1))
86 endif
87
88 ifneq ($$(COMPILE_$(1)),)
89 ifeq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $$(IPKG_$(1)) $(PKG_BUILD_DIR)),$(PKG_BUILD_DIR))
90 $(PKG_BUILD_DIR)/.built: package-recompile
91 endif
92
93 compile-targets: $$(IPKG_$(1))
94 endif
95
96
97 IDEPEND_$(1):=$$(strip $$(DEPENDS))
98
99 DUMPINFO += \
100 echo "Package: $(1)";
101 ifneq ($(MENU),)
102 DUMPINFO += \
103 echo "Menu: $(MENU)";
104 endif
105 ifneq ($(DEFAULT),)
106 DUMPINFO += \
107 echo "Default: $(DEFAULT)";
108 endif
109 DUMPINFO += \
110 echo "Version: $(VERSION)"; \
111 echo "Depends: $$(IDEPEND_$(1))"; \
112 echo "Category: $(CATEGORY)"; \
113 echo "Title: $(TITLE)"; \
114 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
115 ifneq ($(URL),)
116 DUMPINFO += \
117 echo; \
118 echo "$(URL)";
119 endif
120 DUMPINFO += \
121 echo "@@";
122
123
124 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
125 mkdir -p $$(IDIR_$(1))/CONTROL
126 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
127 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
128 echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
129 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
130 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
131 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
132 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
133 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
134 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
135 chmod 644 $$(IDIR_$(1))/CONTROL/control
136 for file in conffiles preinst postinst prerm postrm; do \
137 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
138 done
139
140 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
141 $(call Package/$(1)/install,$$(IDIR_$(1)))
142 mkdir -p $(PACKAGE_DIR)
143 $(RSTRIP) $$(IDIR_$(1))
144 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
145
146 $$(INFO_$(1)): $$(IPKG_$(1))
147 $(IPKG) install $$(IPKG_$(1))
148
149 $(1)-clean:
150 rm -f $(PACKAGE_DIR)/$(1)_*
151 clean: $(1)-clean
152
153 ifneq ($(__DEFAULT_TARGETS),1)
154 $(eval $(call Build/DefaultTargets))
155 endif
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 )
203 endef
204
205 define Build/Configure
206 $(call Build/Configure/Default,)
207 endef
208
209 define Build/Compile/Default
210 $(MAKE) -C $(PKG_BUILD_DIR) \
211 CC=$(TARGET_CC) \
212 CROSS="$(TARGET_CROSS)" \
213 PREFIX="$$(IDIR_$(1))" \
214 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
215 ARCH="$(ARCH)" \
216 DESTDIR="$$(IDIR_$(1))"
217 endef
218
219 define Build/Compile
220 $(call Build/Compile/Default)
221 endef
222
223 define Build/Clean
224 $(MAKE) clean
225 endef
226
227 ifneq ($(DUMP),)
228 dumpinfo:
229 $(DUMPINFO)
230 else
231
232 $(PACKAGE_DIR):
233 mkdir -p $@
234
235 source: FORCE $(DL_DIR)/$(PKG_SOURCE)
236 prepare: FORCE $(PKG_BUILD_DIR)/.prepared
237 configure: FORCE $(PKG_BUILD_DIR)/.configured
238
239 compile-targets: FORCE
240 compile: FORCE compile-targets
241
242 install-targets: FORCE
243 install: FORCE install-targets
244
245 clean-targets: FORCE
246 clean: FORCE
247 @$(MAKE) clean-targets
248 rm -rf $(PKG_BUILD_DIR)
249 endif
250
251 .PHONY: FORCE
252 FORCE: