Commit 5c02a00d authored by Tom Lane's avatar Tom Lane

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
parent 0140a11b
......@@ -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
......@@ -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)
......@@ -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)
/*-------------------------------------------------------------------------
*
* 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 */
......@@ -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)
......
/*-------------------------------------------------------------------------
*
* 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"
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment