Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4GD-0008Nv-53 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Jul 2018 13:25:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fb4GB-00043K-M0 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Jul 2018 13:25:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4GB-00042w-Bi for pgsql-hackers@lists.postgresql.org; Thu, 05 Jul 2018 13:25:23 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fb4G8-0005RH-Iw for pgsql-hackers@postgresql.org; Thu, 05 Jul 2018 13:25:22 +0000 Received: from [192.168.127.1] (port=23370 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fb4G6-00084A-08; Thu, 05 Jul 2018 13:25:18 +0000 Received: from [127.0.0.1] (port=47042 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fb4G5-0000el-9m; Thu, 05 Jul 2018 13:25:17 +0000 From: Andrew Gierth To: Tom Lane Cc: Peter Eisentraut , pgsql-hackers@postgresql.org, Andres Freund Subject: Re: Should contrib modules install .h files? In-Reply-To: <87in5tnafh.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Thu, 05 Jul 2018 13:51:44 +0100") Message-ID: <87efghn7js.fsf@news-spur.riddles.org.uk> References: <87y3euomjh.fsf@news-spur.riddles.org.uk> <87tvpinfr4.fsf@news-spur.riddles.org.uk> <63444.1530537990@sss.pgh.pa.us> <87lgatohzp.fsf@news-spur.riddles.org.uk> <63655.1530540982@sss.pgh.pa.us> <87h8lhoevw.fsf@news-spur.riddles.org.uk> <63819.1530544945@sss.pgh.pa.us> <878t6to8j9.fsf@news-spur.riddles.org.uk> <874lhho071.fsf@news-spur.riddles.org.uk> <67427.1530738056@sss.pgh.pa.us> <87po02m0bh.fsf@news-spur.riddles.org.uk> <87in5tnafh.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Thu, 05 Jul 2018 14:25:17 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-=-= Content-Type: text/plain >>>>> "Andrew" == Andrew Gierth writes: Andrew> Patch with docs (including an example) and Install.pm changes (blind). Andrew> I'll stick this in the open CF to see what cfbot thinks of it. Meh. Oversight in handling empty or missing vars. Also incorrect dir in msvc version. Fixed I hope. -- Andrew (irc:RhodiumToad) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=contrib_includes_4.patch Content-Description: contrib include files diff --git a/contrib/hstore/Makefile b/contrib/hstore/Makefile index ab7fef3979..46d26f8052 100644 --- a/contrib/hstore/Makefile +++ b/contrib/hstore/Makefile @@ -11,6 +11,8 @@ DATA = hstore--1.4.sql hstore--1.4--1.5.sql \ hstore--unpackaged--1.0.sql PGFILEDESC = "hstore - key/value pair data type" +HEADERS = hstore.h + REGRESS = hstore ifdef USE_PGXS diff --git a/doc/src/sgml/extend.sgml b/doc/src/sgml/extend.sgml index 348ae71423..a3cb064131 100644 --- a/doc/src/sgml/extend.sgml +++ b/doc/src/sgml/extend.sgml @@ -1100,13 +1100,15 @@ include $(PGXS) and include the global PGXS makefile. Here is an example that builds an extension module named isbn_issn, consisting of a shared library containing - some C code, an extension control file, a SQL script, and a documentation - text file: + some C code, an extension control file, a SQL script, an include file + (only needed if other modules might need to access the extension functions + without going via SQL), and a documentation text file: MODULES = isbn_issn EXTENSION = isbn_issn DATA = isbn_issn--1.0.sql DOCS = README.isbn_issn +HEADERS_isbn_issn = isbn_issn.h PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) @@ -1221,6 +1223,28 @@ include $(PGXS) + HEADERS + + + files to install under + prefix/include/server/$MODULEDIR/$MODULE_big + + + + + + HEADERS_$MODULE + + + files to install under + prefix/include/server/$MODULEDIR/$MODULE, + where $MODULE must be a module name used + in MODULES or MODULE_big + + + + + SCRIPTS diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk index bfae02f90c..158581b3f5 100644 --- a/src/makefiles/pgxs.mk +++ b/src/makefiles/pgxs.mk @@ -38,6 +38,10 @@ # SCRIPTS -- script files (not binaries) to install into $PREFIX/bin # SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin, # which need to be built first +# HEADERS -- files to install into $(includedir_server)/$MODULEDIR/$MODULE_big +# HEADERS_$(MODULE) -- files to install into +# $(includedir_server)/$MODULEDIR/$MODULE; the value of $MODULE must be +# listed in MODULES or MODULE_big # REGRESS -- list of regression test cases (without suffix) # REGRESS_OPTS -- additional switches to pass to pg_regress # NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if @@ -94,13 +98,16 @@ endif ifdef MODULEDIR datamoduledir := $(MODULEDIR) docmoduledir := $(MODULEDIR) +incmoduledir := $(MODULEDIR) else ifdef EXTENSION datamoduledir := extension docmoduledir := extension +incmoduledir := extension else datamoduledir := contrib docmoduledir := contrib +incmoduledir := contrib endif endif @@ -108,6 +115,43 @@ ifdef PG_CPPFLAGS override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS) endif +HEADER_alldirs := $(patsubst HEADERS_%,%,$(filter HEADERS_%, $(.VARIABLES))) + +# HEADERS is an error in the absence of MODULE_big to provide a dir name +ifdef MODULE_big +ifdef HEADERS +HEADER_dirs := $(MODULE_big) +HEADERS_$(MODULE_big) = $(HEADERS) +else +HEADER_dirs := $(filter $(MODULE_big),$(HEADER_alldirs)) +endif +else +ifdef HEADERS +$(error HEADERS requires MODULE_big to be set) +endif +HEADER_dirs := $(filter $(MODULES),$(HEADER_alldirs)) +endif + +# HEADERS_foo requires that "foo" is in MODULES as a sanity check +ifneq ($(filter-out $(HEADER_dirs),$(HEADER_alldirs)),) +$(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs),$(HEADER_alldirs))) defined with no module) +endif + +# Functions for generating install/uninstall commands; the blank lines +# before the "endef" are required, don't lose them +# $(call install_headers,dir,headers) +define install_headers +$(MKDIR_P) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/' +$(INSTALL_DATA) $(addprefix $(srcdir)/, $(2)) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/' + +endef +# $(call uninstall_headers,dir,headers) +define uninstall_headers +rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2))) + +endef + + all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION)) ifeq ($(with_llvm), yes) @@ -154,6 +198,9 @@ endif # SCRIPTS ifdef SCRIPTS_built $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/' endif # SCRIPTS_built +ifneq ($(strip $(HEADER_dirs)),) + $(foreach dir,$(HEADER_dirs),$(if $(HEADERS_$(dir)),$(call install_headers,$(dir),$(HEADERS_$(dir))))) +endif # HEADERS ifdef MODULE_big ifeq ($(with_llvm), yes) $(call install_llvm_module,$(MODULE_big),$(OBJS)) @@ -218,6 +265,9 @@ endif ifdef SCRIPTS_built rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built)) endif +ifneq ($(strip $(HEADER_dirs)),) + $(foreach dir,$(HEADER_dirs),$(if $(HEADERS_$(dir)),$(call uninstall_headers,$(dir),$(HEADERS_$(dir))))) +endif # HEADERS ifdef MODULE_big ifeq ($(with_llvm), yes) diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm index 429608fde6..73a999892e 100644 --- a/src/tools/msvc/Install.pm +++ b/src/tools/msvc/Install.pm @@ -554,6 +554,48 @@ sub CopySubdirFiles } } + { + $flist = ''; + if ($mf =~ /^HEADERS\s*=\s*(.*)$/m) { $flist .= $1 } + my @modlist = (); + my %fmodlist = (); + while ($mf =~ /^HEADERS_([^\s=]+)\s*=\s*(.*)$/mg) { $fmodlist{$1} .= $2 } + + if ($mf =~ /^MODULE_big\s*=\s*(.*)$/m) + { + push @modlist, $1; + if ($flist ne '') + { + $fmodlist{$1} = $flist; + $flist = ''; + } + } + elsif ($mf =~ /^MODULES\s*=\s*(.*)$/m) + { + push @modlist, split /\s+/, $1; + } + + croak "HEADERS requires MODULE_big in $subdir $module" + if $flist ne ''; + + foreach my $mod (keys %fmodlist) + { + croak "HEADERS_$mod for unknown module in $subdir $module" + unless grep { $_ eq $mod } @modlist; + $flist = ParseAndCleanRule($fmodlist{$mod}, $mf); + EnsureDirectories($target, + "include/server/$moduledir", + "include/server/$moduledir/$mod"); + foreach my $f (split /\s+/, $flist) + { + lcopy("$subdir/$module/$f", + "$target/include/server/$moduledir/$mod/" . basename($f)) + || croak("Could not copy file $f in $subdir $module"); + print '.'; + } + } + } + $flist = ''; if ($mf =~ /^DOCS\s*=\s*(.*)$/mg) { $flist .= $1 } if ($flist ne '') --=-=-=--