I'm using contrib/cube as a starting point, and am having absolutely no luck with moving the C/flex/bison source into a src/ directory. I've tried every combination of MODULES, MODULE_big, and OBJS in the declarations, and various combinations of "src/" and "$(srcdir)" in the dependencies, but I can't get make to recognize that it should be building cubeparse.c, cubescan.c, and cubeparse.o in the src/ directory. Probably doesn't help that I haven't touched Makefiles in ages. Any tips? It doesn't seem that any existing pgxn extensions use both your new-style Makefile/layout and external build tools like flex or bison.
EXTENSION = simvec
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
DATA = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))
DOCS = $(wildcard doc/*.md)
TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --load-language=plpgsql
MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
PG_CONFIG = pg_config
PG91 = $(shell $(PG_CONFIG) --version | grep -qE " 8\.| 9\.0" && echo no || echo yes)
ifeq ($(PG91),yes)
all: sql/$(EXTENSION)--$(EXTVERSION).sql
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
cp $< $@
DATA = $(wildcard sql/*--*.sql) sql/$(EXTENSION)--$(EXTVERSION).sql
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql
endif
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
SHLIB_LINK += $(filter -lm, $(LIBS))
# cubescan is compiled as part of cubeparse. I am not renaming it yet, because flex/bison could be messy.
cubeparse.o: src/cubescan.c
cubeparse.c: src/cubeparse.y
ifdef BISON
$(BISON) $(BISONFLAGS) -o $@ $<
else
@$(missing) bison $< $@
endif
cubescan.c: src/cubescan.l
ifdef FLEX
$(FLEX) $(FLEXFLAGS) -o'$@' $<
else
@$(missing) flex $< $@
endif
distprep: $(srcdir)/cubeparse.c $(srcdir)/cubescan.c
maintainer-clean:
rm -f $(srcdir)/cubeparse.c $(srcdir)/cubescan.c