src/tools/pgindent/README

pgindent
========

This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
*.l files.

1) Install pg_bsd_indent (see below for details).

2) Install entab (src/tools/entab/).

3) Change directory to the top of the build tree.

4) Download the typedef file from the buildfarm:

	wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl

5) Remove all derived files (pgindent has trouble with one of the flex macros):

	gmake maintainer-clean

   Or:

        git clean -fdx

6) Run pgindent:

	find . -name '*.[ch]' -type f -print | \
	egrep -v -f src/tools/pgindent/exclude_file_patterns | \
	xargs -n100 src/tools/pgindent/pgindent src/tools/pgindent/typedefs.list

7) Remove any files that generate errors and restore their original
   versions.

8) Do a full test build:

	run configure
	# stop is only necessary if it's going to install in a location with an
	# already running server
	pg_ctl stop
	gmake -C src install
	gmake -C contrib install
	gmake installcheck-world

9) Indent the Perl MSVC code:

	cd src/tools/msvc
	perltidy -b -bl -nsfs -naws -l=100 -ole=unix *.pl *.pm

---------------------------------------------------------------------------

BSD indent
----------

We have standardized on NetBSD's indent, and renamed it pg_bsd_indent.
We have fixed a few bugs which requre the NetBSD source to be patched
with indent.bsd.patch patch.  A fully patched version is available at
ftp://ftp.postgresql.org/pub/dev.

GNU indent, version 2.2.6, has several problems, and is not recommended.
These bugs become pretty major when you are doing >500k lines of code.
If you don't believe me, take a directory and make a copy.  Run pgindent
on the copy using GNU indent, and do a diff -r. You will see what I
mean. GNU indent does some things better, but mangles too.  For details,
see:

	http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
	http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php

---------------------------------------------------------------------------

Notes about excluded files
--------------------------

src/include/storage/s_lock.h is excluded because it contains assembly code
that pgindent tends to mess up.

src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
are excluded because those files are imported from an external project,
not maintained locally, and are machine-generated anyway.

src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
regression tests.  Several *.h files are included in regression output so
should not be changed.

---------------------------------------------------------------------------

Obsolete typedef list creation instructions
-------------------------------------------

To use pgindent:

1) Build the source tree with _debug_ symbols and all possible configure options

2) Install to /usr/local/pgsql

3) Install all contrib modules

4) Save a list of typedefs by running:

	src/tools/find_typedef /usr/local/pgsql/bin /usr/local/pgsql/lib > /tmp/pgtypedefs
