jbsrc/lib/src/extras/jb-openssl.c (2969B) - raw
1 /*
2 * JB, the Jean-Yves Lefort's Build System
3 * Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <stdio.h>
21 #include "jb-tests.h"
22 #include "jb-variable.h"
23 #include "jb-util.h"
24
25 #define JB_OPENSSL_CFLAGS NULL
26 #define JB_OPENSSL_CPPFLAGS NULL
27 #define JB_OPENSSL_LDFLAGS NULL
28 #define JB_OPENSSL_LIBS "-lssl -lcrypto"
29
30 gboolean
31 jb_openssl_check (const char *minversion)
32 {
33 gboolean result;
34 char *cppflags;
35 int major;
36 int minor;
37 int fix;
38 int patch = 0;
39 char cpatch;
40
41 if (! minversion)
42 /* the OPENSSL_VERSION_NUMBER format we use appeared in 0.9.5b */
43 minversion = "0.9.5b";
44
45 jb_message_checking("for OpenSSL >= %s", minversion);
46
47 if (sscanf(minversion, "%d.%d.%d%c", &major, &minor, &fix, &cpatch) < 3)
48 g_error("invalid version string `%s'", minversion);
49 if (cpatch)
50 patch = cpatch - 96; /* letter -> number */
51
52 cppflags = g_strdup_printf("-DJB_OPENSSL_MAJOR=%i -DJB_OPENSSL_MINOR=%i -DJB_OPENSSL_FIX=%i -DJB_OPENSSL_PATCH=%i",
53 major, minor, fix, patch);
54
55 result = jb_test_run_string("#include <openssl/opensslv.h>\n"
56 "int main () {\n"
57 " if (OPENSSL_VERSION_NUMBER <\n"
58 " (JB_OPENSSL_MAJOR << 28)\n"
59 " + (JB_OPENSSL_MINOR << 20)\n"
60 " + (JB_OPENSSL_FIX << 12)\n"
61 " + (JB_OPENSSL_PATCH << 4))\n"
62 " exit(1); /* version too old */\n"
63 " exit(0); /* ok */\n"
64 "}\n",
65 JB_OPENSSL_CFLAGS,
66 cppflags,
67 JB_OPENSSL_LDFLAGS,
68 JB_OPENSSL_LIBS);
69
70 g_free(cppflags);
71
72 jb_message_result_bool(result);
73
74 if (result)
75 jb_variable_set_package_flags("openssl",
76 JB_OPENSSL_CFLAGS,
77 JB_OPENSSL_CPPFLAGS,
78 JB_OPENSSL_LDFLAGS,
79 JB_OPENSSL_LIBS);
80
81 return result;
82 }
83
84 gboolean
85 jb_openssl_check_mt (void)
86 {
87 gboolean result;
88
89 jb_message_checking("whether OpenSSL supports multi-threading");
90
91 result = jb_test_compile_string("#define OPENSSL_THREAD_DEFINES\n"
92 "#include <openssl/opensslconf.h>\n"
93 "int main () {\n"
94 "#ifndef OPENSSL_THREADS\n"
95 "#error \"no thread support\"\n"
96 "#endif\n"
97 "}\n",
98 JB_OPENSSL_CFLAGS,
99 JB_OPENSSL_CPPFLAGS);
100
101 jb_message_result_bool(result);
102
103 return result;
104 }