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