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