1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

Move CRC tables to libpgport, and provide them in a separate include file.

This makes it much more convenient to build tools for Postgres that are
separately compiled and require a matching CRC implementation.

To prevent multiple copies of the CRC polynomial tables being introduced
into the postgres binaries, they are now included in the static library
libpgport that is mainly meant for replacement system functions.  That
seems like a bit of a kludge, but there's no better place.

This cleans up building of the tools pg_controldata and pg_resetxlog,
which previously had to build their own copies of pg_crc.o.

In the future, external programs that need access to the CRC tables can
include the tables directly from the new header file pg_crc_tables.h.

Daniel Farina, reviewed by Abhijit Menon-Sen and Tom Lane
This commit is contained in:
Tom Lane 2012-02-28 19:53:39 -05:00
parent 0140a11b9b
commit 5c02a00d44
9 changed files with 41 additions and 28 deletions

View File

@ -12,6 +12,6 @@ subdir = src/backend/utils/hash
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
OBJS = dynahash.o hashfn.o pg_crc.o
OBJS = dynahash.o hashfn.o
include $(top_srcdir)/src/backend/common.mk

View File

@ -1,3 +1 @@
/pg_crc.c
/pg_controldata

View File

@ -15,16 +15,13 @@ subdir = src/bin/pg_controldata
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
OBJS= pg_controldata.o pg_crc.o $(WIN32RES)
OBJS= pg_controldata.o $(WIN32RES)
all: pg_controldata
pg_controldata: $(OBJS) | submake-libpgport
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
rm -f $@ && $(LN_S) $< .
install: all installdirs
$(INSTALL_PROGRAM) pg_controldata$(X) '$(DESTDIR)$(bindir)/pg_controldata$(X)'
@ -35,4 +32,4 @@ uninstall:
rm -f '$(DESTDIR)$(bindir)/pg_controldata$(X)'
clean distclean maintainer-clean:
rm -f pg_controldata$(X) $(OBJS) pg_crc.c
rm -f pg_controldata$(X) $(OBJS)

View File

@ -1,3 +1 @@
/pg_crc.c
/pg_resetxlog

View File

@ -15,16 +15,13 @@ subdir = src/bin/pg_resetxlog
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
OBJS= pg_resetxlog.o pg_crc.o $(WIN32RES)
OBJS= pg_resetxlog.o $(WIN32RES)
all: pg_resetxlog
pg_resetxlog: $(OBJS) | submake-libpgport
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
rm -f $@ && $(LN_S) $< .
install: all installdirs
$(INSTALL_PROGRAM) pg_resetxlog$(X) '$(DESTDIR)$(bindir)/pg_resetxlog$(X)'
@ -35,4 +32,4 @@ uninstall:
rm -f '$(DESTDIR)$(bindir)/pg_resetxlog$(X)'
clean distclean maintainer-clean:
rm -f pg_resetxlog$(X) $(OBJS) pg_crc.c
rm -f pg_resetxlog$(X) $(OBJS)

View File

@ -1,7 +1,11 @@
/*-------------------------------------------------------------------------
*
* pg_crc.c
* PostgreSQL CRC support
* pg_crc_tables.h
* Polynomial lookup tables for CRC macros
*
* We make these tables available as a .h file so that programs not linked
* with libpgport can still use the macros in pg_crc.h. They just need
* to #include this header as well.
*
* See Ross Williams' excellent introduction
* A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from
@ -17,16 +21,12 @@
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/utils/hash/pg_crc.c
* src/include/utils/pg_crc_tables.h
*
*-------------------------------------------------------------------------
*/
/* Use c.h so that this file can be built in either frontend or backend */
#include "c.h"
#ifndef PG_CRC_TABLES_H
#define PG_CRC_TABLES_H
/*
* This table is based on the polynomial
@ -513,3 +513,5 @@ const uint64 pg_crc64_table[256] = {
#endif /* SIZEOF_VOID_P < 8 */
#endif /* PROVIDE_64BIT_CRC */
#endif /* PG_CRC_TABLES_H */

View File

@ -31,8 +31,8 @@ override CPPFLAGS := -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
LIBS += $(PTHREAD_LIBS)
OBJS = $(LIBOBJS) chklocale.o dirmod.o erand48.o exec.o fls.o inet_net_ntop.o \
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o pgstrcasecmp.o \
qsort.o qsort_arg.o sprompt.o thread.o
noblock.o path.o pgcheckdir.o pg_crc.o pgmkdirp.o pgsleep.o \
pgstrcasecmp.o qsort.o qsort_arg.o sprompt.o thread.o
# foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
OBJS_SRV = $(OBJS:%.o=%_srv.o)

21
src/port/pg_crc.c Normal file
View File

@ -0,0 +1,21 @@
/*-------------------------------------------------------------------------
*
* pg_crc.c
* PostgreSQL CRC support
*
* This file simply #includes the CRC table definitions so that they are
* available to programs linked with libpgport.
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/port/pg_crc.c
*
*-------------------------------------------------------------------------
*/
#include "c.h"
#include "utils/pg_crc_tables.h"

View File

@ -261,8 +261,8 @@ sub AddDir
$mf =~ s{OBJS[^=]*=\s*(.*)$}{}m;
}
# Match rules that pull in source files from different directories
# example: pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
# Match rules that pull in source files from different directories, eg
# pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
my $replace_re = qr{^([^:\n\$]+\.c)\s*:\s*(?:%\s*: )?\$(\([^\)]+\))\/(.*)\/[^\/]+$}m;
while ($mf =~ m{$replace_re}m)
{