11// vim:ft=javascript
22
3+ function mongodb_generate_header ( inpath , outpath , replacements )
4+ {
5+ STDOUT . WriteLine ( "Generating " + outpath ) ;
6+
7+ var infile = FSO . OpenTextFile ( inpath , 1 ) ;
8+ var outdata = infile . ReadAll ( ) ;
9+ infile . Close ( ) ;
10+
11+ for ( var key in replacements ) {
12+ outdata = outdata . replace ( "@" + key + "@" , replacements [ key ] ) ;
13+ }
14+
15+ var outfile = FSO . CreateTextFile ( outpath , true ) ;
16+ outfile . Write ( outdata ) ;
17+ outfile . Close ( ) ;
18+ }
19+
20+ function mongodb_parse_version_file ( inpath , prefix )
21+ {
22+ var infile = FSO . OpenTextFile ( inpath , 1 ) ;
23+ var version = infile . ReadLine ( ) ;
24+ infile . Close ( ) ;
25+
26+ var xyz_pre = version . split ( "-" ) ;
27+ var xyz = xyz_pre [ 0 ] . split ( "." ) ;
28+
29+ var replacements = { } ;
30+ replacements [ prefix + "VERSION" ] = version ;
31+ replacements [ prefix + "MAJOR_VERSION" ] = xyz [ 0 ] ;
32+ replacements [ prefix + "MINOR_VERSION" ] = xyz [ 1 ] ;
33+ replacements [ prefix + "MICRO_VERSION" ] = xyz [ 2 ] ;
34+ replacements [ prefix + "PRERELEASE_VERSION" ] = xyz_pre [ 1 ] ;
35+
36+ return replacements ;
37+ }
38+
339ARG_ENABLE ( "mongodb" , "MongoDB support" , "no" ) ;
440ARG_WITH ( "mongodb-sasl" , "MongoDB: Build against Cyrus-SASL" , "yes" ) ;
541
642if ( PHP_MONGODB != "no" ) {
743 ADD_EXTENSION_DEP ( "mongodb" , "openssl" , false ) ;
844
9- ADD_FLAG ( "CFLAGS_MONGODB" , " /I" + configure_module_dirname + " /I" + configure_module_dirname + "/src/libmongoc/src/mongoc" + " /I" + configure_module_dirname + "/src/libbson/src/bson/ /I" + configure_module_dirname + "/src/libbson/src /I" + configure_module_dirname + "/src/contrib" ) ;
45+ ADD_FLAG ( "CFLAGS_MONGODB" , " /D BSON_COMPILATION /D MONGOC_COMPILATION /D MONGOC_TRACE / I" + configure_module_dirname + " /I" + configure_module_dirname + "/src/libmongoc/src/mongoc" + " /I" + configure_module_dirname + "/src/libbson/src/bson/ /I" + configure_module_dirname + "/src/libbson/src /I" + configure_module_dirname + "/src/contrib" ) ;
1046 EXTENSION ( "mongodb" , "php_phongo.c" ) ;
1147 ADD_SOURCES ( configure_module_dirname + "/" , "phongo_compat.c" , "mongodb" ) ;
1248 ADD_SOURCES ( configure_module_dirname + "/src" , "bson.c" , "mongodb" ) ;
@@ -28,56 +64,94 @@ if (PHP_MONGODB != "no") {
2864 ADD_SOURCES ( configure_module_dirname + "/src/libmongoc/src/mongoc" , "mongoc-sasl.c" , "mongodb" ) ;
2965
3066 AC_DEFINE ( "HAVE_MONGOC" , 1 ) ;
31- AC_DEFINE ( "MONGOC_HAVE_WEAK_SYMBOLS" , 1 ) ;
3267
33- AC_DEFINE ( "BSON_COMPILATION" , 1 ) ;
34- AC_DEFINE ( "BSON_EXTRA_ALIGN" , 0 ) ;
35- AC_DEFINE ( "BSON_HAVE_DECIMAL128" , 0 ) ;
36- AC_DEFINE ( "BSON_EXPERIMENTAL_FEATURES" , 0 ) ;
37- AC_DEFINE ( "MONGOC_COMPILATION" , 1 ) ;
38- AC_DEFINE ( "MONGOC_NO_AUTOMATIC_GLOBALS" , 1 ) ;
39- AC_DEFINE ( "MONGOC_TRACE" , 1 ) ;
40- AC_DEFINE ( "MONGOC_EXPERIMENTAL_FEATURES" , 0 ) ;
68+ var bson_opts = {
69+ BSON_BYTE_ORDER : 1234 ,
70+ BSON_OS : 2 ,
71+ BSON_HAVE_STDBOOL_H : 0 ,
72+ BSON_HAVE_ATOMIC_32_ADD_AND_FETCH : 0 ,
73+ BSON_HAVE_ATOMIC_64_ADD_AND_FETCH : 0 ,
74+ BSON_PTHREAD_ONCE_INIT_NEEDS_BRACES : 0 ,
75+ BSON_HAVE_CLOCK_GETTIME : 0 ,
76+ BSON_HAVE_STRNLEN : 0 ,
77+ BSON_HAVE_SNPRINTF : 0 ,
78+ BSON_HAVE_REALLOCF : 0 ,
79+ BSON_NEEDS_SET_OUTPUT_FORMAT : 0 ,
80+ BSON_HAVE_TIMESPEC : 0 ,
81+ BSON_EXTRA_ALIGN : 0 ,
82+ BSON_HAVE_SYSCALL_TID : 0 ,
83+ BSON_HAVE_DECIMAL128 : 0 ,
84+ BSON_EXPERIMENTAL_FEATURES : 0
85+ } ;
86+
87+ if ( CHECK_FUNC_IN_HEADER ( "stdio.h" , "_set_output_format" ) ) {
88+ bson_opts . BSON_NEEDS_SET_OUTPUT_FORMAT = 1 ;
89+ }
90+
91+ mongodb_generate_header (
92+ configure_module_dirname + "/src/libbson/src/bson/bson-config.h.in" ,
93+ configure_module_dirname + "/src/libbson/src/bson/bson-config.h" ,
94+ bson_opts
95+ ) ;
96+
97+ mongodb_generate_header (
98+ configure_module_dirname + "/src/libbson/src/bson/bson-version.h.in" ,
99+ configure_module_dirname + "/src/libbson/src/bson/bson-version.h" ,
100+ mongodb_parse_version_file ( configure_module_dirname + "/src/libbson/VERSION_CURRENT" , "BSON_" )
101+ ) ;
102+
103+ var mongoc_opts = {
104+ // TODO: Support building with Secure Channel on Windows
105+ MONGOC_ENABLE_SSL_SECURE_CHANNEL : 0 ,
106+ MONGOC_ENABLE_CRYPTO_CNG : 0 ,
107+ // Secure Transport does not apply to Windows
108+ MONGOC_ENABLE_SSL_SECURE_TRANSPORT : 0 ,
109+ MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO : 0 ,
110+ MONGOC_ENABLE_SSL_OPENSSL : 0 ,
111+ MONGOC_ENABLE_CRYPTO_LIBCRYPTO : 0 ,
112+ MONGOC_ENABLE_SSL : 0 ,
113+ MONGOC_ENABLE_CRYPTO : 0 ,
114+ MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE : 0 ,
115+ MONGOC_ENABLE_SASL : 0 ,
116+ MONGOC_HAVE_SASL_CLIENT_DONE : 0 ,
117+ MONGOC_HAVE_WEAK_SYMBOLS : 0 ,
118+ MONGOC_NO_AUTOMATIC_GLOBALS : 1 ,
119+ MONGOC_EXPERIMENTAL_FEATURES : 0
120+ } ;
41121
42122 if ( CHECK_LIB ( "ssleay32.lib" , "mongodb" , PHP_MONGODB ) &&
43123 CHECK_LIB ( "libeay32.lib" , "mongodb" , PHP_MONGODB ) &&
44124 CHECK_HEADER_ADD_INCLUDE ( "openssl/ssl.h" , "CFLAGS_MONGOC" ) ) {
45- AC_DEFINE ( " MONGOC_ENABLE_SSL_OPENSSL" , 1 ) ;
46- AC_DEFINE ( " MONGOC_ENABLE_CRYPTO_LIBCRYPTO" , 1 ) ;
47- AC_DEFINE ( " MONGOC_ENABLE_SSL" , 1 ) ;
48- AC_DEFINE ( " MONGOC_ENABLE_CRYPTO" , 1 ) ;
49- AC_DEFINE ( " MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE" , 1 ) ;
125+ mongoc_opts . MONGOC_ENABLE_SSL_OPENSSL = 1 ;
126+ mongoc_opts . MONGOC_ENABLE_CRYPTO_LIBCRYPTO = 1 ;
127+ mongoc_opts . MONGOC_ENABLE_SSL = 1 ;
128+ mongoc_opts . MONGOC_ENABLE_CRYPTO = 1 ;
129+ mongoc_opts . MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE = 1 ;
50130 } else {
51131 WARNING ( "mongodb libopenssl support not enabled, libs not found" ) ;
52- AC_DEFINE ( "MONGOC_ENABLE_SSL_OPENSSL" , 0 ) ;
53- AC_DEFINE ( "MONGOC_ENABLE_CRYPTO_LIBCRYPTO" , 0 ) ;
54- AC_DEFINE ( "MONGOC_ENABLE_SSL" , 0 ) ;
55- AC_DEFINE ( "MONGOC_ENABLE_CRYPTO" , 0 ) ;
56- AC_DEFINE ( "MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE" , 0 ) ;
57132 }
58133
59- // Secure Transport does not apply to Windows
60- AC_DEFINE ( "MONGOC_ENABLE_SSL_SECURE_TRANSPORT" , 0 ) ;
61- AC_DEFINE ( "MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO" , 0 ) ;
62-
63- // TODO: Support building with Secure Channel on Windows
64- AC_DEFINE ( "MONGOC_ENABLE_SSL_SECURE_CHANNEL" , 0 )
65- AC_DEFINE ( "MONGOC_ENABLE_CRYPTO_CNG" , 0 )
66-
67134 if ( PHP_MONGODB_SASL != "no" &&
68135 CHECK_LIB ( "libsasl.lib" , "mongodb" , PHP_MONGODB ) &&
69136 CHECK_HEADER_ADD_INCLUDE ( "sasl/sasl.h" , "CFLAGS_MONGOC" ) ) {
70- AC_DEFINE ( "MONGOC_ENABLE_SASL" , 1 ) ;
71- AC_DEFINE ( "MONGOC_HAVE_SASL_CLIENT_DONE" , CHECK_FUNC_IN_HEADER ( "sasl/sasl.h" , "sasl_client_done" ) ? 1 : 0 ) ;
137+ mongoc_opts . MONGOC_ENABLE_SASL = 1 ;
138+ if ( CHECK_FUNC_IN_HEADER ( "sasl/sasl.h" , "sasl_client_done" ) ) {
139+ mongoc_opts . MONGOC_HAVE_SASL_CLIENT_DONE = 1 ;
140+ }
72141 } else {
73142 WARNING ( "mongodb libsasl support not enabled, libs not found" ) ;
74- AC_DEFINE ( "MONGOC_ENABLE_SASL" , 0 ) ;
75- AC_DEFINE ( "MONGOC_HAVE_SASL_CLIENT_DONE" , 0 ) ;
76143 }
77144
78- FSO . CopyFile ( configure_module_dirname + "/win32/bson-config.h" , configure_module_dirname + "/src/libbson/src/bson/bson-config.h" , true ) ;
79- FSO . CopyFile ( configure_module_dirname + "/win32/bson-version.h" , configure_module_dirname + "/src/libbson/src/bson/bson-version.h" , true ) ;
80- FSO . CopyFile ( configure_module_dirname + "/win32/mongoc-config.h" , configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-config.h" , true ) ;
81- FSO . CopyFile ( configure_module_dirname + "/win32/mongoc-version.h" , configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-version.h" , true ) ;
145+ mongodb_generate_header (
146+ configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-config.h.in" ,
147+ configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-config.h" ,
148+ mongoc_opts
149+ ) ;
150+
151+ mongodb_generate_header (
152+ configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-version.h.in" ,
153+ configure_module_dirname + "/src/libmongoc/src/mongoc/mongoc-version.h" ,
154+ mongodb_parse_version_file ( configure_module_dirname + "/src/libmongoc/VERSION_CURRENT" , "MONGOC_" )
155+ ) ;
82156}
83157
0 commit comments