We will continue what we started here, Now let's create the necessary files, and go through each of them. We stopped where we created a directory for the extension add_two_numbers
. In this Blog we will start by creating the Makefile
.
- Makefile:
MODULES = add_two_numbers
EXTENSION = add_two_numbers
DATA = add_two_numbers--0.0.1.sql
PG_CONFIG = /usr/local/pgsql-13/bin/pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
MODULES
: list of shared-library objects to be built from source files with the same stem, which mean you should specify the name of the c file we will build which we will name add_two_numbers
EXTENSION
: specify the name of the extension that postgres will use to identify our extension, we will name it add_two_numbers
as well.
DATA
: by this variable we specify the sql file that postgres will use to run the necessary queries to create and install the extension in the database.
PG_CONFIG
: By this variable we specify the path to the pg_config binary file in the postgres database where we will install the extension, this will give the make
command the necessary information for proper installation. Also we will need this variable in the following variable to get the path for a very important file that extensions use in the building process, this file which is pgxs.mk
, it contains generic rules to build extensions.
PGXS
: as we just said above, here we need to assign a command to that retrieves the pgxs.mk
file location. In $(shell $(PG_CONFIG) --pgxs)
the $(PG_CONFIG) will retrieve what we assigned (PG_CONFIG) variable which is the path to the pg_config file, that's to execute it with the --pgxs
flag to get the path of pgxs.mk
file.
include $(PGXS)
: then this part is responsible to include pgxs.mk
so that to apply the rules in that file to build the extension.
Very important Note: You can always refer to the other variables you can add to Makefile, as by opening pgxs.mk
file you will find instructions on each variable especially for these we created, and for other variables that can be necessary for you later extensions, so take a look on it!. Get the file path by running $(PG_CONFIG) --pgxs
to open it.
Top comments (0)