windows build: default is now --with-mbedtls
[privoxy.git] / windows / MYconfigure
1 #!/bin/sh
2 # run the configure script for a native Windows build
3
4 if [ -f ../configure.in ]; then
5    #  we're in the windows directory, so we need to go up a level
6    cd ..
7 fi
8
9 if [ ! -f configure ]; then
10    autoheader
11    #   creates config.h.in
12    autoconf
13    #   creates configure
14 fi
15
16 ####### configure options:
17 # --help                          Show configure options and a short description
18 #
19 # --host=i686-w64-mingw32         Use the mingw cross-compiler to build a 'native' windows binary
20 # --enable-mingw32                Use mingw32 for a Windows GUI
21 # --enable-static-linking         Use static linking instead of dynamic linking (and not have
22 #                                 to put all the .DLLs in the path or the same dir as Privoxy)
23 # --disable-pthread               Use native threads instead of POSIX pthreads library
24 # --disable-dynamic-pcre          Use the built-in, static pcre, even if libpcre is available
25 # --with-docbook=yes              Enable docbook documentation creation
26
27
28 export CFLAGS="-O2"
29 # note: configure.in line 155
30 #         if test "X$CFLAGS" = "X "; then # if CFLAGS were unset (see above)
31 #   In other words, if you set CFLAGS you need to include -O2 if you want optimization
32 #   assume I'll set cflags below, so set O2 now
33
34 export CPPFLAGS=""
35 # start with initially empty flags
36
37 export LDFLAGS=""
38 # start with initially empty flags
39
40
41 CFLAGS="${CFLAGS} -fstack-protector-strong -D_FORTIFY_SOURCE=2"
42 LDFLAGS="${LDFLAGS} -fstack-protector-strong"
43 # -fstack-protector-strong:  enable stack checking.
44 # NOTE: need to specify when compiling _and_ linking
45 # stack-protector-strong: better balance between security and performance.
46 #   This flag protects more kinds of vulnerable functions than -fstack-protector does,
47 #   but not every function, providing better performance than -fstack-protector-all.
48 # see : https://en.wikipedia.org/wiki/Buffer_overflow_protection
49 # NOTE: needs static linking or the following in the path:
50 #         /usr/i686-w64-mingw32/sys-root/mingw/bin/libssp-0.dll
51 #
52 # -D_FORTIFY_SOURCE:  detect some buffer overflow errors
53 #     ***>> requires compiler optimization level 1 or above <<***
54 # see : https://gcc.gnu.org/legacy-ml/gcc-patches/2004-09/msg02055.html
55 #   The diffence between -D_FORTIFY_SOURCE=1 and -D_FORTIFY_SOURCE=2 is e.g. for
56 #     struct S { struct T { char buf[5]; int x; } t; char buf[20]; } var;
57 #   With -D_FORTIFY_SOURCE=1,
58 #     strcpy (&var.t.buf[1], "abcdefg");
59 #   is not considered an overflow (object is whole VAR), while with -D_FORTIFY_SOURCE=2
60 #     strcpy (&var.t.buf[1], "abcdefg");
61 #   will be considered a buffer overflow.
62
63 ### CFLAGS="${CFLAGS} -march=native"
64 # -march=cpu-type
65 #   Generate instructions for the machine type cpu-type.  In contrast to -mtune=cpu-type, which merely tunes the
66 #   generated code for the specified cpu-type, -march=cpu-type allows GCC to generate code that may not run at all on
67 #   processors other than the one indicated.
68 #   Specifying -march=cpu-type implies -mtune=cpu-type.
69 #
70 # -march=native
71 #   This selects the CPU to generate code for at compilation time by determining the processor type of the compiling
72 #   machine.  Using -march=native enables all instruction subsets supported by the local machine (hence the result
73 #   might not run on different machines).  Using -mtune=native produces code optimized for the local machine under
74 #   the constraints of the selected instruction set.
75
76 LDFLAGS="${LDFLAGS} -Wl,--nxcompat"
77 # https://en.wikipedia.org/wiki/Data_Execution_Prevention
78 #   Enable DEP with -Wl,--nxcompat
79
80 LDFLAGS="${LDFLAGS} -Wl,--dynamicbase,--export-all-symbols"
81 # https://en.wikipedia.org/wiki/Address_space_layout_randomization
82 # https://stackoverflow.com/questions/24283918/how-can-i-enable-aslr-dep-and-safeseh-on-an-exe-in-codeblocks-using-mingw
83 #   ASLR with gcc has a problem: -Wl,--dynamicbase doesn't emit the necessary relocation table.
84 #   As a workaround, you can pass -Wl,--dynamicbase,--export-all-symbols
85 #   NOTE: you can't have both this and profiling (cflags='-pg') enabled!
86
87 CFLAGS="${CFLAGS} -Wall"
88 # see: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
89 # -Wall   doesn't actually turn on all warnings, so add  -Wextra
90 #    but then plenty too many complaints by
91 #      -Wimplicit-fallthrough=3
92 #         too many warnings in pcre/study.c & pcre.c
93 #      -Wmissing-field-initializers
94 #      -Wsign-compare
95 #      -Wtype-limits
96 #      -Wunused-but-set-parameter
97 #      -Wunused-but-set-variable
98 CFLAGS="${CFLAGS} -Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wno-type-limits"
99 CFLAGS="${CFLAGS} -Wno-unused-parameter -Wno-unused-but-set-variable"
100
101 #-no-# CFLAGS="${CFLAGS} -Wconversion"
102 #   way too many warnings for things that don't look like a problem
103
104 #-no-# CFLAGS="${CFLAGS} -Werror"
105 # Turn all warnings into errors.
106 #   Privoxy still has a few warnings that are not a problem
107
108 CFLAGS="${CFLAGS} -Wformat=2"
109 # -Wformat is enabled by -Wall.
110 # -Wformat=2 is equivalent to -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k
111 #   -Wformat-security : also warn about uses of format functions that represent possible security problems.
112
113 CFLAGS="${CFLAGS} -Wlogical-op"
114 # Warn about suspicious uses of logical operators in expressions.
115
116 CFLAGS="${CFLAGS} -Wshadow"
117 # Warn whenever a local variable or type declaration shadows
118 # another variable or whenever a built-in function is shadowed.
119
120 #-no-# CFLAGS="${CFLAGS} -Wwrite-strings"
121 # These warnings help you find at compile time code that can try to write
122 # into a string constant, but only if you have been very careful about
123 # using const in declarations and prototypes.
124 # >>> Otherwise, it is just a nuisance. <<<  -- this, very much this
125
126 # why does the mingw library _not_ include .a files for libpcre?
127 # *sigh* build my own pcre so I can do static linking
128 # Get the 8.x PCRE library from  https://ftp.pcre.org/pub/pcre/
129 inc="/source/pcre-8.44/"
130 lib="/source/pcre-8.44/.libs"
131 CPPFLAGS="${CPPFLAGS} -I${inc}"
132 LDFLAGS="${LDFLAGS} -L${lib}"
133
134 # mbedtls
135 # Get the 2.16.x mbedtls library from  https://github.com/ARMmbed/mbedtls/tags
136 inc="/source/mbedtls-2.16.9/include"
137 lib="/source/mbedtls-2.16.9/library"
138 MITMOPT="--with-mbedtls"
139 CPPFLAGS="${CPPFLAGS} -I${inc}"
140 LDFLAGS="${LDFLAGS} -L${lib}"
141
142 echo "CFLAGS=${CFLAGS}"
143 echo "CPPFLAGS=${CPPFLAGS}"
144 echo "LDFLAGS=${LDFLAGS}"
145
146 # ./configure cross-compilation options:
147 #    --build: the system on which the program will be built.
148 #    --host:  the system on which the generated program will run.
149 #    --target: only used to build a cross-compiling toolchain.
150
151 ./configure  --host=i686-w64-mingw32  --enable-mingw32  --enable-zlib \
152              --enable-static-linking \
153              --enable-strptime-sanity-checks \
154              --disable-pthread  \
155              --enable-extended-statistics \
156              --enable-pcre-host-patterns \
157              --with-docbook=yes
158
159 #  -- done --