Search code examples
postgresqlmakefilepostgresql-13

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile


I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:

curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install

Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:

build:
    curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
    unzip postgres.zip
    rm postgres.zip

    cd postgres-REL_13_3 \
        && ./configure --prefix "`pwd`" --without-readline --without-zlib \
        && $(MAKE) \
        && $(MAKE) install

Running this Makefile results in the error:

../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found

It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.


Solution

  • The issue seems to be due to missing headers as described on this PostgreSQL message board.

    It appears that Makefile generates src/backend/utils/errcodes.h in the build directory, but symlinks src/include/utils/errcodes.h to the sources directory. That is src/include/utils/errcodes.h appears to be a broken symlink.

    A tedious (but working) fix is to manually copy the missing files as part of the make file.

    cp {build_path}/builds/postgresql/src/backend/utils/errcodes.h {build_path}/builds/postgresql/src/include/utils/
    

    The better way is to generate the headers correctly. The accepted answer set me on the right track but unfortunately, I was unable to change the MAKELEVEL variable using the unset command. Also tried the following (separately) but it did not work.

    MAKELEVEL=
    unset -v MAKELEVEL
    env -u MAKELEVEL
    

    I was finally able to generate the headers correctly using this SO answer.

    BUILD_COMMAND $(MAKE) MAKELEVEL=0