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