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