pgxn-style makefiles and flex/bison

24 views
Skip to first unread message

Jay Levitt

unread,
Feb 12, 2012, 3:30:08 PM2/12/12
to pgxn-...@googlegroups.com
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.

My Makefile looks something like:

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

Hitoshi Harada

unread,
Feb 13, 2012, 2:45:49 AM2/13/12
to pgxn-...@googlegroups.com
On Sun, Feb 12, 2012 at 12:30 PM, Jay Levitt <j...@jay.fm> wrote:
> 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.
>
> # 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

Did you try adding src/ to cubeparse.c and cubescan.c as targets?

Thanks,
--
Hitoshi Harada

David E. Wheeler

unread,
Feb 14, 2012, 12:11:01 AM2/14/12
to pgxn-...@googlegroups.com
On Feb 12, 2012, at 11:45 PM, Hitoshi Harada wrote:

> Did you try adding src/ to cubeparse.c and cubescan.c as targets?

It would be nice to get it fixed, but honestly moving C code into the src directly is just a reflection of my own organizational bigotry. If it’s too much effort, then sod it, leave it where you know it works.

Best,

David

Reply all
Reply to author
Forward
0 new messages