configure 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/bin/bash
  2. ## NOTE:
  3. ## I know this is not a clean way to check for some stuff
  4. ## and edit the Makefile, but hey, it does work!
  5. # Configure script for eAthena
  6. # Copyright (C) 2005 dontBR
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. # Default variables
  22. status_mmx="No"
  23. status_sse="No"
  24. status_sse2="No"
  25. status_sse3="No"
  26. status_pcre="No"
  27. prefix='/opt/eathena/'
  28. # Functions
  29. function check_sed {
  30. echo -n "Checking for sed... "
  31. if [ -f $(which sed) ]; then
  32. echo "yes"
  33. else
  34. echo "Error: sed not found in $PATH"
  35. exit 1
  36. fi
  37. }
  38. function check_gcc {
  39. echo -n "Checking for gcc... "
  40. if [ -f $(which gcc) ]; then
  41. echo "yes"
  42. else
  43. echo "Error: GCC not found in $PATH"
  44. exit 1
  45. fi
  46. }
  47. function check_make {
  48. echo -n "Checking for (g)make... "
  49. if [ -f $(which make) ]; then
  50. maker=make
  51. echo "yes"
  52. else if [ -f $(which gmake) ]; then
  53. maker=gmake
  54. echo "yes"
  55. else
  56. echo "Error: (g)make not found in $PATH"
  57. exit 1
  58. fi
  59. fi
  60. }
  61. function check_sockets {
  62. echo -n "Checking for sockets... "
  63. echo "#include <sys/types.h>
  64. #include <sys/socket.h>
  65. #include <netinet/in.h>
  66. int main(){
  67. }" > test_sockets.c
  68. if $(gcc test_sockets.c -o test_sockets); then
  69. echo "yes"
  70. rm -f test_sockets.c test_sockets
  71. else
  72. echo "Error: Unix sockets not found/working."
  73. exit 1
  74. rm -f test_sockets.c
  75. fi
  76. }
  77. function check_mysql_headers {
  78. echo -n "Checking for MySQL headers... "
  79. if [ -d /usr/local/lib/mysql ]; then # Default
  80. echo "yes"
  81. mysql_headers_path='/usr/local/lib/mysql'
  82. else
  83. if [ -d /usr/include/mysql ]; then # Gentoo/Debian/?
  84. echo "yes"
  85. mysql_headers_path='/usr/include/mysql'
  86. else
  87. echo "Error: MySQL headers not found."
  88. mysql_headers_path='Not found.'
  89. fi
  90. fi
  91. }
  92. function optimize {
  93. case $@ in
  94. mmx ) status_mmx="Yes" ;;
  95. sse ) status_sse="Yes" ;;
  96. sse2 ) status_sse2="Yes" ;;
  97. sse3 ) status_sse3="Yes" ;;
  98. all ) status_mmx="Yes"
  99. status_sse="Yes"
  100. status_sse2="Yes"
  101. status_sse3="Yes" ;;
  102. esac
  103. }
  104. function make_changes {
  105. if [ "$maker" != "make" ]; then
  106. sed -e 's,MAKE = make,MAKE = '$maker',g' Makefile -i
  107. fi
  108. if [ "$status_mmx" = "Yes" ]; then
  109. sed -e 's,# OPT += -mmmx,OPT += -mmmx,g' Makefile -i
  110. fi
  111. if [ "$status_sse" = "Yes" ]; then
  112. sed -e 's,# OPT += -msse,OPT += -msse,g' Makefile -i
  113. fi
  114. if [ "$status_sse2" = "Yes" ]; then
  115. sed -e 's,# OPT += -msse2,OPT += -msse2,g' Makefile -i
  116. fi
  117. if [ "$status_sse3" = "Yes" ]; then
  118. sed -e 's,# OPT += -msse3,OPT += -msse3,g' Makefile -i
  119. fi
  120. if [ "$status_pcre" = "Yes" ]; then
  121. sed -e 's,# OPT += -DPCRE_SUPPORT,OPT += -DPCRE_SUPPORT,g' Makefile -i
  122. fi
  123. if [ "$mysql_headers_path" != "/usr/local/lib/mysql" ] && [ "$mysql_headers_path" != "Not found." ]; then
  124. sed -e 's,LIBS += -L/usr/local/lib/mysql -lmysqlclient,LIBS += -L'$mysql_headers_path' -lmysqlclient,g' Makefile -i
  125. fi
  126. }
  127. function opt_check_pcre {
  128. echo -n "Checking for PCRE... "
  129. if [ -f /usr/local/lib/pcre.h ]; then
  130. echo "yes"
  131. status_pcre="Yes"
  132. else
  133. echo "Error: PCRE not found."
  134. status_pcre="No"
  135. fi
  136. }
  137. function make_report {
  138. echo "Configuration report:"
  139. echo eAthena
  140. echo
  141. echo Enable PCRE support..... : $status_pcre
  142. echo
  143. echo Enable MMX optimization. : $status_mmx
  144. echo Enable SSE optimization. : $status_sse
  145. echo Enable SSE2 optimization : $status_sse2
  146. echo Enable SSE3 optimization : $status_sse3
  147. echo
  148. echo MySQL headers path...... : $mysql_headers_path
  149. echo
  150. echo eAthena will be installed in $prefix
  151. echo Please type \'make txt\' or \'make sql\' now to compile eAthena.
  152. }
  153. function helptext {
  154. echo "eAthena Configure Script version 0.1"
  155. echo
  156. echo "Options:"
  157. echo
  158. echo " -h Display this help message and exit."
  159. echo " -d Enter debug mode."
  160. echo " -o Turn on optimization flags."
  161. echo " Supported:"
  162. echo " mmx"
  163. echo " sse"
  164. echo " sse2"
  165. echo " sse3"
  166. echo " all"
  167. echo " -e Enable PCRE support."
  168. echo " -p Root directory where eA is going to be installed."
  169. echo " DON'T FORGET THE LAST SLASH!"
  170. echo " For example:"
  171. echo " ./configure -p /usr/local/"
  172. echo " This will create /usr/local/bin/login-server,"
  173. echo " /usr/local/etc/eathena/save/account.txt, etc"
  174. echo " Default is /opt/eathena/"
  175. echo
  176. echo "Report bugs (about the configure script) to dontBR at the eAthena Support Board."
  177. }
  178. function make_installable {
  179. echo -e '' >> Makefile
  180. echo -e 'install: conf/%.conf conf/%.txt' >> Makefile
  181. echo -e ' $(shell mkdir -p '$prefix'bin/)' >> Makefile
  182. echo -e ' $(shell mkdir -p '$prefix'etc/eathena/)' >> Makefile
  183. echo -e ' $(shell mkdir -p '$prefix'var/log/eathena/)' >> Makefile
  184. echo -e ' $(shell mv save '$prefix'etc/eathena/save)' >> Makefile
  185. echo -e ' $(shell mv db '$prefix'etc/eathena/db)' >> Makefile
  186. echo -e ' $(shell mv conf '$prefix'etc/eathena/conf)' >> Makefile
  187. echo -e ' $(shell mv npc '$prefix'etc/eathena/npc)' >> Makefile
  188. echo -e ' $(shell mv log/* '$prefix'var/log/eathena/)' >> Makefile
  189. echo -e ' $(shell cp *-server* '$prefix'bin/)' >> Makefile
  190. echo -e ' $(shell cp ladmin '$prefix'bin/)' >> Makefile
  191. echo -e ' $(shell ln -s '$prefix'etc/eathena/save/ '$prefix'bin/)' >> Makefile
  192. echo -e ' $(shell ln -s '$prefix'etc/eathena/db/ '$prefix'bin/)' >> Makefile
  193. echo -e ' $(shell ln -s '$prefix'etc/eathena/conf/ '$prefix'bin/)' >> Makefile
  194. echo -e ' $(shell ln -s '$prefix'etc/eathena/npc/ '$prefix'bin/)' >> Makefile
  195. echo -e ' $(shell ln -s '$prefix'var/log/eathena/ '$prefix'bin/log)' >> Makefile
  196. echo '' >> Makefile
  197. echo -e 'bin-clean:' >> Makefile
  198. echo -e ' $(shell rm '$prefix'bin/login-server*)' >> Makefile
  199. echo -e ' $(shell rm '$prefix'bin/char-server*)' >> Makefile
  200. echo -e ' $(shell rm '$prefix'bin/map-server*)' >> Makefile
  201. echo -e ' $(shell rm '$prefix'bin/ladmin)' >> Makefile
  202. echo '' >> Makefile
  203. echo -e 'uninstall:' >> Makefile
  204. echo -e ' bin-clean' >> Makefile
  205. echo -e ' $(shell rm '$prefix'bin/save)' >> Makefile
  206. echo -e ' $(shell rm '$prefix'bin/db)' >> Makefile
  207. echo -e ' $(shell rm '$prefix'bin/conf)' >> Makefile
  208. echo -e ' $(shell rm '$prefix'bin/npc)' >> Makefile
  209. echo -e ' $(shell rm '$prefix'bin/log)' >> Makefile
  210. echo -e ' $(shell rm -rf '$prefix'etc/eathena)' >> Makefile
  211. echo -e ' $(shell rm -rf '$prefix'var/log/eathena)' >> Makefile
  212. }
  213. # Arguments
  214. while getopts ":hdo:ep:" opt; do
  215. case $opt in
  216. h ) helptext ; exit ;;
  217. d ) set -x ;;
  218. o ) optimize ${OPTARG} ;;
  219. e ) opt_check_pcre ;;
  220. p ) prefix=${OPTARG} ; [ -d ${OPTARG} ] || echo "The directory $prefix does not exist. Creating...";;
  221. esac
  222. done
  223. # Execution
  224. echo "eAthena configure script"
  225. echo "Note: This is ALPHA software! Do NOT use it on a production server!"
  226. echo
  227. echo "Checking for dependencies.."
  228. check_sed
  229. check_gcc
  230. check_make
  231. check_sockets
  232. check_mysql_headers
  233. make_changes
  234. make_installable
  235. echo
  236. make_report
  237. exit