summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2008-12-17 20:16:55 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2008-12-17 20:16:55 +0000
commit2d72446860abac08dc4f36b10fde7536f7897956 (patch)
tree25dc114bb696bc8752d68e6e050da8d3dda5f282 /include
parent1cd73b4dadb8e618a0ec56289408922be42aac8a (diff)
More CMake work, mostly to handle both *nix and Windows builds.
Also some tweaks to generation files (like version.sh) to take both input and output files as arguments, to handle CMake when it's used for an out-of-source build. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1836 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'include')
-rw-r--r--include/CMakeLists.txt56
-rw-r--r--include/extern.h4
-rw-r--r--include/modules.h4
-rw-r--r--include/services.h10
-rw-r--r--include/sysconf.h.cmake54
-rw-r--r--include/version.sh11
-rw-r--r--include/version.sh.c38
7 files changed, 125 insertions, 52 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 8deeef120..bfdbadee6 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -8,32 +8,45 @@ set(messages.h_HEADERS modules.h)
set(module.h_HEADERS services.h commands.h ${Anope_BINARY_DIR}/lang/language.h modules.h ${CMAKE_CURRENT_BINARY_DIR}/version.h)
set(modules.h_HEADERS services.h)
set(pseudo.h_HEADERS commands.h ${Anope_BINARY_DIR}/lang/language.h timeout.h encrypt.h datafiles.h slist.h)
-set(services.h_HEADERS sysconf.h config.h sockets.h defs.h slist.h events.h bots.h account.h regchannel.h users.h extern.h configreader.h)
+set(services.h_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/sysconf.h config.h sockets.h defs.h slist.h events.h bots.h account.h regchannel.h users.h extern.h configreader.h)
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
- #COMMAND ${CMAKE_COMMAND} -E copy ${Anope_SOURCE_DIR}/version.log ../
- COMMAND ${SH} ${CMAKE_CURRENT_SOURCE_DIR}/version.sh ${Anope_SOURCE_DIR}/version.log
- #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_SOURCE_DIR}/
- #COMMAND ${CMAKE_COMMAND} -E remove ../version.log
- MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/version.sh DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/services.h ${CMAKE_CURRENT_SOURCE_DIR}/pseudo.h ${CMAKE_CURRENT_SOURCE_DIR}/messages.h ${SRC_SRCS}
-# MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/version.sh DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/services.h ${CMAKE_CURRENT_SOURCE_DIR}/pseudo.h ${CMAKE_CURRENT_SOURCE_DIR}/messages.h
-)
+if(WIN32)
+ set_source_files_properties(version.sh.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
+ add_executable(version.sh version.sh.c)
+ set_target_properties(version.sh PROPERTIES LINK_FLAGS "${LDFLAGS}")
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
+ COMMAND version.sh ${Anope_SOURCE_DIR}/version.log ${CMAKE_CURRENT_SOURCE_DIR}/version.sh ${CMAKE_CURRENT_BINARY_DIR}/version.h
+ MAIN_DEPENDENCY version.sh DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/services.h ${CMAKE_CURRENT_SOURCE_DIR}/pseudo.h ${CMAKE_CURRENT_SOURCE_DIR}/messages.h ${SRC_SRCS}
+ )
+else(WIN32)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
+ #COMMAND ${CMAKE_COMMAND} -E copy ${Anope_SOURCE_DIR}/version.log ../
+ COMMAND ${SH} ${CMAKE_CURRENT_SOURCE_DIR}/version.sh ${Anope_SOURCE_DIR}/version.log ${CMAKE_CURRENT_BINARY_DIR}/version.h
+ #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_SOURCE_DIR}/
+ #COMMAND ${CMAKE_COMMAND} -E remove ../version.log
+ MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/version.sh DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/services.h ${CMAKE_CURRENT_SOURCE_DIR}/pseudo.h ${CMAKE_CURRENT_SOURCE_DIR}/messages.h ${SRC_SRCS}
+ # MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/version.sh DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/services.h ${CMAKE_CURRENT_SOURCE_DIR}/pseudo.h ${CMAKE_CURRENT_SOURCE_DIR}/messages.h
+ )
+endif(WIN32)
foreach(HEADER ${HEADERS_REL})
- add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}
- COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}
- )
+ if(NOT WIN32)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}
+ COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}
+ )
+ endif(NOT WIN32)
set(HEADERS_FULL ${HEADERS_FULL} ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER})
set(HEADERS)
if(${HEADER}_HEADERS)
- foreach(HEADER ${${HEADER}_HEADERS})
- string(SUBSTRING ${HEADER} 0 1 FIRST_CHAR)
- if(FIRST_CHAR STREQUAL "/")
- set(HEADERS ${HEADERS} ${HEADER})
- else(FIRST_CHAR STREQUAL "/")
- set(HEADERS ${HEADERS} ${Anope_SOURCE_DIR}/include/${HEADER})
- endif(FIRST_CHAR STREQUAL "/")
- endforeach(HEADER)
+ foreach(HEADER_REL ${${HEADER}_HEADERS})
+ string(SUBSTRING ${HEADER_REL} 0 1 FIRST_CHAR)
+ string(SUBSTRING ${HEADER_REL} 1 1 SECOND_CHAR)
+ if(FIRST_CHAR STREQUAL "/" OR SECOND_CHAR STREQUAL ":")
+ set(HEADERS ${HEADERS} ${HEADER_REL})
+ else(FIRST_CHAR STREQUAL "/" OR SECOND_CHAR STREQUAL ":")
+ set(HEADERS ${HEADERS} ${Anope_SOURCE_DIR}/include/${HEADER_REL})
+ endif(FIRST_CHAR STREQUAL "/" OR SECOND_CHAR STREQUAL ":")
+ endforeach(HEADER_REL)
endif(${HEADER}_HEADERS)
if(HEADERS)
set_source_files_properties(${HEADER} PROPERTIES OBJECT_DEPENDS "${HEADERS}")
@@ -66,4 +79,5 @@ message(STATUS "HEADERS_FULL: ${HEADERS_FULL}")
add_custom_target(headers DEPENDS ${HEADERS_FULL})
#add_dependencies(include include_version_h)
-set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM yes ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/version.h ${CMAKE_CURRENT_BINARY_DIR}/language.h")
+set(HEADERS_CLEAN ${CMAKE_CURRENT_BINARY_DIR}/version.h)
+set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM yes ADDITIONAL_MAKE_CLEAN_FILES "${HEADERS_CLEAN}")
diff --git a/include/extern.h b/include/extern.h
index 0e913413a..8bbf3fde5 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -670,8 +670,8 @@ E int nickIsServices(const char *nick, int bot);
E void add_entropy_userkeys();
E void rand_init();
E unsigned char getrandom8();
-E u_int16_t getrandom16();
-E u_int32_t getrandom32();
+E uint16 getrandom16();
+E uint32 getrandom32();
E char *str_signed(unsigned char *str);
diff --git a/include/modules.h b/include/modules.h
index 05ef6b524..dc00807c9 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -24,10 +24,10 @@ typedef HMODULE ano_module_t;
#define ano_modopen(file) LoadLibrary(file)
/* ano_moderr in modules.c */
-#define ano_modsym(file, symbol) (void *)GetProcAddress(file, symbol)
+#define ano_modsym(file, symbol) (HMODULE)GetProcAddress(file, symbol)
#define ano_modclose(file) FreeLibrary(file) ? 0 : 1
#define ano_modclearerr() SetLastError(0)
-#define MODULE_EXT ".dll"
+#define MODULE_EXT ".so"
#else
typedef void * ano_module_t;
diff --git a/include/services.h b/include/services.h
index 66e12aeb2..7d504e3a2 100644
--- a/include/services.h
+++ b/include/services.h
@@ -81,7 +81,7 @@
#include <sys/stat.h> /* for umask() on some systems */
#include <sys/types.h>
-#ifndef _WIN32
+#ifdef HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
@@ -197,7 +197,8 @@ extern int strncasecmp(const char *, const char *, size_t);
*/
#ifdef _WIN32
#define MODULE_INIT(x, y) \
- extern "C" DllExport Module *init_module(const std::string &modname, const std::string &creator) \
+ extern "C" DllExport Module *init_module(const std::string &, const std::string &); \
+ extern "C" Module *init_module(const std::string &modname, const std::string &creator) \
{ \
return new y(x, creator); \
} \
@@ -211,9 +212,10 @@ extern int strncasecmp(const char *, const char *, size_t);
} \
return TRUE; \
} \
- extern "C" DllExport void destroy_module(y *m) \
+ extern "C" DllExport void destroy_module(y *); \
+ extern "C" void destroy_module(y *m) \
{ \
- delete m; \
+ delete m; \
}
#else
diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake
index b4241f4b2..e7464492d 100644
--- a/include/sysconf.h.cmake
+++ b/include/sysconf.h.cmake
@@ -26,6 +26,8 @@
// Temporary, remove from here later as well as elsewhere in the code
#define DL_PREFIX ""
+#cmakedefine HAVE_UINT8_T 1
+#cmakedefine HAVE_U_INT8_T 1
#cmakedefine HAVE_INT16_T 1
#cmakedefine HAVE_UINT16_T 1
#cmakedefine HAVE_U_INT16_T 1
@@ -43,10 +45,28 @@
# include <stddef.h>
#endif
+#ifdef HAVE_UINT8_T
+typedef uint8_t uint8;
+#else
+# ifdef HAVE_U_INT8_T
+typedef u_int8_t uint8;
+# else
+# ifdef _WIN32
+typedef unsigned __int8 uint8;
+# else
+typedef unsigned short uint8;
+# endif
+# endif
+#endif
+
#ifdef HAVE_INT16_T
typedef int16_t int16;
#else
-typedef short int16;
+# ifdef _WIN32
+typedef signed __int16 int16;
+# else
+typedef int int16;
+# endif
#endif
#ifdef HAVE_UINT16_T
@@ -55,14 +75,22 @@ typedef uint16_t uint16;
# ifdef HAVE_U_INT16_T
typedef u_int16_t uint16;
# else
-typedef unsigned short uint16;
+# ifdef _WIN32
+typedef unsigned __int16 uint16;
+# else
+typedef unsigned int uint16;
+# endif
# endif
#endif
#ifdef HAVE_INT32_T
typedef int32_t int32;
#else
+# ifdef _WIN32
+typedef signed __int32 int32;
+# else
typedef long int32;
+# endif
#endif
#ifdef HAVE_UINT32_T
@@ -71,8 +99,30 @@ typedef uint32_t uint32;
# ifdef HAVE_U_INT32_T
typedef u_int32_t uint32;
# else
+# ifdef _WIN32
+typedef unsigned __int32 uint32;
+# else
typedef unsigned long uint32;
+# endif
+# endif
+#endif
+
+#ifdef _WIN32
+# ifdef MSVCPP
+# define snprintf _snprintf
+# endif
+# define popen _popen
+# define pclose _pclose
+# define ftruncate _chsize
+# ifdef MSVCPP
+# define PATH_MAX MAX_PATH
+# endif
+# define MAXPATHLEN MAX_PATH
+# define bzero(buf, size) memset(buf, 0, size)
+# ifdef MSVCPP
+# define strcasecmp stricmp
# endif
+# define sleep(x) Sleep(x * 1000)
#endif
#endif
diff --git a/include/version.sh b/include/version.sh
index 962896e6b..77e2d5f3a 100644
--- a/include/version.sh
+++ b/include/version.sh
@@ -3,8 +3,8 @@
# Build version string and increment Services build number.
#
-if [ $# -lt 1 ] ; then
- echo "Syntax: $0 <version.log>"
+if [ $# -lt 2 ] ; then
+ echo "Syntax: $0 <version.log> <version.h>"
exit 1
fi
# Grab version information from the version control file.
@@ -19,8 +19,9 @@ fi
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_EXTRA} (${VERSION_BUILD})"
VERSIONDOTTED="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_EXTRA}.${VERSION_BUILD}"
-if [ -f version.h ] ; then
- BUILD=`fgrep '#define BUILD' version.h | cut -f2 -d\"`
+VERSIONH="$2"
+if [ -f $VERSIONH ] ; then
+ BUILD=`fgrep '#define BUILD' $VERSIONH | cut -f2 -d\"`
BUILD=`expr $BUILD + 1 2>/dev/null`
else
BUILD=1
@@ -28,7 +29,7 @@ fi
if [ ! "$BUILD" ] ; then
BUILD=1
fi
-cat >version.h <<EOF
+cat >$VERSIONH <<EOF
/* Version information for Services.
*
* (C) 2003-2008 Anope Team
diff --git a/include/version.sh.c b/include/version.sh.c
index f95ae7d63..2b2f0c198 100644
--- a/include/version.sh.c
+++ b/include/version.sh.c
@@ -19,8 +19,6 @@
#include <cstdlib>
#include <cctype>
-#define CTRL "version.log"
-
long version_major, version_minor, version_patch, version_build, build;
char *version_extra = NULL;
char version[1024];
@@ -32,16 +30,20 @@ long get_value(char *);
char *get_value_str(char *);
char *strip(char *);
void parse_version(FILE *);
-void write_version(FILE *);
+void write_version(FILE *, const char *);
void parse_line(FILE *, char *);
-int main()
+int main(int argc, char *argv[])
{
- FILE *fd = fopen(CTRL, "r");
+ if (argc < 4) {
+ fprintf(stderr, "Syntax: %s <version.log> <version.sh> <version.h>\n", argv[0]);
+ exit(1);
+ }
+ FILE *fd = fopen(argv[1], "r");
if (!fd) {
- fprintf(stderr, "Error: Unable to find control file: " CTRL "\n");
+ fprintf(stderr, "Error: Unable to find control file: %s\n", argv[1]);
exit(0);
}
@@ -54,7 +56,7 @@ int main()
_snprintf(version_dotted, 1024, "%ld.%ld.%ld%s.%ld", version_major, version_minor,
version_patch, (version_extra ? version_extra : ""), version_build);
- fd = fopen("version.h", "r");
+ fd = fopen(argv[3], "r");
if (fd) {
parse_version(fd);
@@ -63,10 +65,10 @@ int main()
build = 1;
- fd = fopen("version.h", "w");
- write_version(fd);
+ fd = fopen(argv[3], "w");
+ write_version(fd, argv[2]);
fclose(fd);
-
+
if (version_extra)
free(version_extra);
}
@@ -109,7 +111,7 @@ char *strip(char *str)
long get_value(char *string)
{
// XXX : if the fields in version.log are empty strtok returns a double quote, dont try to atol it then
- if (*string != '"')
+ if (string[1] != '"')
return atol(get_value_str(string));
else
return 0;
@@ -118,6 +120,7 @@ long get_value(char *string)
char *get_value_str(char *string)
{
int len;
+ char *newstr;
if (*string == '"')
string++;
@@ -128,7 +131,10 @@ char *get_value_str(char *string)
string[len - 1] = 0;
if (!*string)
return NULL;
- return strdup(string);
+ newstr = (char *)malloc(len + 1);
+ strcpy(newstr, string);
+ return newstr;
+ //return strdup(string);
}
void parse_version(FILE * fd)
@@ -161,9 +167,9 @@ void parse_version(FILE * fd)
build = 1;
}
-void write_version(FILE * fd)
+void write_version(FILE * fd, const char *input)
{
- FILE *fdin = fopen("include\\version.sh", "r");
+ FILE *fdin = fopen(input, "r");
char buf[1024];
short until_eof = 0;
@@ -178,7 +184,7 @@ void write_version(FILE * fd)
parse_line(fd, buf);
}
- if (!strcmp(buf, "cat >version.h <<EOF"))
+ if (!strcmp(buf, "cat >$VERSIONH <<EOF"))
until_eof = 1;
}
@@ -221,7 +227,7 @@ void parse_line(FILE * fd, char *line)
fprintf(fd, "%s", version);
else if (!strcmp(varbegin, "VERSIONDOTTED"))
fprintf(fd, "%s", version_dotted);
- fputc(tmp, fd);
+ if (tmp) fputc(tmp, fd);
}
c = var;
} else