work around a make bug in define/endef handling
[openwrt.git] / 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 TITLE:=
50 DESCRIPTION:=
51 endef
52
53 define BuildPackage
54 $(eval $(call Package/Default))
55 $(eval $(call Package/$(1)))
56
57 ifeq ($$(TITLE),)
58 $$(error Package $(1) has no TITLE)
59 endif
60 ifeq ($$(CATEGORY),)
61 $$(error Package $(1) has no CATEGORY)
62 endif
63 ifeq ($$(PRIORITY),)
64 $$(error Package $(1) has no PRIORITY)
65 endif
66 ifeq ($$(VERSION),)
67 $$(error Package $(1) has no VERSION)
68 endif
69 ifeq ($$(PKGARCH),)
70 PKGARCH:=$(ARCH)
71 endif
72
73 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
74 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
75 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
76
77 ifneq ($(PACKAGE_$(1)),)
78 COMPILE_$(1):=1
79 endif
80 ifneq ($(DEVELOPER),)
81 COMPILE_$(1):=1
82 endif
83 ifeq ($(PACKAGE_$(1)),y)
84 install-targets: $$(INFO_$(1))
85 endif
86
87 ifneq ($$(COMPILE_$(1)),)
88 ifeq ($$(shell $(SCRIPT_DIR)/timestamp.pl -p -x ipkg $$(IPKG_$(1)) $(PKG_BUILD_DIR)),$(PKG_BUILD_DIR))
89 $(PKG_BUILD_DIR)/.built: package-recompile
90 endif
91
92 compile-targets: $$(IPKG_$(1))
93 endif
94
95
96 IDEPEND_$(1):=$$(strip $$(DEPENDS))
97
98 DUMPINFO += \
99 echo "Package: $(1)"; \
100 echo "Version: $(VERSION)"; \
101 echo "Depends: $(IDEPEND_$(1))"; \
102 echo "Title: $(TITLE)"; \
103 echo "$(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
104 echo; \
105 echo "$(URL)"; \
106 echo "@@";
107
108
109 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
110 mkdir -p $$(IDIR_$(1))/CONTROL
111 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
112 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
113 echo "Depends: $(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
114 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
115 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
116 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
117 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
118 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
119 echo "Description: $(TITLE)" >> $$(IDIR_$(1))/CONTROL/control
120 echo " $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
121 chmod 644 $$(IDIR_$(1))/CONTROL/control
122 for file in conffiles preinst postinst prerm postrm; do \
123 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
124 done
125
126 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
127 $(call Package/$(1)/install,$$(IDIR_$(1)))
128 mkdir -p $(PACKAGE_DIR)
129 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
130
131 $$(INFO_$(1)): $$(IPKG_$(1))
132 $(IPKG) install $$(IPKG_$(1))
133
134 $(1)-clean:
135 rm -f $(PACKAGE_DIR)/$(1)_*
136 clean: $(1)-clean
137
138 ifneq ($(__DEFAULT_TARGETS),1)
139 $(eval $(call Build/DefaultTargets))
140 endif
141
142 endef
143
144 ifneq ($(strip $(PKG_SOURCE)),)
145 $(DL_DIR)/$(PKG_SOURCE):
146 @$(CMD_TRACE) "downloading... "
147 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) $(MAKE_TRACE)
148
149 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
150 endif
151
152 ifneq ($(strip $(PKG_CAT)),)
153 define Build/Prepare/Default
154 if [ "$(PKG_CAT)" = "unzip" ]; then \
155 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
156 else \
157 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
158 fi
159 if [ -d ./patches ]; then \
160 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
161 fi
162 endef
163 endif
164
165 define Build/Prepare
166 $(call Build/Prepare/Default)
167 endef
168
169 define Build/Configure/Default
170 # TODO: add configurable default command
171 endef
172
173 define Build/Configure
174 $(call Build/Configure/Default)
175 endef
176
177 define Build/Compile/Default
178 # TODO: add configurable default command
179 endef
180
181 define Build/Compile
182 $(call Build/Compile/Default)
183 endef
184
185 define Build/Clean
186 $(MAKE) clean
187 endef
188
189 ifneq ($(DUMP),)
190 dumpinfo:
191 $(DUMPINFO)
192 else
193
194 source: $(DL_DIR)/$(PKG_SOURCE)
195 prepare: source
196 @[ -f $(PKG_BUILD_DIR)/.prepared ] || { \
197 $(CMD_TRACE) "preparing... "; \
198 $(MAKE) $(PKG_BUILD_DIR)/.prepared $(MAKE_TRACE); \
199 }
200
201 configure: prepare
202 @[ -f $(PKG_BUILD_DIR)/.configured ] || { \
203 $(CMD_TRACE) "configuring... "; \
204 $(MAKE) $(PKG_BUILD_DIR)/.configured $(MAKE_TRACE); \
205 }
206
207 compile-targets:
208 compile: configure
209 @$(CMD_TRACE) "compiling... "
210 @$(MAKE) compile-targets $(MAKE_TRACE)
211
212 install-targets:
213 install:
214 @$(CMD_TRACE) "installing... "
215 @$(MAKE) install-targets $(MAKE_TRACE)
216
217 rebuild:
218 $(CMD_TRACE) "rebuilding... "
219 $(MAKE) package-clean compile $(MAKE_TRACE)
220
221 $(PACKAGE_DIR):
222 mkdir -p $@
223
224 clean-targets:
225 clean:
226 @$(CMD_TRACE) "cleaning... "
227 @$(MAKE) clean-targets $(MAKE_TRACE)
228 rm -rf $(PKG_BUILD_DIR)
229 endif
230
231 .PHONY: all source prepare compile install clean rebuild dumpinfo compile-targets install-targets clean-targets
This page took 0.058723 seconds and 5 git commands to generate.