summaryrefslogtreecommitdiff
path: root/acprep
blob: 1788c5eb484a2658729d0823497096ee1f04b731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/sh

# acprep, version 3.0
#
# This script configures my ledger source tree on my Mac OS/X machine.  This
# is not necessary, however, since I keep all the files necessary for building
# checked in to the source tree.  Users can just type './configure && make'.
# This script simply sets up the compiler and linker flags for all the various
# build permutations I use for testing and profiling.

export AUTOCONF_VERSION=2.62
export AUTOMAKE_VERSION=1.10.1

touch AUTHORS COPYING ChangeLog

cmd=$(which glibtoolize 2>&1)
if [ -x "$cmd" ]; then
    export LIBTOOLIZE="$cmd"
fi

COMMIT=$(git describe --all --long | sed 's/heads\///')

cat version.m4.in | sed "s/%VERSION%/$COMMIT/" > version.m4

autoreconf --force --install


SWITCHES=""

INCDIRS="-isystem /usr/local/include"
INCDIRS="$INCDIRS -isystem /opt/local/include"
INCDIRS="$INCDIRS -isystem /usr/local/include/boost-1_35"

LIBDIRS="-L/usr/local/lib -L/opt/local/lib"
LDFLAGS=""

PYTHON_HOME="/usr"


SYSTEM=$(uname -s)

if [ $SYSTEM = Linux ]; then
    CXXFLAGS="-pthread"
elif [ $SYSTEM = Solaris ]; then
    CXXFLAGS="-pthreads"
elif [ $SYSTEM = Darwin ]; then
    CXXFLAGS=""
    #CXXFLAGS="-arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk"
    #LDFLAGS="$LDFLAGS -arch i386 -arch ppc -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
    #SWITCHES="$SWITCHES --disable-dependency-tracking"
else
    CXXFLAGS=""
fi

# Building the command-line tool as a shared library is a luxury,
# since there are no clients except a GUI tool which might use it (and
# that is built again anyway by Xcode).
CPPFLAGS="$INCDIRS"
CXXFLAGS="$CXXFLAGS -pipe"
LDFLAGS="$LDFLAGS $LIBDIRS"
LOCAL=false

# Warning flags
CXXFLAGS="$CXXFLAGS -Wall -ansi -Winvalid-pch"
CXXFLAGS="$CXXFLAGS -Wextra"
#CXXFLAGS="$CXXFLAGS -Weffc++"
CXXFLAGS="$CXXFLAGS -Wcast-align"
CXXFLAGS="$CXXFLAGS -Wcast-qual"
CXXFLAGS="$CXXFLAGS -Wconversion"
CXXFLAGS="$CXXFLAGS -Wfloat-equal"
CXXFLAGS="$CXXFLAGS -Wmissing-field-initializers"
CXXFLAGS="$CXXFLAGS -Wno-endif-labels"
CXXFLAGS="$CXXFLAGS -Wold-style-cast"
CXXFLAGS="$CXXFLAGS -Woverloaded-virtual"
CXXFLAGS="$CXXFLAGS -Wshorten-64-to-32"
CXXFLAGS="$CXXFLAGS -Wsign-compare"
CXXFLAGS="$CXXFLAGS -Wsign-promo"
CXXFLAGS="$CXXFLAGS -Wstrict-null-sentinel"
CXXFLAGS="$CXXFLAGS -Wwrite-strings"


# The following are options to prepare a developer tree of Ledger for
# building:
#
# --debug
#
#   Build with debugging information.  This doesn't slow things down by much,
#   but gives you useful stack traces to mention in your bug reports.
#   Recommended if you're not running a release version.
#
# --local
#
#   Prepare for building in the same directory as the sources.  This is
#   required for using pre-compiled headers with the --devel option (see
#   below).  Otherwise, if you have a directory named ~/Products, Ledger will
#   build itself there.  There's no option for changing that directory yet, so
#   just edit this script if you need to.
#
# --boost SUFFIX
#
#   Use the boost library with the given SUFFIX.  Check the Boost "Getting
#   Started" documentation for what the different suffixes are and what they
#   mean.  Usually you can see the available suffixes on your system using
#   something like this command:
#
#    $ ls /usr/local/lib/libboost_date_time*
#
#   Here's everything that's available on my machine right now:
#
#    ""      - dynamic optimized Boost library
#    d       - dynamic debug
#    s       - static optimized
#    sd      - static debug
#    mt      - multi-threaded optimized
#    mt-d    - multi-threaded debug
#    mt-s    - multi-threaded static optimized
#    mt-sd   - multi-threaded static debug
#
#   Since Ledger does not use threading, I recommend using the static
#   optimized library unless you wish to build with debugging enabled.  If you
#   want to do that, see the --devel switch below.
#
# --devel
#
#   This means you want to build like the developer does, which means:
#
#    * using pre-compiled headers
#    * with glibc debugging enabled
#    * static linking as much as possible
#
#   The glibc debugging is the only tricky part, since you must have Boost
#   compiled with _GLIBCXX_DEBUG defined also -- which it won't be on your
#   system by default.
#  
#   So, you have to roll your own set of Boost debug libraries in order to
#   support this.  I like this because it gives me the most amount of safety
#   and checking possible, which is great for testing.  Here's how I build a
#   super-debugging Boost:
#
#      src $ git clone git://repo.or.cz/boost.git
#      src $ git checkout -b v1.35.0 svn/Version_1_35_0
#      src $ cd boost
#    boost $ sudo bjam release --prefix=/usr/local/stow/boost_1_35_0 \
#                --build-dir=$HOME/Products/boost_1_35_0 --toolset=darwin \
#                architecture=combined install
#    boost $ sudo bjam debug --prefix=/usr/local/stow/boost_1_35_0 \
#                --build-dir=$HOME/Products/boost_1_35_0 --toolset=darwin \
#                architecture=combined define=_GLIBCXX_DEBUG=1 install
#    boost $ cd /usr/local/stow
#     stow $ stow boost_1_35_0
#
#   Of course, you'll need MacPorts to do this, with both the "bjam" and "stow"
#   packages installed.
#
#   Lastly, you need to build cppunit by hand with GLIBCXX_DEBUG also, or else
#   you'll see UniTests crash in flames and none of the unit tests will run.
#  
#   Now you're ready to run acprep like this:
#  
#    $ ./acprep --local --devel --debug --boost sd
#
#   Or, as I do it:
#
#    $ ./myacprep
#

while [ -n "$1" ]; do
  case "$1" in
    --devel)
	#SWITCHES="$SWITCHES --disable-shared --enable-pch"
	SWITCHES="$SWITCHES --disable-shared"
	# The use of this flag requires that Boost be also build with
	# _GLIBCXX_DEBUG.
	CPPFLAGS="$CPPFLAGS -D_GLIBCXX_DEBUG=1"
	#LDFLAGS="-Wl,-read_only_relocs,suppress"
	#LIBS=""
	#if [ -f /opt/local/lib/libexpat.a ]; then
	#    LIBS="$LIBS /opt/local/lib/libexpat.a"
	#fi
	#if [ -f /opt/local/lib/libgmp.a ]; then
	#    LIBS="$LIBS /opt/local/lib/libgmp.a"
	#fi
	#if [ -f /usr/lib/gcc/i686-apple-darwin9/4.2.1/libgcc_static.a ]; then
	#    LIBS="$LIBS /usr/lib/gcc/i686-apple-darwin9/4.2.1/libgcc_static.a"
	#fi
	shift 1 ;;

    --debug)
	SWITCHES="$SWITCHES --enable-debug"
	CPPFLAGS="$CPPFLAGS -DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING=1"
	CPPFLAGS="$CPPFLAGS -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE=1"
	CXXFLAGS="$CXXFLAGS -g"
	LDFLAGS="$LDFLAGS -g"
	shift 1 ;;
      
    --boost)
	shift 1
	SWITCHES="$SWITCHES --with-boost-suffix=$1"
	shift 1 ;;

    --gcov)
	CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
	shift 1 ;;

    --gprof)
        CXXFLAGS="$CXXFLAGS -g -pg"
	shift 1 ;;

    --python)
	if [ -d "$PYTHON_HOME" ]; then
	    SWITCHES="$SWITCHES --enable-python"
	    CPPFLAGS="$CPPFLAGS -I$PYTHON_HOME/include/python2.5"
	    LDFLAGS="$LDFLAGS -L$PYTHON_HOME/lib/python2.5/config"
	fi
	shift 1;;

    --pic)
	CXXFLAGS="$CXXFLAGS -fPIC"
	shift 1 ;;

    --opt)
	CXXFLAGS="$CXXFLAGS -fomit-frame-pointer -O3"
	shift 1 ;;

    --local)
	LOCAL=true
	shift 1 ;;

    *)
	break ;;
  esac
done


HERE="$PWD"

if [ "$LOCAL" = "false" -a -d "$HOME/Products" ]; then
    projdir="$HOME/Products/ledger"
    if [ ! -d "$projdir" ]; then
	mkdir -p "$projdir"
    fi
    cd "$projdir" || (echo "Cannot change to $projdir"; exit 1)
fi

"$HERE/configure" --srcdir="$HERE" CXX="$CXX" \
    CPPFLAGS="$CPPFLAGS" CXXFLAGS="$CXXFLAGS $local_cxxflags" \
    LDFLAGS="$LDFLAGS" LIBS="$LIBS" $SWITCHES "$@"

# Alter the Makefile so that it's not nearly so verbose.  This makes errors
# and warnings much easier to spot.

if [ -f Makefile ]; then
    perl -i -pe 's/^\t(\$\((LIBTOOL|CXX)\).*?\.cc)$/\t\@echo "   " CXX \$\@;$1 > \/dev\/null/;' Makefile
    perl -i -pe 's/^\tmv -f/\t\@mv -f/;' Makefile
    perl -i -pe 's/^\t(\$\((.*?)LINK\).*)/\t\@echo "   " LD \$\@;$1 > \/dev\/null/;' Makefile
fi