#----------------------------------------------------------------------------
# build_libsrs2.txt - how to build the binaries and create folder and
#                     packages
#
# Creation   : 2012-01-06 jed
# Last update: $Id: $
#
# !!! this is not a script but an step-by-step howto !!!
#------------------------------------------------------------------------------
exit 1

### download the source code from the internet, e.g.
wget http://www.libsrs2.org/srs/libsrs2-1.0.18.tar.gz

### extract file in a temporary location
tar -xzvf libsrs2-1.0.18.tar.gz

cd libsrs2-1.0.18

1. ./configure --prefix=/usr --enable-perl

2. make


1. ./configure --prefix=/usr

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... yes
checking for working aclocal-1.4... missing
checking for working autoconf... found
checking for working automake-1.4... missing
checking for working autoheader... found
checking for working makeinfo... found
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for AIX... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ANSI C... (cached) none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... (cached) yes
checking for ranlib... ranlib
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /usr/bin/sed
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for epcf90... no
checking for f95... no
checking for fort... no
checking for xlf95... no
checking for ifc... no
checking for efc... no
checking for pgf95... no
checking for lf95... no
checking for gfortran... no
checking whether we are using the GNU Fortran 77 compiler... no
checking whether  accepts -g... no
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... (cached) ranlib
checking for strip... strip
checking if gcc static flag  works... yes
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc supports -c -o file.o... yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
configure: creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
appending configuration tag "F77" to libtool
checking for strerror in -lcposix... no
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for pid_t... yes
checking for size_t... yes
checking for working volatile... yes
checking whether byte ordering is bigendian... no
checking for inline... (cached) inline
checking whether char is unsigned... no
checking for int... yes
checking size of int... 4
checking for unsigned long... yes
checking size of unsigned long... 4
checking for ANSI C header files... (cached) yes
checking for strings.h... (cached) yes
checking time.h usability... yes
checking time.h presence... yes
checking for time.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for sys/types.h... (cached) yes
checking for unistd.h... (cached) yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking stdarg.h usability... yes
checking stdarg.h presence... yes
checking for stdarg.h... yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking alloca.h usability... yes
checking alloca.h presence... yes
checking for alloca.h... yes
checking for inet_pton in -lnsl... yes
checking for socket in -lsocket... no
checking for gethostbyname in -lresolv... yes
checking for an ANSI C-conforming const... (cached) yes
checking for size_t... (cached) yes
checking whether time.h and sys/time.h may both be included... yes
checking for strdup... yes
checking for strstr... yes
checking for alloca... no
checking for strcasecmp... yes
checking for strncasecmp... yes
checking for _alloca... no
checking for _stricmp... no
checking for _strnicmp... no
checking for getopt_long... yes
configure: creating ./config.status
config.status: creating libsrs2/Makefile
config.status: creating tools/Makefile
config.status: creating Makefile
config.status: creating config.h
config.status: executing default-1 commands

2. make

make  all-recursive
make[1]: Entering directory `/soft/libsrs2-1.0.18'
Making all in libsrs2
make[2]: Entering directory `/soft/libsrs2-1.0.18/libsrs2'
gcc -DHAVE_CONFIG_H -I. -I. -I..     -Wall -g -O2 -c srs2.c
gcc -DHAVE_CONFIG_H -I. -I. -I..     -Wall -g -O2 -c sha1.c
sha1.c: In function 'sha_digest':
sha1.c:360: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:361: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
sha1.c: In function 'srs_hmac_init':
sha1.c:386: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c: In function 'srs_hmac_update':
sha1.c:392: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c: In function 'srs_hmac_fini':
sha1.c:400: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
sha1.c:402: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:403: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:404: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
rm -f libsrs2.a
ar cru libsrs2.a srs2.o sha1.o 
ranlib libsrs2.a
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I..     -Wall -g -O2 -c srs2.c
mkdir .libs
gcc -DHAVE_CONFIG_H -I. -I. -I.. -Wall -g -O2 -c srs2.c  -fPIC -DPIC -DPIC -o srs2.o
mv -f srs2.o .libs/srs2.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -Wall -g -O2 -c srs2.c -o srs2.o >/dev/null 2>&1
mv -f .libs/srs2.lo srs2.lo
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I..     -Wall -g -O2 -c sha1.c
rm -f .libs/sha1.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -Wall -g -O2 -c sha1.c  -fPIC -DPIC -DPIC -o sha1.o
sha1.c: In function 'sha_digest':
sha1.c:360: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:361: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
sha1.c: In function 'srs_hmac_init':
sha1.c:386: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c: In function 'srs_hmac_update':
sha1.c:392: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c: In function 'srs_hmac_fini':
sha1.c:400: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
sha1.c:402: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:403: warning: pointer targets in passing argument 2 of 'sha_update' differ in signedness
sha1.c:404: warning: pointer targets in passing argument 1 of 'sha_final' differ in signedness
mv -f sha1.o .libs/sha1.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -Wall -g -O2 -c sha1.c -o sha1.o >/dev/null 2>&1
mv -f .libs/sha1.lo sha1.lo
/bin/sh ../libtool --mode=link gcc  -Wall -g -O2  -o libsrs2.la -rpath /usr/lib -version-info 0:0:0 srs2.lo sha1.lo  -lresolv -lnsl 
rm -fr .libs/libsrs2.la .libs/libsrs2.* .libs/libsrs2.*
gcc -shared  srs2.lo sha1.lo  -lresolv -lnsl  -Wl,-soname -Wl,libsrs2.so.0 -o .libs/libsrs2.so.0.0.0
(cd .libs && rm -f libsrs2.so.0 && ln -s libsrs2.so.0.0.0 libsrs2.so.0)
(cd .libs && rm -f libsrs2.so && ln -s libsrs2.so.0.0.0 libsrs2.so)
ar cru .libs/libsrs2.a  srs2.o sha1.o 
ranlib .libs/libsrs2.a
creating libsrs2.la
(cd .libs && rm -f libsrs2.la && ln -s ../libsrs2.la libsrs2.la)
make[2]: Leaving directory `/soft/libsrs2-1.0.18/libsrs2'
Making all in tools
make[2]: Entering directory `/soft/libsrs2-1.0.18/tools'
gcc -DHAVE_CONFIG_H -I. -I. -I..     -g -Wall -g -O2 -c srs.c
/bin/sh ../libtool --mode=link gcc  -g -Wall -g -O2  -o srs  srs.o -L../libsrs2 -lsrs2 -lresolv -lnsl 
mkdir .libs
gcc -g -Wall -g -O2 -o .libs/srs srs.o  -L/soft/libsrs2-1.0.18/libsrs2 /soft/libsrs2-1.0.18/libsrs2/.libs/libsrs2.so -lresolv -lnsl
creating srs
make[2]: Leaving directory `/soft/libsrs2-1.0.18/tools'
make[2]: Entering directory `/soft/libsrs2-1.0.18'
make[2]: Leaving directory `/soft/libsrs2-1.0.18'
make[1]: Leaving directory `/soft/libsrs2-1.0.18'

3. make test

make: *** No rule to make target `test'.  Stop.

4. export DESTDIR=/public/libsrs2-1.0.18; make install >>./jed_conf 2>>./jed_conf

Making install in libsrs2
make[1]: Entering directory `/soft/libsrs2-1.0.18/libsrs2'
rm -f libsrs2.a
ar cru libsrs2.a srs2.o sha1.o 
ranlib libsrs2.a
make[2]: Entering directory `/soft/libsrs2-1.0.18/libsrs2'
/bin/sh ../mkinstalldirs /usr/lib
 /usr/bin/install -c -m 644 libsrs2.a /usr/lib/libsrs2.a
 ranlib /usr/lib/libsrs2.a
/bin/sh ../mkinstalldirs /usr/lib
/bin/sh ../libtool  --mode=install /usr/bin/install -c libsrs2.la /usr/lib/libsrs2.la
/usr/bin/install -c .libs/libsrs2.so.0.0.0 /usr/lib/libsrs2.so.0.0.0
(cd /usr/lib && rm -f libsrs2.so.0 && ln -s libsrs2.so.0.0.0 libsrs2.so.0)
(cd /usr/lib && rm -f libsrs2.so && ln -s libsrs2.so.0.0.0 libsrs2.so)
/usr/bin/install -c .libs/libsrs2.lai /usr/lib/libsrs2.la
/usr/bin/install -c .libs/libsrs2.a /usr/lib/libsrs2.a
ranlib /usr/lib/libsrs2.a
chmod 644 /usr/lib/libsrs2.a
PATH="$PATH:/sbin" ldconfig -n /usr/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/sh ../mkinstalldirs /usr/include
 /usr/bin/install -c -m 644 srs2.h /usr/include/srs2.h
make[2]: Leaving directory `/soft/libsrs2-1.0.18/libsrs2'
make[1]: Leaving directory `/soft/libsrs2-1.0.18/libsrs2'
Making install in tools
make[1]: Entering directory `/soft/libsrs2-1.0.18/tools'
make[2]: Entering directory `/soft/libsrs2-1.0.18/tools'
/bin/sh ../mkinstalldirs /usr/bin
 /bin/sh ../libtool  --mode=install /usr/bin/install -c  srs /usr/bin/srs
/usr/bin/install -c .libs/srs /usr/bin/srs
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/soft/libsrs2-1.0.18/tools'
make[1]: Leaving directory `/soft/libsrs2-1.0.18/tools'
make[1]: Entering directory `/soft/libsrs2-1.0.18'
make[2]: Entering directory `/soft/libsrs2-1.0.18'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/soft/libsrs2-1.0.18'
make[1]: Leaving directory `/soft/libsrs2-1.0.18'

5. mkdir -p /public/libsrs2-1.0.18/usr/bin
   mkdir -p /public/libsrs2-1.0.18/usr/bin/doc
   mkdir -p /public/libsrs2-1.0.18/usr/include
   mkdir -p /public/libsrs2-1.0.18/usr/lib

   cp /usr/bin/srs /public/libsrs2-1.0.18/usr/bin/
   cp AUTHORS       /public/libsrs2-1.0.18/usr/bin/doc/
   cp COPYING       /public/libsrs2-1.0.18/usr/bin/doc/
   cp INSTALL       /public/libsrs2-1.0.18/usr/bin/doc/
   cp LICENSE.GPL-2 /public/libsrs2-1.0.18/usr/bin/doc/
   cp NEWS          /public/libsrs2-1.0.18/usr/bin/doc/
   cp README        /public/libsrs2-1.0.18/usr/bin/doc/
   cp /usr/include/srs2.h /public/libsrs2-1.0.18/usr/include/
   cp /usr/lib/libsrs2.a        /public/libsrs2-1.0.18/usr/lib/
   cp /usr/lib/libsrs2.la       /public/libsrs2-1.0.18/usr/lib/
   cp /usr/lib/libsrs2.so.0.0.0 /public/libsrs2-1.0.18/usr/lib/

   strip -s /public/libsrs2-1.0.18/usr/bin/srs
   strip -s /public/libsrs2-1.0.18/usr/lib/libsrs2.a
   strip -s /public/libsrs2-1.0.18/usr/lib/libsrs2.so.0.0.0

======================
 Compile Perl module
======================

1. perl Makefile.PL

perl Makefile.PL
Checking if your kit is complete...
Looks good
Warning: -L../libsrs2/.libs changed to
-L/soft/libsrs2-1.0.18/perl/../libsrs2/.libs
Writing Makefile for Mail::SRS_XS

2. make

cp SRS_XS.pm blib/lib/Mail/SRS_XS.pm
/usr/bin/perl5.12.0 /usr/lib/perl5/5.12.0/ExtUtils/xsubpp  -typemap
/usr/lib/perl5/5.12.0/ExtUtils/typemap -typemap typemap  SRS_XS.xs >
SRS_XS.xsc && mv SRS
_XS.xsc SRS_XS.c
cc -c   -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -DPERL_US
E_SAFE_PUTENV -DHAVE_CONFIG_H   -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\"
-fPIC "-I/usr/lib/perl5/5.12.0/i686-linux-thread-multi/CORE"   SRS_XS.c
Running Mkbootstrap for Mail::SRS_XS ()
chmod 644 SRS_XS.bs
rm -f blib/arch/auto/Mail/SRS_XS/SRS_XS.so
LD_RUN_PATH="/soft/libsrs2-1.0.18/perl/../libsrs2/.libs" cc  -shared -O2
SRS_XS.o  -o blib/arch/auto/Mail/SRS_XS/SRS_XS.so      \
   -L/soft/libsrs2-1.0.18/perl/../libsrs2/.libs -lsrs2          \

chmod 755 blib/arch/auto/Mail/SRS_XS/SRS_XS.so
cp SRS_XS.bs blib/arch/auto/Mail/SRS_XS/SRS_XS.bs
chmod 644 blib/arch/auto/Mail/SRS_XS/SRS_XS.bs

3. make test

PERL_DL_NONLAZY=1 /usr/bin/perl5.12.0 "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01load.t ........ ok
t/02constants.t ... ok
t/03basic.t ....... ok
t/05forward.t ..... ok
fwd1 = SRS0=izJH=7R=hosta.com=usera@hostb.com
rev1 = usera@hosta.com
fwd2 = SRS1=ocBS=hostb.com==izJH=7R=hosta.com=usera@hostc.com
rev2 = SRS0=izJH=7R=hosta.com=usera@hostb.com
fwd3 = SRS1=ocBS=hostb.com==izJH=7R=hosta.com=usera@hostd.com
rev3 = SRS0=izJH=7R=hosta.com=usera@hostb.com
t/06reverse.t ..... ok
t/10regression.t .. ok
All tests successful.
Files=6, Tests=31,  0 wallclock secs ( 0.02 usr  0.02 sys +
0.18 cusr  0.02 csys =  0.24 CPU)
Result: PASS

4. ../../perl/perl-files.sh