<?xml version="1.0" encoding="UTF-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><id>https://blog.pgxn.org/tags/contrib/</id><title>Contrib</title><updated>2012-04-11T16:36:00Z</updated><link rel="self" type="application/atom+xml" href="https://blog.pgxn.org/tags/contrib/feed.xml"/><link rel="alternate" type="text/html" href="https://blog.pgxn.org/tags/contrib/"/><author><name>The PGXN Maintainers</name></author><generator uri="https://gohugo.io/" version="0.167.0">Hugo</generator><entry><id>https://blog.pgxn.org/post/20908326485</id><title type="html">Lose USE_PGXS in your Makefiles</title><link rel="alternate" type="text/html" href="https://blog.pgxn.org/2012/lose-use-pgxs/"/><updated>2026-10-07T16:13:48Z</updated><published>2012-04-11T16:36:00Z</published><author><name>David E. Wheeler</name></author><category scheme="https://blog.pgxn.org/tags" term="extension" label="Extension"/><category scheme="https://blog.pgxn.org/tags" term="use_pgxs" label="USE_PGXS"/><category scheme="https://blog.pgxn.org/tags" term="makefile" label="Makefile"/><category scheme="https://blog.pgxn.org/tags" term="make" label="make"/><category scheme="https://blog.pgxn.org/tags" term="pg_config" label="pg_config"/><category scheme="https://blog.pgxn.org/tags" term="contrib" label="contrib"/><summary type="html"><![CDATA[<p>Traditionally, folks have created extensions for PostgreSQL by copying one of
the <a href="https://www.postgresql.org/docs/current/static/contrib.html">contrib modules</a> and hacking it into something new. One of the things
that comes along for the ride is the <code>Makefile</code> (<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=contrib/isn/Makefile;hb=HEAD">example</a>). As a result,
there are a lot of third-party extensions that use the <code>USE_PGXS</code> variable.</p>
<p>A bit of background. The core contrib extensions generally rely on a relative
path to include the core <code>Makefile</code>s needed to build the extension. Because
they ship with the core distribution, they can generally expect that the core
has already been compiled, the necessary <code>Makefile</code>s have been created, and
that they should be built against them. All the assumptions are that the
extensions should be built against the source tree in which they are
distributed. So there is no need to use <a href="https://www.postgresql.org/docs/current/static/app-pgconfig.html"><code>pg_config</code></a> to find <a href="https://www.postgresql.org/docs/current/static/extend-pgxs.html">PGXS</a>; it
already knows where to find what it needs.</p>]]></summary><content type="html" xml:base="https://blog.pgxn.org/" xml:space="preserve"><![CDATA[<p>Traditionally, folks have created extensions for PostgreSQL by copying one of
the <a href="https://www.postgresql.org/docs/current/static/contrib.html">contrib modules</a> and hacking it into something new. One of the things
that comes along for the ride is the <code>Makefile</code> (<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=contrib/isn/Makefile;hb=HEAD">example</a>). As a result,
there are a lot of third-party extensions that use the <code>USE_PGXS</code> variable.</p>
<p>A bit of background. The core contrib extensions generally rely on a relative
path to include the core <code>Makefile</code>s needed to build the extension. Because
they ship with the core distribution, they can generally expect that the core
has already been compiled, the necessary <code>Makefile</code>s have been created, and
that they should be built against them. All the assumptions are that the
extensions should be built against the source tree in which they are
distributed. So there is no need to use <a href="https://www.postgresql.org/docs/current/static/app-pgconfig.html"><code>pg_config</code></a> to find <a href="https://www.postgresql.org/docs/current/static/extend-pgxs.html">PGXS</a>; it
already knows where to find what it needs.</p>
<p>But as extensions, there is still the possibility that one might want to build
them against an existing installation of PostgreSQL, or an older version than
the source with which they&rsquo;re distributed. So the core hackers provided the
<code>USE_PGXS</code> variable so that one can in effect tell <code>make</code>, &ldquo;Don&rsquo;t build
against the local source tree, but find PGXS for some other install and build
against that, instead.&rdquo; It was expected to be exceptional, since most folks
would build against the local source tree, and not a big deal to make anyone
else build it with:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">make <span class="nv">USE_PGXS</span><span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><p>Today things are different. There is a growing ecosystem of third party
extensions on <a href="https://pgxn.org/">PGXN</a>, <a href="https://pgfoundry.org/">pgFoundry</a>, <a href="https://github.com/">GitHub</a>, and <a href="https://bitbucket.org/">Bitbucket</a>, and obviously
they&rsquo;re not distributed with the PostgreSQL core. For these extensions, there
is no surrounding PostgreSQL source code to automatically include, so they
<em>must</em> use <code>pg_config</code> to find PGXS in order build.</p>
<p>Yet, there are quite a few third-party extensions that nevertheless assume
that they are in the <code>contrib</code> directory of the PostgreSQL source code
distribution, and so still have the <code>USE_PGXS</code> variable. The <a href="https://api.pgxn.org/src/twitter_fdw/twitter_fdw-1.0.0/Makefile">twitter_ftw
1.0.0 <code>Makefile</code></a> is a recent example. Just like core extensions, it has this
code:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-makefile" data-lang="makefile"><span class="line"><span class="cl"><span class="err">ifdef</span> <span class="err">USE_PGXS</span>
</span></span><span class="line"><span class="cl"><span class="nv">PG_CONFIG</span> <span class="o">=</span> pg_config
</span></span><span class="line"><span class="cl"><span class="nv">PGXS</span> <span class="o">:=</span> <span class="k">$(</span>shell <span class="k">$(</span>PG_CONFIG<span class="k">)</span> --pgxs<span class="k">)</span>
</span></span><span class="line"><span class="cl"><span class="err">include</span> <span class="k">$(</span><span class="nv">PGXS</span><span class="k">)</span>
</span></span><span class="line"><span class="cl"><span class="err">else</span>
</span></span><span class="line"><span class="cl"><span class="nv">subdir</span> <span class="o">=</span> contrib/twitter_fdw
</span></span><span class="line"><span class="cl"><span class="nv">top_builddir</span> <span class="o">=</span> ../..
</span></span><span class="line"><span class="cl"><span class="err">include</span> <span class="k">$(</span><span class="nv">top_builddir</span><span class="k">)</span><span class="err">/src/Makefile.global</span>
</span></span><span class="line"><span class="cl"><span class="err">include</span> <span class="k">$(</span><span class="nv">top_srcdir</span><span class="k">)</span><span class="err">/contrib/contrib-global.mk</span>
</span></span><span class="line"><span class="cl"><span class="err">endif</span>
</span></span></code></pre></div><p>Because Hitoshi-san originally copied the <code>Makefile</code> from a core extension, it
still assumes it will be distributed in core by default. And as I said, there
are quite a few third-party extensions that exhibit this pattern.</p>
<p>And now the <a href="https://en.wikipedia.org/wiki/Public_service_announcement">PSA</a>: <strong>Please don&rsquo;t use <code>USE_PGXS</code> in PostgreSQL extension
<code>Makefile</code>s.</strong></p>
<p>Not only is it unnecessary, it makes no sense for third-party extensions. They
should <em>always</em> assume that they need to use <code>pg_config</code> to find PGXS. If you
have an extension <code>Makefile</code> with <code>USE_PGXS</code> like twitter_ftw 1.0.0 did, you
should change it to something like this (as Hitoshi-san did in the
<a href="https://api.pgxn.org/src/twitter_fdw/twitter_fdw-1.0.1/Makefile">twitter_ftw 1.0.1 <code>Makefile</code></a>):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-makefile" data-lang="makefile"><span class="line"><span class="cl"><span class="nv">PG_CONFIG</span> <span class="o">=</span> pg_config
</span></span><span class="line"><span class="cl"><span class="nv">PGXS</span> <span class="o">:=</span> <span class="k">$(</span>shell <span class="k">$(</span>PG_CONFIG<span class="k">)</span> --pgxs<span class="k">)</span>
</span></span><span class="line"><span class="cl"><span class="err">include</span> <span class="k">$(</span><span class="nv">PGXS</span><span class="k">)</span>
</span></span></code></pre></div><p>That&rsquo;s it. I am asking you to <em>make your <code>Makefile</code> simpler.</em></p>
<hr>
<p><em>An Aside</em></p>
<p>There is <em>one</em> situation in which you might need to include the core contrib
<code>Makefile</code>s. And it&rsquo;s pretty unusual. If you need to support PostgreSQL 8.1 or
earlier, <code>pg_config</code> will not be able to tell you where to find PGXS. So users
will have to copy the extension source directory into the PostgreSQL source
<code>contrib/</code> directory and build from there. They will need a way to tell <code>make</code>
<em>not</em> to use PGXS. In this one unusual case, I suggest you add a <code>NO_PGXS</code>
variable. <a href="https://api.pgxn.org/src/pgtap/pgtap-0.90.0/Makefile">pgTAP&rsquo;s <code>Makefile</code></a> provides an example. But honestly, very few
extensions need to support PostgreSQL 8.1 (the oldest release currently
supported by the core hackers is <em>8.3!</em>), so make use of this pattern only if
absolutely necessary.</p>
<p>Otherwise, please don&rsquo;t use <code>USE_PGXS</code>.</p>
<hr>
<p>If you want a complete guide to creating your extension <code>Makefile</code>, have a
look at the <a href="https://manager.pgxn.org/howto">PGXN Howto</a>, which includes some detailed examples that include
support for pre- and post-<a href="https://www.postgresql.org/docs/current/static/sql-createextension.html"><code>CREATE EXTENSION</code></a> support. The <a href="https://www.postgresql.org/docs/current/static/extend-pgxs.html">PGXS</a> docs
contain additional details about all the <code>Makefile</code> variables you can use to
simplify extension configuration and installation. Check &rsquo;em out.</p>
]]></content></entry></feed>