##################### GENERAL ##################### 
GARNAME = postgresql
GARVERSION = 11.3
GARELEASE = 4
HOME_URL = http://postgresql.org
CATEGORIES = app/database
MASTER_SITES += https://ftp.postgresql.org/pub/source/v$(GARVERSION)/
DISTFILES = postgresql-$(GARVERSION).tar.bz2
PATCHFILES = postmaster-s6-notify.patch sockdir_in_run.patch
MAINTAINER = Felipe Sanchez <izto@asic-linux.com.mx>
LICENSE = BSD


DESCRIPTION = PostgreSQL Database Management System
define BLURB

PostgreSQL is an advanced object-relational database management system
that supports an extended subset of the SQL standard, including
transactions, foreign keys, subqueries, triggers, user-defined types
and functions. This distribution also contains C language bindings.

endef

##################### PACKAGING #####################


#IZTACI_PACKAGE_PATH =

# Users and groups the binary package will create
# WHEN INSTALLED ON THE DESTINATION SYSTEM
CREATE_GROUPS = postgres:55
CREATE_USERS = postgres:55:55

# This is to be appended to the package's installation script
# Use it to set file owners, permissions, DB initialization, etc.
# Remember any shell variables (Such as $ROOT) have to be escaped
# like this: \$$ROOT

define DOINST_APPEND

if ! [ -d \$$ROOT/$(PGDATA) ]; then
   mkdir -vp \$$ROOT/$(PGDATA)
   chown -vR postgres:postgres \$$ROOT/$(PGDATA)
fi

   
echo ------------------------------------------------------------------
echo s6-rc services installed:
echo
echo \"    postgres-server\"
echo \"    postgres-log\"
echo \"    postgres\"
echo
echo Run \'rc update\' to add them to the live services database.
echo
echo ------------------------------------------------------------------
echo If this is a new installation you can initialize your database with:
echo
echo  sudo -u postgres $(prefix)/bin/initdb -E utf8 -D $(PGDATA)
echo
echo You might also want to review the host access rules in
echo $(PGDATA)/pg_hba.conf 
echo
echo Afterwards, start the PostgreSQL service with \'rc up postgres\'
echo ------------------------------------------------------------------
echo
endef

# Required dependencies
define SLACK_REQUIRED
readline
ncurses
linux-pam
openssl
tcl
zlib
endef

# Suggested dependencies
define SLACK_SUGGESTS
endef

# Package conflicts (lprng vs cups for example)
define SLACK_CONFLICTS
endef



##################### BUILDING #####################


CONFIGURE_SCRIPTS = $(WORKSRC)/configure
BUILD_SCRIPTS     = custom
INSTALL_SCRIPTS   = $(WORKSRC)/Makefile

CONFIGURE_ARGS = $(DIRPATHS)
NODIRPATHS = 

# Directories to be created as part of the install process.
# Can be inside the final package or just transient dirs we need
# while building it.
INSTALL_DIRS += $(DESTDIR)/etc/sysconfig
INSTALL_DIRS += $(DESTDIR)/etc/s6-rc/source

# If some dirs are trying to install into /, list their names
# here, such as: prefix bindir mandir
INSTALL_OVERRIDE_DIRS = 


# Dependencies are of the form categorydir/packagedir
# LIBDEPS are for libraries, and DEPENDS are for everything else
DEPENDS =
LIBDEPS =
DEPENDS =
# Builddeps are installed in the build DESTIMG
BUILDDEPS =

##################### GAR #####################

# This should go before any hand-made rules.
include config.mk
include ../level.mk

##################### CUSTOMIZING #####################

configure-custom:
	cd $(WORKSRC); ./configure $(CONFIGURE_OPTS)
	$(MAKECOOKIE)

build-custom:
	cd $(WORKSRC); env -i /bin/bash -c "PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin /usr/bin/make $(MFLAGS)"
	$(MAKECOOKIE)

pre-install:
	sed -i "/^#log_line_prefix/s/.*/log_line_prefix = '[%p] '/g" $(WORKSRC)/src/backend/utils/misc/postgresql.conf.sample
	$(MAKECOOKIE)

post-install:
	$(MAKE) s6rc
	$(MAKE) sysconfig
	$(MAKE) $(INSTALL_ENV) DESTDIR=$(DESTDIR) -C $(WORKSRC)/doc/src/sgml/ install-man
	$(MAKE) strip
	$(MAKE) gzip-man
	$(MAKECOOKIE)
