aa7d800e82d25bbfc7595a17a09bca738780e22c
[packages.git] / libs / postgresql / Makefile
1
2 # Copyright (C) 2006-2009 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:=8.3.3
12 PKG_RELEASE:=2
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:=0ae4bd9620e84d3e08dcf923808d14d0
22
23 include $(INCLUDE_DIR)/package.mk
24
25 define Package/libpq
26   SECTION:=libs
27   CATEGORY:=Libraries
28   DEPENDS:=+zlib +libreadline +libncurses
29   TITLE:=PostgreSQL client library
30   URL:=http://www.postgresql.org/
31   SUBMENU:=database
32 endef
33
34 define Package/libpq/description
35 PostgreSQL client library.
36 endef
37
38 define Package/pgsql-cli
39   SECTION:=utils
40   CATEGORY:=Utilities
41   DEPENDS:=+libpq
42   TITLE:=Command Line Interface (CLI) to PostgreSQL databases
43   URL:=http://www.postgresql.org/
44   SUBMENU:=database
45 endef
46
47 define Package/pgsql-cli/description
48 Command Line Interface (CLI) to PostgreSQL databases.
49 endef
50
51 define Package/pgsql-server
52   SECTION:=utils
53   CATEGORY:=Utilities
54   DEPENDS:=+libpq
55   TITLE:=PostgreSQL databases Server
56   URL:=http://www.postgresql.org/
57   SUBMENU:=database
58 endef
59
60 define Package/pgsql-server/description
61 PostgreSQL databases Server.
62 endef
63
64 # Need a native ecpg ,pg_config, and zic for build
65 define Build/Configure
66         (cd $(PKG_BUILD_DIR); rm -f config.cache; \
67                 ./configure \
68                         --prefix=/usr \
69                         --exec-prefix=/usr \
70                         --bindir=/usr/bin \
71                         --datadir=/usr/share \
72                         --includedir=/usr/include \
73                         --infodir=/usr/share/info \
74                         --libdir=/usr/lib \
75                         --libexecdir=/usr/lib \
76                         --localstatedir=/var \
77                         --mandir=/usr/share/man \
78                         --sbindir=/usr/sbin \
79                         --sysconfdir=/etc \
80                         $(DISABLE_NLS) \
81                         $(DISABLE_LARGEFILE) \
82                         --enable-shared \
83                         --enable-static \
84                         --disable-integer-datetimes \
85                         --disable-rpath \
86                         --without-java \
87                         --without-krb4 \
88                         --without-krb5 \
89                         --without-openssl \
90                         --without-pam \
91                         --without-perl \
92                         --without-python \
93                         --without-readline \
94                         --without-rendezvous \
95                         --without-tcl \
96                         --without-tk \
97                         --with-zlib="yes" \
98                         --enable-depend \
99         );
100         $(MAKE) -C $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc CC="$(HOSTCC)" CFLAGS+="-I../../libpq"
101         mv $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg \
102                 $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg.host
103         $(MAKE) -C $(PKG_BUILD_DIR)/src/timezone CC="$(HOSTCC)"
104         mv $(PKG_BUILD_DIR)/src/timezone/zic $(PKG_BUILD_DIR)/src/timezone/zic.host
105         $(MAKE) -C $(PKG_BUILD_DIR)/src/bin/pg_config CC="$(HOSTCC)"
106         mv $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config \
107                 $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config.host
108         $(MAKE) -C $(PKG_BUILD_DIR) distclean
109
110         (cd $(PKG_BUILD_DIR); rm -f config.cache; \
111                 $(TARGET_CONFIGURE_OPTS) \
112                 CFLAGS="$(TARGET_CFLAGS)" \
113                 CPPFLAGS="$$$$CPPFLAGS $(TARGET_CPPFLAGS)" \
114                 LDFLAGS="$(TARGET_LDFLAGS)" \
115                 ./configure \
116                         --target=$(GNU_TARGET_NAME) \
117                         --host=$(GNU_TARGET_NAME) \
118                         --build=$(GNU_HOST_NAME) \
119                         --program-prefix="" \
120                         --program-suffix="" \
121                         --prefix=/usr \
122                         --exec-prefix=/usr \
123                         --bindir=/usr/bin \
124                         --datadir=/usr/share \
125                         --includedir=/usr/include \
126                         --infodir=/usr/share/info \
127                         --libdir=/usr/lib \
128                         --libexecdir=/usr/lib \
129                         --localstatedir=/var \
130                         --mandir=/usr/share/man \
131                         --sbindir=/usr/sbin \
132                         --sysconfdir=/etc \
133                         $(DISABLE_NLS) \
134                         $(DISABLE_LARGEFILE) \
135                         --enable-shared \
136                         --enable-static \
137                         --disable-integer-datetimes \
138                         --disable-rpath \
139                         --without-java \
140                         --without-krb4 \
141                         --without-krb5 \
142                         --without-openssl \
143                         --without-pam \
144                         --without-perl \
145                         --without-python \
146                         --without-rendezvous \
147                         --without-tcl \
148                         --without-tk \
149                         --with-zlib="yes" \
150                         --enable-depend \
151                         $(if $(CONFIG_TARGET_avr32),--disable-spinlocks) \
152         );
153         $(SED) 's@ECPG = ../../preproc/ecpg@ECPG = ../../preproc/ecpg.host@' $(PKG_BUILD_DIR)/src/interfaces/ecpg/test/Makefile.regress
154         $(SED) 's@\./zic -d@./zic.host -d@' $(PKG_BUILD_DIR)/src/timezone/Makefile
155         # note: unclear if this is needed yet, commenting out for the moment
156         #$(SED) 's@US/Eastern@America/New_York@' $(PKG_BUILD_DIR)/src/timezone/Makefile
157 endef
158
159 TARGET_CFLAGS += $(FPIC)
160
161 define Build/Compile
162         $(MAKE) -C "$(PKG_BUILD_DIR)" \
163                 DESTDIR="$(PKG_INSTALL_DIR)" \
164                 all install
165 endef
166
167 define Package/libpq/install
168         $(INSTALL_DIR) $(1)/usr/lib
169         $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpq.so.* $(1)/usr/lib/
170 endef
171
172 define Package/pgsql-cli/install
173         $(INSTALL_DIR) $(1)/usr/bin
174         $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/psql $(1)/usr/bin/
175 endef
176
177 define Package/pgsql-server/install
178         $(INSTALL_DIR) $(1)/usr/bin
179         $(INSTALL_DIR) $(1)/usr/share/postgresql
180         $(INSTALL_DIR) $(1)/usr/lib
181         $(INSTALL_DIR) $(1)/etc/init.d
182         $(INSTALL_DIR) $(1)/etc/config
183         $(INSTALL_BIN) \
184                 $(PKG_INSTALL_DIR)/usr/bin/postgres \
185                 $(PKG_INSTALL_DIR)/usr/bin/dropdb \
186                 $(PKG_INSTALL_DIR)/usr/bin/clusterdb \
187                 $(PKG_INSTALL_DIR)/usr/bin/createdb \
188                 $(PKG_INSTALL_DIR)/usr/bin/createlang \
189                 $(PKG_INSTALL_DIR)/usr/bin/createuser \
190                 $(PKG_INSTALL_DIR)/usr/bin/droplang \
191                 $(PKG_INSTALL_DIR)/usr/bin/dropuser \
192                 $(PKG_INSTALL_DIR)/usr/bin/initdb \
193                 $(PKG_INSTALL_DIR)/usr/bin/ipcclean \
194                 $(PKG_INSTALL_DIR)/usr/bin/pg_config \
195                 $(PKG_INSTALL_DIR)/usr/bin/pg_controldata \
196                 $(PKG_INSTALL_DIR)/usr/bin/pg_ctl \
197                 $(PKG_INSTALL_DIR)/usr/bin/pg_dump \
198                 $(PKG_INSTALL_DIR)/usr/bin/pg_dumpall \
199                 $(PKG_INSTALL_DIR)/usr/bin/pg_restore \
200                 $(PKG_INSTALL_DIR)/usr/bin/pg_resetxlog \
201                 $(PKG_INSTALL_DIR)/usr/bin/reindexdb \
202                 $(PKG_INSTALL_DIR)/usr/bin/vacuumdb \
203                 $(1)/usr/bin
204         ln -sf postgres $(1)/usr/bin/postmaster
205
206         $(INSTALL_BIN) ./files/postgresql.init $(1)/etc/init.d/postgresql
207
208         $(INSTALL_DATA) \
209                 $(PKG_INSTALL_DIR)/usr/share/postgresql/postgres.bki \
210                 $(PKG_INSTALL_DIR)/usr/share/postgresql/postgres.description \
211                 $(PKG_INSTALL_DIR)/usr/share/postgresql/conversion_create.sql \
212                 $(PKG_INSTALL_DIR)/usr/share/postgresql/information_schema.sql \
213                 $(PKG_INSTALL_DIR)/usr/share/postgresql/pg_hba.conf.sample \
214                 $(PKG_INSTALL_DIR)/usr/share/postgresql/pg_ident.conf.sample \
215                 $(PKG_INSTALL_DIR)/usr/share/postgresql/pg_service.conf.sample \
216                 $(PKG_INSTALL_DIR)/usr/share/postgresql/postgresql.conf.sample \
217                 $(PKG_INSTALL_DIR)/usr/share/postgresql/sql_features.txt \
218                 $(PKG_INSTALL_DIR)/usr/share/postgresql/postgres.shdescription \
219                 $(PKG_INSTALL_DIR)/usr/share/postgresql/psqlrc.sample \
220                 $(PKG_INSTALL_DIR)/usr/share/postgresql/recovery.conf.sample \
221                 $(PKG_INSTALL_DIR)/usr/share/postgresql/system_views.sql \
222                 $(PKG_INSTALL_DIR)/usr/share/postgresql/snowball_create.sql \
223                 $(1)/usr/share/postgresql
224
225                 $(INSTALL_DATA) ./files/postgresql.config $(1)/etc/config/postgresql
226
227                 $(CP) -r \
228                         $(PKG_INSTALL_DIR)/usr/share/postgresql/timezone \
229                         $(PKG_INSTALL_DIR)/usr/share/postgresql/timezonesets \
230                         $(1)/usr/share/postgresql
231
232                 $(CP) -r \
233                         $(PKG_INSTALL_DIR)/usr/lib/postgresql \
234                         $(1)/usr/lib
235 endef
236
237 define Package/pgsql-server/postinst
238 #!/bin/sh
239 grep -q '^postgres:' /etc/passwd && exit 0
240
241 if [ -e /bin/addgroup ]; then
242   /bin/addgroup postgres
243   RG=$$?
244
245   if [ -e /bin/adduser ]; then
246     /bin/adduser -h /tmp -H -g 'PostgreSQL administrator' -s /bin/ash -D -H -G postgres postgres
247         RU=$$?
248   fi
249 fi
250
251 if [ -z "$${RG}" -o -z "$${RU}" ]; then
252   echo "Could not find user utils, you will need to create the postgres user by hand"
253   exit 
254 fi
255
256 if [ "$${RG}" != "0" -o "$${RU}" != "0" ]; then
257   echo "Failed to created postgres user"
258   exit 1
259 fi
260 endef
261
262 define Build/InstallDev
263         mkdir -p $(1)/usr/bin
264         $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/bin/pg_config/pg_config.host $(1)/usr/bin/pg_config
265         mkdir -p $(1)/usr/include
266         $(CP) $(PKG_INSTALL_DIR)/usr/include/libpq $(1)/usr/include/
267         $(CP) $(PKG_INSTALL_DIR)/usr/include/libpq-fe.h $(1)/usr/include/
268         $(CP) $(PKG_INSTALL_DIR)/usr/include/pg_config.h $(1)/usr/include/
269         $(CP) $(PKG_INSTALL_DIR)/usr/include/postgres_ext.h $(1)/usr/include/
270         $(CP) $(PKG_INSTALL_DIR)/usr/include/postgresql $(1)/usr/include/
271         mkdir -p $(1)/usr/lib
272         $(CP) $(PKG_INSTALL_DIR)/usr/lib/libpq.{a,so*} $(1)/usr/lib/
273         $(CP) $(PKG_BUILD_DIR)/src/interfaces/ecpg/preproc/ecpg.host $(1)/usr/bin/ecpg
274         $(CP) $(PKG_BUILD_DIR)/src/timezone/zic.host $(1)/usr/bin/zic
275 endef
276
277 $(eval $(call BuildPackage,libpq))
278 $(eval $(call BuildPackage,pgsql-cli))
279 $(eval $(call BuildPackage,pgsql-server))