# ------------ Barunson instructions, edits by Karmel ------------
# Necessary software downloads ## updated 18.04.18 ### some errors in compiling apr, use new version ####
cd /usr/local
wget https://www.samba.org/ftp/ccache/ccache-3.4.2.tar.gz
wget https://botan.randombit.net/releases/Botan-1.10.17.tgz
wget http://www-eu.apache.org/dist//apr/apr-1.6.3.tar.gz
wget http://www-eu.apache.org/dist//apr/apr-util-1.6.1.tar.gz
wget http://archive.apache.org/dist/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.tar.gz
wget http://downloads.sourceforge.net/project/jsoncpp/jsoncpp/0.6.0-rc2/jsoncpp-src-0.6.0-rc2.tar.gz
wget https://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz
wget http://ftp.ps.pl/pub/apache/subversion/subversion-1.10.0.tar.gz
wget https://curl.haxx.se/download/curl-7.59.0.tar.gz
wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz
#wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
tar xvzf ccache-3.4.2.tar.gz
tar xvzf Botan-1.10.17.tgz
tar xvzf apr-1.6.3.tar.gz
tar xvzf apr-util-1.6.1.tar.gz
tar xvzf apache-log4cxx-0.10.0.tar.gz
tar xvzf jsoncpp-src-0.6.0-rc2.tar.gz
tar xvzf sqlite-autoconf-3230100.tar.gz
tar xvzf subversion-1.10.0.tar.gz
tar xvzf curl-7.59.0.tar.gz
tar xvzf boost_1_65_1.tar.gz
#tar xvzf mysql-5.1.73.tar.gz
# _____________________________________________________
####### x64 unix #######
#export CFLAGS='-m32'
#export CC="gcc -m32"
#export CXX="g++ -m32"
####### x64 unix #######
cd /usr/local

# CentOS Update (optional)
yum -y upgrade

yum -y install python python-devel nano libtool
yum -y install gcc gcc-c++ gcc.i686 gcc-c++.i686
yum -y install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686 ncurses-devel.i686
yum -y install zlib zlib-devel zlib-devel.i686
yum -y install libidn-devel openldap-devel openssl-devel libidn-devel.i686 openldap-devel.i686 openssl-devel.i686
yum -y install svn
# ccache
cd ccache-3.4.2
./configure && make -j4 && make install

cd ..
# Botan library
cd Botan-1.10.17
./configure.py --disable-shared --includedir=../../usr/include
##_x64_##./configure.py --disable-shared --includedir=../../usr/include --cpu=x86_32 --cc-bin='gcc -m32'
######################### source edits
# nano src/hash/gost_3411/gost_3411.cpp
	#include <stdint.h>
make -j4 && make install
cp -R /usr/include/botan-1.10/botan /usr/include/

yum -y install expat expat-devel openldap openldap-devel expat.i686 expat-devel.i686 openldap.i686 openldap-devel.i686

cd ..
# Apache Portable Runtime
cd apr-1.6.3
./configure --prefix=/usr/local/apr-1.6.3 --enable-shared=no
make -j4 && make install
#ln -s /usr/local/apr-1.6.3 /usr/local/apr

cd ..
# Apache Portable Runtime Utility
cd apr-util-1.6.1
./configure --with-apr=/usr/local/apr-1.6.3 --with-expat=builtin
make -j4 && make install

cd ..
# Apache log4cxx
cd apache-log4cxx-0.10.0
./configure --enable-shared=no --enable-static=yes #--with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-util-1.6.1
##_x64_##./configure --enable-shared=no --enable-static=yes LDFLAGS="-L/usr/lib"
######################### source edits
# nano src/main/cpp/inputstreamreader.cpp
# nano src/main/cpp/socketoutputstream.cpp
# nano src/examples/cpp/console.cpp
	#include <stdio.h>
	#include <string.h>
make -j4 && make install

cd ..
# jsoncpp
cd jsoncpp-src-0.6.0-rc2
cd src/lib_json/
g++ -I../../include -O2 -c *.cpp
##_x64_##g++ -m32 -I../../include -O2 -c *.cpp
ar rs libjsoncpp.a *.o
cp libjsoncpp.a /usr/local/lib
cp -R ../../include/json /usr/local/include

cd ../../..
# Sqlite-autoconf
cd sqlite-autoconf-3230100
./configure && make -j4 && make install

cd ..
# Subversion
cd subversion-1.10.0
./configure --with-zlib #--with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-util-1.6.1
make -j4 && make install
# unreferenced 'dl*': compile with library: -ldl

cd ..
# ncurses-devel
yum -y install ncurses-devel

# curl
cd curl-7.59.0
./configure --enable-shared=no --libdir=/usr/local/lib
make -j4 && make install

cd ..
# Boost
cd boost_1_65_1
./bootstrap.sh
./b2 -j4 --toolset=gcc --build-type=complete --layout=versioned link=static threading=multi install
##_x64_##./bjam -j4 --toolset=gcc --build-type=complete --layout=versioned link=static threading=multi install cflags=-m32 cxxflags=-m32 address-model=32 threading=multi architecture=x86 instruction-set=i686 stage
#cp -R /usr/local/boost_1_65_1/boost /usr/include/
#ln -s -d /usr/local/boost_1_65_1/boost /usr/include/

## MySQL
#wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
#tar xvzf mysql-5.1.73.tar.gz
#cd mysql-5.1.73
#./configure --without-server --enable-static=yes --enable-shared=no --includedir=/usr/include --libdir=/usr/lib
#make -j4 && make install

yum -y install mysql mysql-devel mysql-devel.i686

# After installation, check below
#// yum list | grep expat
#// yum -y install expat-devel

cd /usr/local/lib
ln -s /usr/lib/libexpat.a

# ---------------------------
make -j8 -C ./ShareLib usa
make -j8 -C ./Connector usa
make -j8 -C ./Helper usa
make -j8 -C ./SubHelper usa
make -j8 -C ./Messenger usa
make -j8 -C ./LoginServer usa
make -j8 -C ./GameServer usadebug
# -------------------- Source edits --------------------
# makefile (change to your boost current version(1_65_1))
nano makefile.inc
	BOOST_INCLUDE = /usr/local/include/boost-1_65_1
	BOOST_LIB_VER = -gcc44-mt-d-1_65_1

# gameserver
nano GameServer/DBProcess_CreateChar.cpp
	#include <boost/scoped_ptr.hpp>
________________________________________
# config(optional) comment this lines(3, 39) by //
nano ShareLib/Config_Localize_USA.h
	#define SERVER_AUTHENTICATION
	#define XTRAP
