From 8a31e5c654af9a4b3261db3e290f08ce5629b071 Mon Sep 17 00:00:00 2001 From: Huynh Tran Date: Thu, 23 Jun 2005 19:49:21 +0000 Subject: Wrote the M4 function and re-added header files to Makefile.am for make dist. --- acinclude.m4 | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++ ax_compare_version.m4 | 162 ++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 97 +++++++++----------------- src/Makefile.am | 36 ++++++++-- 4 files changed, 408 insertions(+), 70 deletions(-) create mode 100644 acinclude.m4 create mode 100644 ax_compare_version.m4 diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..8dc0426 --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,183 @@ +dnl $Id$ + +dnl @synopsis AC_CHECK_LIB_TMW( +dnl LIBRARY +dnl [, MINIMUM-VERSION +dnl [, LIBRARY-CONFIG-EXE +dnl [, ACTION-IF-FOUND +dnl [, ACTION-IF-NOT-FOUND ]]]] +dnl ) +dnl +dnl This function runs a LIBRARY-config script (or LIBRARY-CONFIG-EXE if +dnl specified) and defines LIBRARY_CFLAGS and LIBRARY_LIBS. +dnl +dnl The script must support `--cflags' and `--libs' args. +dnl If MINIMUM-VERSION is specified, the script must also support the +dnl `--version' arg. +dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given, +dnl it must also support `--prefix' and `--exec-prefix'. +dnl (In other words, it must be like gtk-config.) +dnl +dnl Example: +dnl +dnl AC_CHECK_LIB_TMW(foo, 1.0.0) +dnl +dnl would run `foo-config --version' and check that it is at least 1.0.0. +dnl +dnl If so, the following would then be defined: +dnl +dnl FOO_CFLAGS to `foo-config --cflags` +dnl FOO_LIBS to `foo-config --libs` +dnl +dnl This function is a hack of the original ac_path_generic.m4 written by +dnl Angus Lees . +dnl It adds LIBRARY-CONFIG-EXE so that it is possible to define `foo_config` +dnl as the script to execute instead of the default `foo-config`. + +m4_include(ax_compare_version.m4) + +AC_DEFUN([AC_CHECK_LIB_TMW], [ + dnl define macros to uppercase or lowercase a string. + pushdef([UP], translit([$1], [a-z], [A-Z]))dnl + pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl + + dnl add two options to the configure script to set the prefix and + dnl the exec-prefix of the library. + AC_ARG_WITH( + DOWN-prefix, + AS_HELP_STRING( + [--with-DOWN-prefix=PREFIX], + [prefix where lib$1 is installed (optional)] + ), + [DOWN[]_config_prefix="$withval"], + [DOWN[]_config_prefix=""] + ) + + AC_ARG_WITH( + DOWN-exec-prefix, + AS_HELP_STRING( + [--with-DOWN-exec-prefix=EPREFIX], + [exec prefix where lib$1 is installed (optional)] + ), + [DOWN[]_config_exec_prefix="$withval"], + [DOWN[]_config_exec_prefix=""] + ) + + dnl set default shell script to execute. + ifelse( + [$3], + [], + [DOWN[]_config_script="DOWN-config"], + [DOWN[]_config_script="$3"] + ) + + dnl print an info message if we have detected the environment + dnl variable LIBRARY_CONFIG. + if test -n "${UP[]_CONFIG+set}"; then + AC_MSG_NOTICE( + [using UP[]_CONFIG=$UP[]_CONFIG found from your environment] + ) + fi + + if test -n "$DOWN[]_config_prefix"; then + DOWN[]_config_args=\ + "$DOWN[]_config_args --prefix=$DOWN[]_config_prefix" + + if test -z "${UP[]_CONFIG+set}"; then + [UP[]_CONFIG=$DOWN[]_config_prefix/bin/$DOWN[]_config_script] + fi + fi + + if test -n "$DOWN[]_config_exec_prefix"; then + DOWN[]_config_args=\ + "$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix" + + if test -z "${UP[]_CONFIG+set}"; then + [UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/$DOWN[]_config_script] + fi + fi + + succeeded=no + + if test -z "$UP[]_CONFIG"; then + AC_PATH_PROG(UP[]_CONFIG, $DOWN[]_config_script, [no]) + fi + + if test "$UP[]_CONFIG" = "no"; then + echo "*** The $DOWN[]_config_script script could not be found. Make" + echo "*** sure it is in your path, or set the UP[]_CONFIG environment" + echo "*** variable to the full path to $DOWN[]_config_script." + else + ifelse( + [$2], [], + AC_MSG_CHECKING([for $1]), + AC_MSG_CHECKING([for $1 - version >= $2]) + ) + + if test -x "$UP[]_CONFIG"; then + ifelse( + [$2], [], [], + [DOWN[]_version=`$UP[]_CONFIG $DOWN[]_config_args --version` + + AX_COMPARE_VERSION( + [$DOWN[]_version], [ge], [$2], + [], + [AC_MSG_RESULT([no]) + + UP[]_CFLAGS="" + UP[]_LIBS="" + + echo "***" + echo "*** If you have already installed a sufficiently new" + echo "*** version, this error probably means that the wrong" + echo "*** copy of the $DOWN[]_config_script shell script is" + echo "*** being found in your path." + echo "***" + + AC_MSG_ERROR([found $DOWN[]_version]) + ] + )] + ) + + AC_MSG_RESULT(yes) + succeeded="yes" + + AC_MSG_CHECKING(UP[]_CFLAGS) + UP[]_CFLAGS=`$UP[]_CONFIG $DOWN[]_config_args --cflags` + AC_MSG_RESULT($UP[]_CFLAGS) + + AC_MSG_CHECKING(UP[]_LIBS) + UP[]_LIBS=`$UP[]_CONFIG $DOWN[]_config_args --libs` + AC_MSG_RESULT($UP[]_LIBS) + else + AC_MSG_RESULT([could not execute $UP[]_CONFIG]) + + echo "***" + echo "*** The $UP[]_CONFIG shell script does not exist or" + echo "*** is not executable. Please check if the file exists and" + echo "*** is executable or update your UP[]_CONFIG environment" + echo "*** variable so that it points to an existing DOWN-config" + echo "*** shell script." + echo "***" + fi + fi + + dnl define output variables. + AC_SUBST(UP[]_CFLAGS) + AC_SUBST(UP[]_LIBS) + + if test "$succeeded" = "yes"; then + ifelse([$4], [], :, [$4]) + else + ifelse( + [$5], + [], + AC_MSG_ERROR([library requirements (>=$2) not met.]), + [$5] + ) + fi + + dnl undefine macros. + popdef([UP]) + popdef([DOWN]) +]) diff --git a/ax_compare_version.m4 b/ax_compare_version.m4 new file mode 100644 index 0000000..bd6c51b --- /dev/null +++ b/ax_compare_version.m4 @@ -0,0 +1,162 @@ +dnl @synopsis AX_COMPARE_VERSION(VERSION_A, OP, VERSION_B, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +dnl +dnl This macro compares two version strings. It is used heavily in the +dnl macro _AX_PATH_BDB for library checking. Due to the various number +dnl of minor-version numbers that can exist, and the fact that string +dnl comparisons are not compatible with numeric comparisons, this is +dnl not necessarily trivial to do in a autoconf script. This macro +dnl makes doing these comparisons easy. +dnl +dnl The six basic comparisons are available, as well as checking +dnl equality limited to a certain number of minor-version levels. +dnl +dnl The operator OP determines what type of comparison to do, and can +dnl be one of: +dnl +dnl eq - equal (test A == B) +dnl ne - not equal (test A != B) +dnl le - less than or equal (test A <= B) +dnl ge - greater than or equal (test A >= B) +dnl lt - less than (test A < B) +dnl gt - greater than (test A > B) +dnl +dnl Additionally, the eq and ne operator can have a number after it to +dnl limit the test to that number of minor versions. +dnl +dnl eq0 - equal up to the length of the shorter version +dnl ne0 - not equal up to the length of the shorter version +dnl eqN - equal up to N sub-version levels +dnl neN - not equal up to N sub-version levels +dnl +dnl When the condition is true, shell commands ACTION-IF-TRUE are run, +dnl otherwise shell commands ACTION-IF-FALSE are run. The environment +dnl variable 'ax_compare_version' is always set to either 'true' or +dnl 'false' as well. +dnl +dnl Examples: +dnl +dnl AX_COMPARE_VERSION([3.15.7],[lt],[3.15.8]) +dnl AX_COMPARE_VERSION([3.15],[lt],[3.15.8]) +dnl +dnl would both be true. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq],[3.15.8]) +dnl AX_COMPARE_VERSION([3.15],[gt],[3.15.8]) +dnl +dnl would both be false. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq2],[3.15.8]) +dnl +dnl would be true because it is only comparing two minor versions. +dnl +dnl AX_COMPARE_VERSION([3.15.7],[eq0],[3.15]) +dnl +dnl would be true because it is only comparing the lesser number of +dnl minor versions of the two values. +dnl +dnl Note: The characters that separate the version numbers do not +dnl matter. An empty string is the same as version 0. OP is evaluated +dnl by autoconf, not configure, so must be a string, not a variable. +dnl +dnl The author would like to acknowledge Guido Draheim whose advice +dnl about the m4_case and m4_ifvaln functions make this macro only +dnl include the portions necessary to perform the specific comparison +dnl specified by the OP argument in the final configure script. +dnl +dnl @category Misc +dnl @author Tim Toolan +dnl @version 2004-03-01 +dnl @license GPLWithACException + +dnl ######################################################################### +AC_DEFUN([AX_COMPARE_VERSION], [ + # Used to indicate true or false condition + ax_compare_version=false + + # Convert the two version strings to be compared into a format that + # allows a simple string comparison. The end result is that a version + # string of the form 1.12.5-r617 will be converted to the form + # 0001001200050617. In other words, each number is zero padded to four + # digits, and non digits are removed. + AS_VAR_PUSHDEF([A],[ax_compare_version_A]) + A=`echo "$1" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + AS_VAR_PUSHDEF([B],[ax_compare_version_B]) + B=`echo "$3" | sed -e 's/\([[0-9]]*\)/Z\1Z/g' \ + -e 's/Z\([[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/Z\([[0-9]][[0-9]][[0-9]]\)Z/Z0\1Z/g' \ + -e 's/[[^0-9]]//g'` + + dnl # In the case of le, ge, lt, and gt, the strings are sorted as necessary + dnl # then the first line is used to determine if the condition is true. + dnl # The sed right after the echo is to remove any indented white space. + m4_case(m4_tolower($2), + [lt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [gt],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/false/;s/x${B}/true/;1q"` + ], + [le],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ], + [ge],[ + ax_compare_version=`echo "x$A +x$B" | sed 's/^ *//' | sort -r | sed "s/x${A}/true/;s/x${B}/false/;1q"` + ],[ + dnl Split the operator from the subversion count if present. + m4_bmatch(m4_substr($2,2), + [0],[ + # A count of zero means use the length of the shorter version. + # Determine the number of characters in A and B. + ax_compare_version_len_A=`echo "$A" | awk '{print(length)}'` + ax_compare_version_len_B=`echo "$B" | awk '{print(length)}'` + + # Set A to no more than B's length and B to no more than A's length. + A=`echo "$A" | sed "s/\(.\{$ax_compare_version_len_B\}\).*/\1/"` + B=`echo "$B" | sed "s/\(.\{$ax_compare_version_len_A\}\).*/\1/"` + ], + [[0-9]+],[ + # A count greater than zero means use only that many subversions + A=`echo "$A" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + B=`echo "$B" | sed "s/\(\([[0-9]]\{4\}\)\{m4_substr($2,2)\}\).*/\1/"` + ], + [.+],[ + AC_WARNING( + [illegal OP numeric parameter: $2]) + ],[]) + + # Pad zeros at end of numbers to make same length. + ax_compare_version_tmp_A="$A`echo $B | sed 's/./0/g'`" + B="$B`echo $A | sed 's/./0/g'`" + A="$ax_compare_version_tmp_A" + + # Check for equality or inequality as necessary. + m4_case(m4_tolower(m4_substr($2,0,2)), + [eq],[ + test "x$A" = "x$B" && ax_compare_version=true + ], + [ne],[ + test "x$A" != "x$B" && ax_compare_version=true + ],[ + AC_WARNING([illegal OP parameter: $2]) + ]) + ]) + + AS_VAR_POPDEF([A])dnl + AS_VAR_POPDEF([B])dnl + + dnl # Execute ACTION-IF-TRUE / ACTION-IF-FALSE. + if test "$ax_compare_version" = "true" ; then + m4_ifvaln([$4],[$4],[:])dnl + m4_ifvaln([$5],[else $5])dnl + fi +]) dnl AX_COMPARE_VERSION diff --git a/configure.ac b/configure.ac index 117aac5..31e2d95 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,6 @@ dnl $Id$ -# TODO: write an M4 PKG_CHECK_MODULES-like for the external libraries that -# provide an executable -config (e.g. SDL, MySQL, PostgreSQL) to -# make this file shorter, more readable and easier to maintain. - - AC_PREREQ(2.59) AC_INIT([TMW Server], [0.0.1], [b_lindeijer@users.sourceforge.net], [tmwserv]) AC_CONFIG_HEADER([config.h]) @@ -24,23 +19,11 @@ AC_PROG_INSTALL AC_CHECK_LIB([crypto], [EVP_md5]) AC_CHECK_LIB([physfs], [PHYSFS_init]) -# libSDL -AC_PATH_PROG(SDL_CONFIG, [sdl-config], [no]) -if test "$SDL_CONFIG" = "no"; then - AC_MSG_ERROR([The sdl-config could not be found. Please check your path.]) -else - AC_MSG_CHECKING(SDL_CFLAGS) - SDL_CFLAGS=`$SDL_CONFIG --cflags` - AC_MSG_RESULT($SDL_CFLAGS) - - AC_MSG_CHECKING(SDL_LIBS) - SDL_LIBS=`$SDL_CONFIG --libs` - AC_MSG_RESULT($SDL_LIBS) - - # update CXXFLAGS and LIBS. - CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" - LIBS="$LIBS $SDL_LIBS" -fi +AC_CHECK_LIB_TMW([SDL], [1.2.0]) +# update CXXFLAGS and LIBS. +# SDL_CFLAGS and SDL_LIBS are set by AC_CHECK_LIB_TMW. +CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" +LIBS="$LIBS $SDL_LIBS" AC_CHECK_LIB([SDL_net], [SDLNet_Init]) @@ -73,56 +56,36 @@ AC_ARG_WITH( [use storage backend [[ARG=mysql,postgresql,sqlite]] [(default=sqlite)]] ), - [], + [if test "$withval" = "yes"; then + # default is sqlite. + with_storage_backend="sqlite" + elif test "$withval" = "no"; then + AC_MSG_ERROR([$PACKAGE_NAME cannot run without a storage backend.]) + else + with_storage_backend="$withval" + fi], [with_storage_backend="sqlite"] ) if test "$with_storage_backend" = "mysql"; then - # use mysql_config to get the CFLAGS and LIBS values. - AC_PATH_PROG(MYSQL_CONFIG, [mysql_config], [no]) - - if test "$MYSQL_CONFIG" = "no"; then - AC_MSG_ERROR( - [The mysql_config could not be found. Please check your path.] - ) - else - AC_MSG_CHECKING(MYSQL_CFLAGS) - MYSQL_CFLAGS=`$MYSQL_CONFIG --cflags` - AC_MSG_RESULT($MYSQL_CFLAGS) - - AC_MSG_CHECKING(MYSQL_LIBS) - MYSQL_LIBS=`$MYSQL_CONFIG --libs` - AC_MSG_RESULT($MYSQL_LIBS) - - # update CXXFLAGS and LIBS. - CXXFLAGS="$CXXFLAGS -DMYSQL_SUPPORT $MYSQL_CFLAGS" - LIBS="$LIBS $MYSQL_LIBS" - fi + # use mysql_config to check libmysqlclient. + # MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LIBS are set by AC_CHECK_LIB_TMW. + AC_CHECK_LIB_TMW([mysqlclient], [4.1.0], [mysql_config]) + + # update CXXFLAGS and LIBS. + CXXFLAGS="$CXXFLAGS -DMYSQL_SUPPORT $MYSQLCLIENT_CFLAGS" + LIBS="$LIBS $MYSQLCLIENT_LIBS" elif test "$with_storage_backend" = "postgresql"; then - # use mysql_config to get the CFLAGS and LIBS values. - AC_PATH_PROG(POSTGRESQL_CONFIG, [pg_config], [no]) - - if test "$POSTGRESQL_CONFIG" = "no"; then - AC_MSG_ERROR( - [The pg_config could not be found. Please check your path.] - ) - else - AC_MSG_CHECKING(POSTGRESQL_CFLAGS) - POSTGRESQL_CFLAGS=`$POSTGRESQL_CONFIG --cflags` - AC_MSG_RESULT($POSTGRESQL_CFLAGS) - - AC_MSG_CHECKING(POSTGRESQL_LIBS) - POSTGRESQL_LIBS=`$POSTGRESQL_CONFIG --libs` - AC_MSG_RESULT($POSTGRESQL_LIBS) - - # update CXXFLAGS and LIBS. - CXXFLAGS="$CXXFLAGS -DPOSTGRESQL_SUPPORT $POSTGRESQL_CFLAGS" - LIBS="$LIBS $POSTGRESQL_LIBS" - fi + # use pg_config to check libpq. + # PQ_CFLAGS and PQ_LIBS are set by AC_CHECK_LIB_TMW. + AC_CHECK_LIB_TMW([pq], [7.0.0], [pg_config]) + + # update CXXFLAGS and LIBS. + CXXFLAGS="$CXXFLAGS -DPOSTGRESQL_SUPPORT $PQ_CFLAGS" + LIBS="$LIBS $PQ_LIBS" elif test "$with_storage_backend" = "sqlite"; then # use pkg-config to check libsqlite3. - # SQLITE_CFLAGS and SQLITE_LIBS are set by PKG_CHECK_MODULES - # so nothing much to do here :) + # SQLITE_CFLAGS and SQLITE_LIBS are set by PKG_CHECK_MODULES. PKG_CHECK_MODULES(SQLITE,[sqlite3 >= 3.0.6]) # update CXXFLAGS and LIBS. @@ -152,8 +115,10 @@ elif test "$with_scripting_engine" = "squirrel"; then # update CXXFLAGS and LIBS CXXFLAGS="$CXXFLAGS -DSCRIPT_SUPPORT -DSQUIRREL_SUPPORT" + # there is no need to append -lsquirrel as it is already done by + # AC_CHECK_LIB LIBS="$LIBS -lsqstdlib" -elif test ! "$with_scripting_engine" = "no"; then +elif test "$with_scripting_engine" != "no"; then AC_MSG_ERROR([unknown scripting engine: $with_scripting_engine]) fi diff --git a/src/Makefile.am b/src/Makefile.am index 3c39871..d567125 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,41 +4,69 @@ bin_PROGRAMS = tmwserv tmwserv_SOURCES = main.cpp \ + accounthandler.h \ accounthandler.cpp \ + connectionhandler.h \ connectionhandler.cpp \ + debug.h \ debug.cpp \ defines.h \ + items.h \ + messagehandler.h \ messagehandler.cpp \ + messagein.h \ messagein.cpp \ + messageout.h \ messageout.cpp \ + netcomputer.h \ netcomputer.cpp \ + netsession.h \ netsession.cpp \ + packet.h \ packet.cpp \ + skill.h \ skill.cpp \ + storage.h \ storage.cpp \ + account.h \ account.cpp \ + object.h \ object.cpp \ + dalstorage.h \ dalstorage.cpp \ + dal/dalexcept.h \ + dal/dataprovider.h \ dal/dataprovider.cpp \ + dal/dataproviderfactory.h \ dal/dataproviderfactory.cpp \ + dal/recordset.h \ dal/recordset.cpp \ + utils/functors.h \ + utils/singleton.h \ + utils/cipher.h \ utils/cipher.cpp \ + utils/logger.h \ utils/logger.cpp if BUILD_MYSQL -tmwserv_SOURCES += dal/mysqldataprovider.cpp +tmwserv_SOURCES += dal/mysqldataprovider.h \ + dal/mysqldataprovider.cpp endif if BUILD_POSTGRESQL -tmwserv_SOURCES += dal/pqdataprovider.cpp +tmwserv_SOURCES += dal/pqdataprovider.h \ + dal/pqdataprovider.cpp endif if BUILD_SQLITE -tmwserv_SOURCES += dal/sqlitedataprovider.cpp +tmwserv_SOURCES += dal/sqlitedataprovider.h \ + dal/sqlitedataprovider.cpp endif if BUILD_SQUIRREL -tmwserv_SOURCES += script.cpp \ +tmwserv_SOURCES += script.h \ + script.cpp \ + script-squirrel.h \ script-squirrel.cpp endif -- cgit