fix InstallDev bug
[openwrt/staging/dedeckeh.git] / openwrt / 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 $(PKG_BUILD_DIR)/.dev-installed: $(PKG_BUILD_DIR)/.built
33 $(call Build/InstallDev)
34 touch $$@
35
36 ifdef Build/InstallDev
37 compile-targets: $(PKG_BUILD_DIR)/.dev-installed
38 endif
39
40 package-clean: FORCE
41 $(call Build/Clean)
42 $(call Build/UninstallDev)
43
44 package-rebuild: FORCE
45 @-rm $(PKG_BUILD_DIR)/.built
46
47 define Build/DefaultTargets
48 endef
49 endef
50
51 define Package/Default
52 CONFIGFILE:=
53 SECTION:=opt
54 CATEGORY:=Extra packages
55 DEPENDS:=
56 MAINTAINER:=OpenWrt Developers Team <openwrt-devel@openwrt.org>
57 SOURCE:=$(patsubst $(TOPDIR)/%,%,${shell pwd})
58 VERSION:=$(PKG_VERSION)-$(PKG_RELEASE)
59 PKGARCH:=$(ARCH)
60 PRIORITY:=optional
61 DEFAULT:=
62 MENU:=
63 TITLE:=
64 DESCRIPTION:=
65 endef
66
67 define BuildPackage
68 $(eval $(call Package/Default))
69 $(eval $(call Package/$(1)))
70
71 $(foreach FIELD, TITLE CATEGORY PRIORITY VERSION,
72 ifeq ($($(FIELD)),)
73 $$(error Package/$(1) is missing the $(FIELD) field)
74 endif
75 )
76
77 ifeq ($(PKGARCH),)
78 PKGARCH:=$(ARCH)
79 endif
80
81 ifeq ($(DESCRIPTION),)
82 $(eval DESCRIPTION:=$(TITLE))
83 endif
84
85 IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
86 IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg/$(1)
87 INFO_$(1):=$(IPKG_STATE_DIR)/info/$(1).list
88
89 ifeq ($(CONFIG_PACKAGE_$(1)),y)
90 install-targets: $$(INFO_$(1))
91 endif
92
93 ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
94 compile-targets: $$(IPKG_$(1))
95 endif
96
97 IDEPEND_$(1):=$$(strip $$(DEPENDS))
98
99 DUMPINFO += \
100 echo "Package: $(1)";
101
102 ifneq ($(MENU),)
103 DUMPINFO += \
104 echo "Menu: $(MENU)";
105 endif
106
107 ifneq ($(DEFAULT),)
108 DUMPINFO += \
109 echo "Default: $(DEFAULT)";
110 endif
111
112 DUMPINFO += \
113 echo "Version: $(VERSION)"; \
114 echo "Depends: $$(IDEPEND_$(1))"; \
115 echo "Build-Depends: $(PKG_BUILDDEP)"; \
116 echo "Category: $(CATEGORY)"; \
117 echo "Title: $(TITLE)"; \
118 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n,g';
119
120 ifneq ($(URL),)
121 DUMPINFO += \
122 echo; \
123 echo "$(URL)";
124 endif
125
126 DUMPINFO += \
127 echo "@@";
128
129 ifneq ($(CONFIG),)
130 DUMPINFO += \
131 echo "Config: $(CONFIG)" | sed -e 's,\\,\n,g'; \
132 echo "@@";
133 endif
134
135 $$(IDIR_$(1))/CONTROL/control: $(PKG_BUILD_DIR)/.prepared
136 mkdir -p $$(IDIR_$(1))/CONTROL
137 echo "Package: $(1)" > $$(IDIR_$(1))/CONTROL/control
138 echo "Version: $(VERSION)" >> $$(IDIR_$(1))/CONTROL/control
139 ( \
140 DEPENDS=; \
141 for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
142 DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
143 done; \
144 echo "Depends: $$$$DEPENDS" >> $$(IDIR_$(1))/CONTROL/control; \
145 )
146 echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
147 echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
148 echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
149 echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
150 echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
151 echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
152 chmod 644 $$(IDIR_$(1))/CONTROL/control
153 for file in conffiles preinst postinst prerm postrm; do \
154 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
155 done
156
157 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
158 $(call Package/$(1)/install,$$(IDIR_$(1)))
159 mkdir -p $(PACKAGE_DIR)
160 -find $$(IDIR_$(1)) -name CVS | xargs rm -rf
161 -find $$(IDIR_$(1)) -name .svn | xargs rm -rf
162 -find $$(IDIR_$(1)) -name '.#*' | xargs rm -f
163 $(RSTRIP) $$(IDIR_$(1))
164 $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
165
166 $$(INFO_$(1)): $$(IPKG_$(1))
167 $(IPKG) install $$(IPKG_$(1))
168
169 $(1)-clean:
170 rm -f $(PACKAGE_DIR)/$(1)_*
171
172 clean: $(1)-clean
173
174 $$(eval $$(call Build/DefaultTargets,$(1)))
175
176 endef
177
178 ifneq ($(strip $(PKG_SOURCE)),)
179 $(DL_DIR)/$(PKG_SOURCE):
180 $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
181 endif
182
183 ifneq ($(strip $(PKG_CAT)),)
184 define Build/Prepare/Default
185 @if [ "$(PKG_CAT)" = "unzip" ]; then \
186 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
187 else \
188 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
189 fi
190 @if [ -d ./patches ]; then \
191 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
192 fi
193 endef
194 endif
195
196 define Build/Prepare
197 $(call Build/Prepare/Default)
198 endef
199
200 define Build/Configure/Default
201 @(cd $(PKG_BUILD_DIR); \
202 [ -x configure ] && \
203 $(TARGET_CONFIGURE_OPTS) \
204 CFLAGS="$(TARGET_CFLAGS)" \
205 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
206 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
207 ./configure \
208 --target=$(GNU_TARGET_NAME) \
209 --host=$(GNU_TARGET_NAME) \
210 --build=$(GNU_HOST_NAME) \
211 --program-prefix="" \
212 --program-suffix="" \
213 --prefix=/usr \
214 --exec-prefix=/usr \
215 --bindir=/usr/bin \
216 --sbindir=/usr/sbin \
217 --libexecdir=/usr/lib \
218 --sysconfdir=/etc \
219 --datadir=/usr/share \
220 --localstatedir=/var \
221 --mandir=/usr/man \
222 --infodir=/usr/info \
223 $(DISABLE_NLS) \
224 $(1); \
225 true; \
226 )
227 endef
228
229 define Build/Configure
230 $(call Build/Configure/Default,)
231 endef
232
233 define Build/Compile/Default
234 $(MAKE) -C $(PKG_BUILD_DIR) \
235 CC=$(TARGET_CC) \
236 CROSS="$(TARGET_CROSS)" \
237 PREFIX="$$(IDIR_$(1))" \
238 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
239 ARCH="$(ARCH)" \
240 DESTDIR="$$(IDIR_$(1))" \
241 $(1);
242 endef
243
244 define Build/Compile
245 $(call Build/Compile/Default,)
246 endef
247
248 define Build/Clean
249 $(MAKE) clean
250 endef
251
252 ifneq ($(DUMP),)
253 dumpinfo: FORCE
254 @$(DUMPINFO)
255 else
256
257 $(PACKAGE_DIR):
258 mkdir -p $@
259
260 source: $(DL_DIR)/$(PKG_SOURCE)
261 prepare: $(PKG_BUILD_DIR)/.prepared
262 configure: $(PKG_BUILD_DIR)/.configured
263
264 compile-targets:
265 compile: compile-targets
266
267 install-targets:
268 install: install-targets
269
270 clean-targets:
271 clean: FORCE
272 @$(MAKE) clean-targets
273 rm -rf $(PKG_BUILD_DIR)
274 endif