From 0c6eab434f2db89cafb5bb7b7f44f32f3551cb3d Mon Sep 17 00:00:00 2001 From: BLM Date: Thu, 16 Jul 2015 14:03:05 -0500 Subject: [PATCH] Made build system automatically find sizeof(PhoneNumber) --- .gitignore | 2 ++ Makefile | 12 +++++++++++- get_sizeof_phone_number.cpp | 10 ++++++++++ pg_libphonenumber.cpp | 1 - ...number--1.0.sql => pg_libphonenumber.sql.template | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 get_sizeof_phone_number.cpp rename pg_libphonenumber--1.0.sql => pg_libphonenumber.sql.template (89%) diff --git a/.gitignore b/.gitignore index 0aa9426..ebde25e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.swp *.o *.so +/get_sizeof_phone_number +/pg_libphonenumber--*.sql diff --git a/Makefile b/Makefile index b1731d0..85a5d8a 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,21 @@ EXTENSION := pg_libphonenumber -DATA := pg_libphonenumber--1.0.sql +version := 1.0 +extension_script := $(EXTENSION)--$(version).sql +DATA_built := $(extension_script) MODULE_big := pg_libphonenumber OBJS := pg_libphonenumber.o PG_CPPFLAGS := -fPIC -std=c++11 -g SHLIB_LINK := -lphonenumber -lstdc++ +EXTRA_CLEAN := $(extension_script) get_sizeof_phone_number + PG_CONFIG := pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) + +$(extension_script): $(EXTENSION).sql.template get_sizeof_phone_number + sed "s/SIZEOF_PHONE_NUMBER/$(shell ./get_sizeof_phone_number)/" $< > $@ + +get_sizeof_phone_number: get_sizeof_phone_number.cpp + g++ $< -o $@ diff --git a/get_sizeof_phone_number.cpp b/get_sizeof_phone_number.cpp new file mode 100644 index 0000000..45307ff --- /dev/null +++ b/get_sizeof_phone_number.cpp @@ -0,0 +1,10 @@ +#include + +#include "phonenumbers/phonenumber.pb.h" + +using namespace i18n::phonenumbers; + +int main(int argc, const char** argv) { + std::cout << sizeof(PhoneNumber) << std::endl; + return 0; +} diff --git a/pg_libphonenumber.cpp b/pg_libphonenumber.cpp index 8c35912..2d3f2f2 100755 --- a/pg_libphonenumber.cpp +++ b/pg_libphonenumber.cpp @@ -1,7 +1,6 @@ #include #include -#define I18N_PHONENUMBERS_USE_BOOST #include "phonenumbers/phonenumberutil.h" extern "C" { diff --git a/pg_libphonenumber--1.0.sql b/pg_libphonenumber.sql.template similarity index 89% rename from pg_libphonenumber--1.0.sql rename to pg_libphonenumber.sql.template index 1fee397..7289af7 100644 --- a/pg_libphonenumber--1.0.sql +++ b/pg_libphonenumber.sql.template @@ -19,8 +19,9 @@ CREATE FUNCTION phone_number_send(phone_number) RETURNS bytea LANGUAGE c IMMUTABLE STRICT AS 'pg_libphonenumber', 'phone_number_send'; +--SIZEOF_PHONE_NUMBER is replaced when generating the "real" script. CREATE TYPE phone_number ( - INTERNALLENGTH = 64, + INTERNALLENGTH = SIZEOF_PHONE_NUMBER, INPUT = phone_number_in, OUTPUT = phone_number_out, RECEIVE = phone_number_recv,