1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # Makefile to compile up the OWASP-for-C package after first compiling up its dependencies
|
---|
4 | # The OWASP-for-C package:
|
---|
5 | # http://code.google.com/p/owasp-esapi-c/
|
---|
6 | # http://owasp-esapi-c.googlecode.com/svn/trunk/doc/html/index.html
|
---|
7 | # 3 of its Makefiles were changed to get things compiling: top level, src and example folders
|
---|
8 |
|
---|
9 | # unpack everything
|
---|
10 | # (svn checkout owasp-for-c? or commit as a directory to gs?)
|
---|
11 | # put uthash/src/* into owasp-for-c/include/.
|
---|
12 | # create 'installed' folder
|
---|
13 | # compile everything (or at least all the dependencies) into the installed folder, compile owasp
|
---|
14 |
|
---|
15 | securitydir=`pwd`
|
---|
16 | installdir=$securitydir/installed
|
---|
17 |
|
---|
18 | LIBGPGERROR=libgpg-error-1.12
|
---|
19 | LIBGCRYPT=libgcrypt-1.6.1
|
---|
20 | LOG4C=log4c-1.2.4
|
---|
21 | UTHASH=uthash-master
|
---|
22 | OWASPC=gs_owasp-esapi-c_27.02.2014
|
---|
23 | # svn checkout http://owasp-esapi-c.googlecode.com/svn/trunk/ owasp-esapi-c-read-only
|
---|
24 |
|
---|
25 |
|
---|
26 | # If doing tarclean: then get rid of all the extracted folders and the installed folder
|
---|
27 | if [ "x$1" = "xtarclean" ]; then
|
---|
28 | folders="$LIBGPGERROR $LIBGCRYPT $LOG4C $UTHASH $OWASPC $installdir"
|
---|
29 | for folder in $folders; do
|
---|
30 | if [ -d $folder ]; then
|
---|
31 | rm -rf $folder
|
---|
32 | fi
|
---|
33 | done
|
---|
34 | exit
|
---|
35 | fi
|
---|
36 |
|
---|
37 |
|
---|
38 | # make the installed folder
|
---|
39 | if [ ! -e $installdir ]; then
|
---|
40 | mkdir $installdir
|
---|
41 | fi
|
---|
42 |
|
---|
43 |
|
---|
44 | # UNPACK
|
---|
45 | bziplist="$LIBGPGERROR $LIBGCRYPT $OWASPC $UTHASH"
|
---|
46 | for bzip in $bziplist; do
|
---|
47 | if test ! -d "$bzip" ; then
|
---|
48 | tar xvjf $bzip.tar.bz2
|
---|
49 | fi
|
---|
50 | done
|
---|
51 | if test ! -d "$LOG4C" ; then
|
---|
52 | tar xvzf $LOG4C.tar.gz
|
---|
53 | fi
|
---|
54 | #cp $UTHASH/src/* $OWASPC/include/.
|
---|
55 |
|
---|
56 |
|
---|
57 | # If doing a make clean or distclean
|
---|
58 | pkglist=
|
---|
59 | if [ "x$1" != "x" ]; then
|
---|
60 | pkglist="$LIBGPGERROR $LIBGCRYPT $OWASPC $LOG4C"
|
---|
61 | for d in $pkglist; do
|
---|
62 | cd $d
|
---|
63 | make $1
|
---|
64 | cd $securitydir
|
---|
65 | done
|
---|
66 | exit 0
|
---|
67 | fi
|
---|
68 |
|
---|
69 | # COMPILE DEPENDENCIES
|
---|
70 | # The dependencies of OWASP are LIBGCRYPT, LOG4C and UTHASH.
|
---|
71 | # The last is just header files that gets copied over into the src folder
|
---|
72 | # LIBGCRYPT is dependent on LIBGPGERROR, so that needs to be compiled up first
|
---|
73 |
|
---|
74 | pkglist="$LIBGPGERROR $LIBGCRYPT $LOG4C"
|
---|
75 | for d in $pkglist; do
|
---|
76 | echo " Compiling $d"
|
---|
77 |
|
---|
78 | cd $d
|
---|
79 |
|
---|
80 |
|
---|
81 | # configure, but only if we haven't already
|
---|
82 | if [ ! -e Makefile ] && [ ! -e config.h ] ; then
|
---|
83 |
|
---|
84 | # if we're making static libraries (.a) files in the lib folder, add --disable-shared to the configure step
|
---|
85 | # if we're making .so (shared object files/dlls) in the lib folder, then remove --disable-shared from configure
|
---|
86 |
|
---|
87 | if [ "$d" = "$LIBGCRYPT" ]; then
|
---|
88 | ./configure --with-gpg-error-prefix=$installdir --prefix=$installdir --disable-shared
|
---|
89 | else
|
---|
90 | ./configure --prefix=$installdir --disable-shared
|
---|
91 | fi
|
---|
92 | fi
|
---|
93 |
|
---|
94 | if [ $? != 0 ] ; then
|
---|
95 | echo "Error encountered when configuring $d"
|
---|
96 | exit 1
|
---|
97 | fi
|
---|
98 |
|
---|
99 | # make
|
---|
100 | make
|
---|
101 | if [ $? != 0 ] ; then
|
---|
102 | echo "Error encountered making $d"
|
---|
103 | exit 1
|
---|
104 | fi
|
---|
105 |
|
---|
106 | # make install
|
---|
107 | make install
|
---|
108 | if [ $? != 0 ] ; then
|
---|
109 | echo "Error encountered when installing $d"
|
---|
110 | exit 1
|
---|
111 | fi
|
---|
112 |
|
---|
113 | cd $securitydir
|
---|
114 | done
|
---|
115 |
|
---|
116 | # COMPILE OWASP ESAPI for C
|
---|
117 | echo " Compiling $OWASPC"
|
---|
118 |
|
---|
119 | cd $OWASPC/
|
---|
120 | CFLAGS=-I$installdir/include LDFLAGS=-L$installdir/lib prefix=$installdir make
|
---|
121 | CFLAGS=-I$installdir/include LDFLAGS=-L$installdir/lib prefix=$installdir make install
|
---|
122 | #CFLAGS=-I$installdir/include LDFLAGS=-L$installdir/lib prefix=$installdir make examples
|
---|
123 | cd $securitydir
|
---|
124 |
|
---|
125 | # To get the OWASP example working, need to compile manually in the example folder,
|
---|
126 | # since the above 'make examples' command does not work
|
---|
127 |
|
---|
128 | # make examples does the following (all on one line):
|
---|
129 |
|
---|
130 | #/.../security/owasp-esapi-c_27.02.2014/example>cc -I$installdir/include
|
---|
131 | #-O0 -g3 -ggdb -DDEBUG=1 -std=c99 -Wall -Wextra -Wno-unused -Wformat=2 -Wformat-security -fstack-protector-all -pedantic -c -static
|
---|
132 | #-I../include -I../../include access_ref_example.c -o access_ref_example -L../lib -L$installdir/lib
|
---|
133 | #-Wl,-z,nodlopen -Wl,-z,nodldump -Wl,-z,relro -Wl,-z,now
|
---|
134 | #-lesapi -lgcrypt -lgpg-error -llog4c
|
---|
135 |
|
---|
136 | # while the following works (run all on one line):
|
---|
137 |
|
---|
138 | #/.../security/owasp-esapi-c_27.02.2014/example>cc -I$installdir/include
|
---|
139 | #-I../include -I../../include access_ref_example.c -o access_ref_example -L../lib -L$installdir/lib
|
---|
140 | #-lesapi -lgcrypt -lgpg-error -llog4c |
---|