postgresql: deptest fixes. staging dir is not preserved. Put host-zic into the build...
[packages.git] / libs / postgresql / Makefile
1 #
2 # Copyright (C) 2006-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 include $(TOPDIR)/rules.mk
9
10 PKG_NAME:=postgresql
11 PKG_VERSION:=9.0.0
12 PKG_RELEASE:=1
13
14 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
15 PKG_SOURCE_URL:=\
16         http://ftp7.us.postgresql.org/pub/postgresql/source/v$(PKG_VERSION) \
17         http://ftp8.us.postgresql.org/pub/postgresql/source/v$(PKG_VERSION) \
18         http://ftp9.us.postgresql.org/pub/postgresql/source/v$(PKG_VERSION) \
19         http://ftp.be.postgresql.org/postgresql/source/v$(PKG_VERSION) \
20         ftp://ftp-archives.postgresql.org/pub/source/v$(PKG_VERSION)
21 PKG_MD5SUM:=14c2122cc322e69ab2ab702ed7714bbe
22 PKG_BUILD_PARALLEL:=1
23
24 include $(INCLUDE_DIR)/package.mk
25
26 define Package/libpq
27   SECTION:=libs
28   CATEGORY:=Libraries
29   DEPENDS:=+zlib +libreadline +libncurses +coreutils-su
30   TITLE:=PostgreSQL client library
31   URL:=http://www.postgresql.org/
32   SUBMENU:=database
33 endef
34
35 define Package/libpq/description
36 PostgreSQL client library.
37 endef
38
39 define Package/pgsql-cli
40   SECTION:=utils
41   CATEGORY:=Utilities
42   DEPENDS:=+libpq
43   TITLE:=Command Line Interface (CLI) to PostgreSQL databases
44   URL:=http://www.postgresql.org/
45   SUBMENU:=database
46 endef
47
48 define Package/pgsql-cli/description
49 Command Line Interface (CLI) to PostgreSQL databases.
50 endef
51
52 define Package/pgsql-server
53   SECTION:=utils
54   CATEGORY:=Utilities
55   DEPENDS:=+libpq
56   TITLE:=PostgreSQL databases Server
57   URL:=http://www.postgresql.org/
58   SUBMENU:=database
59 endef
60
61 define Package/pgsql-server/description
62 PostgreSQL databases Server.
63 endef
64
65 # Need a native ecpg ,pg_config, and zic for build
66 define Build/Configure
67         (cd $(PKG_BUILD_DIR); rm -f config.cache; \
68                 ./configure \
69                         --prefix=/usr \
70                         --exec-prefix=/usr \
71                         --bindir=/usr/bin \
72                         --datadir=/usr/share \
73                         --includedir=/usr/include \
74                         --infodir=/usr/share/info \
75                         --libdir=/usr/lib \
76                         --libexecdir=/usr/lib \
77                         --localstatedir=/var \
78                         --mandir=/usr/share/man \
79                         --sbindir=/usr/sbin \
80                         --sysconfdir=/etc \
81                         $(DISABLE_NLS) \
82                         $(DISABLE_LARGEFILE) \
83                         --enable-shared \
84                         --enable-static \
85                         --disable-integer-datetimes \
86                         --disable-rpath \
87                         --without-java \
88                         --without-krb4 \
89                         --without-krb5 \
90                         --without-openssl \
91                         --without-pam \
92                         --without-perl \
93                         --without-python \
94                         --without-readline \
95                         --without-rendezvous \
96                         --without-tcl \
97                         --without-tk \
98                         --with-zlib="yes" \
99                         --enable-depend \
100                         --with-system-timezone=/tmp \
101         );
102         $(MAKE) -C $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc CC="$(HOSTCC)" CFLAGS+="-I../../libpq"
103         mv $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg \
104                 $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg.host
105         $(MAKE) -C $(PKG_BUILD_DIR)/src/timezone CC="$(HOSTCC)"
106         mv $(PKG_BUILD_DIR)/src/timezone/zic $(PKG_BUILD_DIR)/host-zic
107         $(INSTALL_DIR) $(STAGING_DIR)/host/bin/
108         $(CP) $(PKG_BUILD_DIR)/host-zic $(STAGING_DIR)/host/bin/zic
109         $(MAKE) -C $(PKG_BUILD_DIR)/src/bin/pg_config CC="$(HOSTCC)"
110         mv $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config \
111                 $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config.host
112         $(MAKE) -C $(PKG_BUILD_DIR) distclean
113
114         (cd $(PKG_BUILD_DIR); rm -f config.cache; \
115                 $(TARGET_CONFIGURE_OPTS) \
116                 CFLAGS="$(TARGET_CFLAGS)" \
117                 CPPFLAGS="$$$$CPPFLAGS $(TARGET_CPPFLAGS)" \
118                 LDFLAGS="$(TARGET_LDFLAGS)" \
119                 ./configure \
120                         --target=$(GNU_TARGET_NAME) \
121                         --host=$(GNU_TARGET_NAME) \
122                         --build=$(GNU_HOST_NAME) \
123                         --program-prefix="" \
124                         --program-suffix="" \
125                         --prefix=/usr \
126                         --exec-prefix=/usr \
127                         --bindir=/usr/bin \
128                         --datadir=/usr/share \
129                         --includedir=/usr/include \
130                         --infodir=/usr/share/info \
131                         --libdir=/usr/lib \
132                         --libexecdir=/usr/lib \
133                         --localstatedir=/var \
134                         --mandir=/usr/share/man \
135                         --sbindir=/usr/sbin \
136                         --sysconfdir=/etc \
137                         $(DISABLE_NLS) \
138                         $(DISABLE_LARGEFILE) \
139                         --enable-shared \
140                         --enable-static \
141                         --disable-integer-datetimes \
142                         --disable-rpath \
143                         --without-java \
144                         --without-krb4 \
145                         --without-krb5 \
146                         --without-openssl \
147                         --without-pam \
148                         --without-perl \
149                         --without-python \
150                         --without-rendezvous \
151                         --without-tcl \
152                         --without-tk \
153                         --with-zlib="yes" \
154                         --enable-depend \
155                         $(if $(CONFIG_TARGET_avr32),--disable-spinlocks) \
156         );
157         $(SED) 's@ECPG = ../../preproc/ecpg@ECPG = ../../preproc/ecpg.host@' $(PKG_BUILD_DIR)/src/interfaces/ecpg/test/Makefile.regress
158 endef
159
160 TARGET_CFLAGS += $(FPIC)
161
162 define Build/Compile
163         $(MAKE) $(PKG_JOBS) -C "$(PKG_BUILD_DIR)" \
164                 DESTDIR="$(PKG_INSTALL_DIR)" \
165                 all
166         $(MAKE) $(PKG_JOBS) -C "$(PKG_BUILD_DIR)" \
167                 DESTDIR="$(PKG_INSTALL_DIR)" \
168                 install
169 endef
170
171 define Package/libpq/install
172         $(INSTALL_DIR) $(1)/usr/lib
173         $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpq.so.* $(1)/usr/lib/
174 endef
175
176 define Package/pgsql-cli/install
177         $(INSTALL_DIR) $(1)/usr/bin
178         $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/psql $(1)/usr/bin/
179 endef
180
181 define Package/pgsql-server/install
182         $(INSTALL_DIR) $(1)/usr/bin
183         $(INSTALL_DIR) $(1)/usr/share/postgresql
184         $(INSTALL_DIR) $(1)/usr/lib
185         $(INSTALL_DIR) $(1)/etc/init.d
186         $(INSTALL_DIR) $(1)/etc/config
187         $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin
188         ln -sf postgres $(1)/usr/bin/postmaster
189
190         $(INSTALL_BIN) ./files/postgresql.init $(1)/etc/init.d/postgresql
191
192         $(CP) -r $(PKG_INSTALL_DIR)/usr/share/postgresql/* \
193                 $(1)/usr/share/postgresql
194
195         $(INSTALL_DATA) ./files/postgresql.config $(1)/etc/config/postgresql
196
197         $(CP) -r \
198                 $(PKG_INSTALL_DIR)/usr/lib/postgresql \
199                 $(1)/usr/lib
200 endef
201
202 define Package/pgsql-server/postinst
203 #!/bin/sh
204 grep -q '^postgres:' /etc/passwd && exit 0
205 group=$$(grep '^postgres:' /etc/group | cut -f3 -d:)
206 if [ -z "$${group}" ] ; then
207         group=1000
208         tst=$$(cat /etc/group | grep ":$${group}:")
209         while [ -n "$${tst}" ] ; do
210                 group=$$(($${group}+1))
211                 tst=$$(cat /etc/group | grep ":$${group}:")
212         done
213         echo "postgres:x:$${group}:" >>/etc/group
214 fi
215
216 user=$$(cat /etc/passwd | grep "^postgres:")
217 if [ -z "$${user}" ] ; then
218         num="$${group}"
219         tst=$$(cat /etc/passwd | grep ":.*:$${num}:")
220         while [ -n "$${tst}" ] ; do
221                 num=$$(($${num}+1))
222                 tst=$$(cat /etc/passwd | grep ":.*:$${num}:")
223         done
224         echo "postgres:*:$${num}:$${group}:PostgreSQL administrator:/tmp:/bin/ash" >>/etc/passwd
225 fi
226 endef
227
228 define Build/InstallDev
229         $(INSTALL_DIR) $(1)/usr/bin
230         $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config.host $(1)/usr/bin/pg_config
231         $(INSTALL_DIR) $(1)/usr/include
232         $(CP) $(PKG_INSTALL_DIR)/usr/include/libpq $(1)/usr/include/
233         $(CP) $(PKG_INSTALL_DIR)/usr/include/libpq-fe.h $(1)/usr/include/
234         $(CP) $(PKG_INSTALL_DIR)/usr/include/pg_config.h $(1)/usr/include/
235         $(CP) $(PKG_INSTALL_DIR)/usr/include/pg_config_manual.h $(1)/usr/include/
236         $(CP) $(PKG_INSTALL_DIR)/usr/include/postgres_ext.h $(1)/usr/include/
237         $(CP) $(PKG_INSTALL_DIR)/usr/include/postgresql $(1)/usr/include/
238         $(INSTALL_DIR) $(1)/usr/lib
239         $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpq.{a,so*} $(1)/usr/lib/
240         $(CP) $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg.host $(1)/usr/bin/ecpg
241         $(CP) $(PKG_BUILD_DIR)/host-zic $(1)/usr/bin/zic
242 endef
243
244 $(eval $(call BuildPackage,libpq))
245 $(eval $(call BuildPackage,pgsql-cli))
246 $(eval $(call BuildPackage,pgsql-server))