revert some previous changes and add another bugfix
[openwrt.git] / package / rules.mk
1 # default target
2 ifneq ($(DUMP),)
3 all: dumpinfo
4 else
5 all: compile
6 endif
7
8 define Build/DefaultTargets
9 $(PKG_BUILD_DIR)/.prepared:
10 rm -rf $(PKG_BUILD_DIR)
11 mkdir -p $(PKG_BUILD_DIR)
12 $(call Build/Prepare)
13 touch $$@
14
15 $(PKG_BUILD_DIR)/.configured:
16 $(call Build/Configure)
17 touch $$@
18
19 $(PKG_BUILD_DIR)/.built:
20 $(call Build/Compile)
21 touch $$@
22
23 define Build/DefaultTargets
24 endef
25 endef
26
27
28 define Package/Default
29 CONFIGFILE:=
30 SECTION:=opt
31 CATEGORY:=Extra packages
32 DEPENDS:=
33 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
34 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
35 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
36 PKGARCH:=$(ARCH)
37 PRIORITY:=optional
38 TITLE:=
39 DESCRIPTION:=
40 endef
41
42 define BuildPackage
43 $(eval $(call Package/Default))
44 $(eval $(call Package/$(1)))
45
46 ifeq ($$(TITLE),)
47 $$(error Package $(1) has no TITLE)
48 endif
49 ifeq ($$(CATEGORY),)
50 $$(error Package $(1) has no CATEGORY)
51 endif
52 ifeq ($$(PRIORITY),)
53 $$(error Package $(1) has no PRIORITY)
54 endif
55 ifeq ($$(VERSION),)
56 $$(error Package $(1) has no VERSION)
57 endif
58 ifeq ($$(PKGARCH),)
59 PKGARCH:=$(ARCH)
60 endif
61
62 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
63 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
64 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
65
66 ifneq ($(PACKAGE_$(1)),)
67 compile-targets: $$(IPKG_$(1))
68 endif
69 ifneq ($(DEVELOPER),)
70 compile-targets: $$(IPKG_$(1))
71 endif
72 ifeq ($(PACKAGE_$(1)),y)
73 install-targets: $$(INFO_$(1))
74 endif
75
76 IDEPEND_$(1):=$$(strip $$(DEPENDS))
77
78 DUMPINFO += \
79 echo "Package: $(1)"; \
80 echo "Version: $(VERSION)"; \
81 echo "Depends: $(IDEPEND_$(1))"; \
82 echo "Title: $(TITLE)"; \
83 echo "$(DESCRIPTION)" | sed -e 's,\\,\n,g'; \
84 echo; \
85 echo "$(URL)"; \
86 echo "@@";
87
88
89 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
90 mkdir -p $$(IDIR_$(1))/CONTROL
91 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
92 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
93 echo "Depends: $(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
94 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
95 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
96 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
97 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
98 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
99 echo "Description: $(TITLE)" >> $$(IDIR_$(1))/CONTROL/control
100 echo "$(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
101 chmod 644 $$(IDIR_$(1))/CONTROL/control
102 for file in conffiles preinst postinst prerm postrm; do \
103 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
104 done
105
106 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built $(PACKAGE_DIR)
107 $(call Package/$(1)/install,$$(IDIR_$(1)))
108 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
109
110 $$(INFO_$(1)): $$(IPKG_$(1))
111 $(IPKG) install $$(IPKG_$(1))
112
113 $(1)-clean:
114 rm -f $$(IPKG_$(1))
115 clean: $(1)-clean
116
117 PACKAGES += $(1)
118
119 ifneq ($(__DEFAULT_TARGETS),1)
120 $(eval $(call Build/DefaultTargets))
121 endif
122
123 endef
124
125 ifneq ($(strip $(PKG_SOURCE)),)
126 $(DL_DIR)/$(PKG_SOURCE):
127 @$(CMD_TRACE) "downloading... "
128 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL) $(MAKE_TRACE)
129
130 $(PKG_BUILD_DIR)/.prepared: $(DL_DIR)/$(PKG_SOURCE)
131 endif
132
133 ifneq ($(strip $(PKG_CAT)),)
134 define Build/Prepare/Default
135 if [ "$(PKG_CAT)" = "unzip" ]; then \
136 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
137 else \
138 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
139 fi
140 if [ -d ./patches ]; then \
141 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
142 fi
143 endef
144 endif
145
146 define Build/Prepare
147 $(call Build/Prepare/Default)
148 endef
149
150 define Build/Configure/Default
151 # TODO: add configurable default command
152 endef
153
154 define Build/Configure
155 $(call Build/Configure/Default)
156 endef
157
158 define Build/Compile/Default
159 # TODO: add configurable default command
160 endef
161
162 define Build/Compile
163 $(call Build/Compile/Default)
164 endef
165
166 ifneq ($(DUMP),)
167 dumpinfo:
168 $(DUMPINFO)
169 else
170
171 source: $(DL_DIR)/$(PKG_SOURCE)
172 prepare: source
173 @[ -f $(PKG_BUILD_DIR)/.prepared ] || { \
174 $(CMD_TRACE) "preparing... "; \
175 $(MAKE) $(PKG_BUILD_DIR)/.prepared $(MAKE_TRACE); \
176 }
177
178 configure: prepare
179 @[ -f $(PKG_BUILD_DIR)/.configured ] || { \
180 $(CMD_TRACE) "configuring... "; \
181 $(MAKE) $(PKG_BUILD_DIR)/.configured $(MAKE_TRACE); \
182 }
183
184 compile-targets:
185 compile: configure
186 @$(CMD_TRACE) "compiling... "
187 @$(MAKE) compile-targets $(MAKE_TRACE)
188
189 install-targets:
190 install:
191 @$(CMD_TRACE) "installing... "
192 @$(MAKE) install-targets $(MAKE_TRACE)
193
194 mostlyclean:
195 rebuild:
196 $(CMD_TRACE) "rebuilding... "
197 @-$(MAKE) mostlyclean 2>&1 >/dev/null
198 if [ -f $(PKG_BUILD_DIR)/.built ]; then \
199 $(MAKE) clean $(MAKE_TRACE); \
200 fi
201 $(MAKE) compile $(MAKE_TRACE)
202
203 $(PACKAGE_DIR):
204 mkdir -p $@
205
206 clean-targets:
207 clean:
208 @$(CMD_TRACE) "cleaning... "
209 @$(MAKE) clean-targets $(MAKE_TRACE)
210 rm -rf $(PKG_BUILD_DIR)
211 endif
212
213 .PHONY: all source prepare compile install clean dumpinfo
This page took 0.062313 seconds and 5 git commands to generate.