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