add proper build depends
[oweals/openwrt.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   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         echo "Depends: $$(IDEPEND_$(1))" >> $$(IDIR_$(1))/CONTROL/control
136         echo "Source: $(SOURCE)" >> $$(IDIR_$(1))/CONTROL/control
137         echo "Section: $(SECTION)" >> $$(IDIR_$(1))/CONTROL/control
138         echo "Priority: $(PRIORITY)" >> $$(IDIR_$(1))/CONTROL/control
139         echo "Maintainer: $(MAINTAINER)" >> $$(IDIR_$(1))/CONTROL/control
140         echo "Architecture: $(PKGARCH)" >> $$(IDIR_$(1))/CONTROL/control
141         echo "Description: $(DESCRIPTION)" | sed -e 's,\\,\n ,g' >> $$(IDIR_$(1))/CONTROL/control
142         chmod 644 $$(IDIR_$(1))/CONTROL/control
143         for file in conffiles preinst postinst prerm postrm; do \
144                 [ -f ./ipkg/$(1).$$$$file ] && cp ./ipkg/$(1).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file || true; \
145         done
146
147   $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $(PKG_BUILD_DIR)/.built
148         $(call Package/$(1)/install,$$(IDIR_$(1)))
149         mkdir -p $(PACKAGE_DIR)
150         $(RSTRIP) $$(IDIR_$(1))
151         $(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
152
153   $$(INFO_$(1)): $$(IPKG_$(1))
154         $(IPKG) install $$(IPKG_$(1))
155
156   $(1)-clean:
157         rm -f $(PACKAGE_DIR)/$(1)_*
158
159   clean: $(1)-clean
160
161   $$(eval $$(call Build/DefaultTargets,$(1)))
162
163 endef
164
165 ifneq ($(strip $(PKG_SOURCE)),)
166   $(DL_DIR)/$(PKG_SOURCE):
167         $(SCRIPT_DIR)/download.pl "$(DL_DIR)" "$(PKG_SOURCE)" "$(PKG_MD5SUM)" $(PKG_SOURCE_URL)
168 endif
169
170 ifneq ($(strip $(PKG_CAT)),)
171   define Build/Prepare/Default
172         @if [ "$(PKG_CAT)" = "unzip" ]; then \
173                 unzip -d $(PKG_BUILD_DIR) $(DL_DIR)/$(PKG_SOURCE) ; \
174         else \
175                 $(PKG_CAT) $(DL_DIR)/$(PKG_SOURCE) | tar -C $(PKG_BUILD_DIR)/.. $(TAR_OPTIONS) - ; \
176         fi                                                
177         @if [ -d ./patches ]; then \
178                 $(PATCH) $(PKG_BUILD_DIR) ./patches ; \
179         fi
180   endef
181 endif
182
183 define Build/Prepare
184   $(call Build/Prepare/Default)
185 endef
186
187 define Build/Configure/Default
188         @(cd $(PKG_BUILD_DIR); \
189         [ -x configure ] && \
190                 $(TARGET_CONFIGURE_OPTS) \
191                 CFLAGS="$(TARGET_CFLAGS)" \
192                 CPPFLAGS="-I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
193                 LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
194                 ./configure \
195                 --target=$(GNU_TARGET_NAME) \
196                 --host=$(GNU_TARGET_NAME) \
197                 --build=$(GNU_HOST_NAME) \
198                 --program-prefix="" \
199                 --program-suffix="" \
200                 --prefix=/usr \
201                 --exec-prefix=/usr \
202                 --bindir=/usr/bin \
203                 --sbindir=/usr/sbin \
204                 --libexecdir=/usr/lib \
205                 --sysconfdir=/etc \
206                 --datadir=/usr/share \
207                 --localstatedir=/var \
208                 --mandir=/usr/man \
209                 --infodir=/usr/info \
210                 $(DISABLE_NLS) \
211                 $(1); \
212                 true; \
213         )
214 endef
215
216 define Build/Configure
217   $(call Build/Configure/Default,)
218 endef
219
220 define Build/Compile/Default
221         $(MAKE) -C $(PKG_BUILD_DIR) \
222                 CC=$(TARGET_CC) \
223                 CROSS="$(TARGET_CROSS)" \
224                 PREFIX="$$(IDIR_$(1))" \
225                 EXTRA_CFLAGS="$(TARGET_CFLAGS)" \
226                 ARCH="$(ARCH)" \
227                 DESTDIR="$$(IDIR_$(1))" \
228                 $(1);
229 endef
230
231 define Build/Compile
232   $(call Build/Compile/Default,)
233 endef
234
235 define Build/InstallDev
236 endef
237
238 define Build/Clean
239         $(MAKE) clean
240 endef
241
242 define Build/UninstallDev
243 endef
244
245 ifneq ($(DUMP),)
246   dumpinfo: FORCE
247         @$(DUMPINFO)
248 else
249                 
250   $(PACKAGE_DIR):
251         mkdir -p $@
252
253   source: $(DL_DIR)/$(PKG_SOURCE)
254   prepare: $(PKG_BUILD_DIR)/.prepared
255   configure: $(PKG_BUILD_DIR)/.configured
256
257   compile-targets: $(PKG_BUILD_DIR)/.dev-installed
258   compile: compile-targets
259
260   install-targets:
261   install: install-targets
262
263   clean-targets:
264   clean: FORCE
265         @$(MAKE) clean-targets
266         rm -rf $(PKG_BUILD_DIR)
267 endif