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