Thread: Building an extension in a separate directory from the source files.

Building an extension in a separate directory from the source files.

From
a.mitrokhin@postgrespro.ru
Date:
hi.

1. Does postgresql support building an extension in a separate directory
    from the source files? For example, is this design officially 
supported?

         ~$ mkdir -p $(BUILDDIR)
         ~$ make -C $(BUILDDIR) -f $(SRCDIR)/Makefile USE_PGXS=1 all

2. If so, what is the correct way to build object files for .c files 
that are
    located in their own subdirectories inside $(SRCDIR)? For example, in
    $(SRCDIR)/Makefile it is written:
         OBJS = src/a.c src/b.c
    I'm getting:
         gcc ... -c -o src/a.o ../src/a.c
         Assembler messages:
         Fatal error: can't create src/a.o: No such file or directory

Patch which fixes this problem for me:

--- src/Makefile.global.in.orig 2024-11-29 16:26:14.350728880 +0700
+++ src/Makefile.global.in      2024-11-29 16:26:54.362809922 +0700
@@ -991,6 +991,7 @@
  # GCC allows us to create object and dependency file in one invocation.
  %.o : %.c
         @if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
+       @if test ! -d $(@D); then mkdir -p $(@D); fi
         $(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po

  %.o : %.cpp

/foo