diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..218591b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 3.2) +include(CMakeDependentOption) +include(CPack) +include(CheckFunctionExists) + +project(mbusd VERSION 0.2.4) + +#TODO ISC_Posix, prog_libtool +# single-configuration generator setup +SET(BASIC_C_FLAGS "-W -pedantic -fno-builtin-log -Wall") +SET(CMAKE_C_FLAGS_RELEASE "${BASIC_C_FLAGS} -O2") +SET(CMAKE_C_FLAGS_DEBUG "${BASIC_C_FLAGS} -g") + +add_definitions(-DPACKAGE="${PROJECT_NAME}" -DVERSION="${PROJECT_VERSION}") + +# user options +option (TRXCTL "Support RS-232 to RS-485 converter data direction control" ON) +if(TRXCTL) + add_definitions(-DTRXCTL) +endif() +option (LOG "enabling logging facility via logw" ON) +check_function_exists(logw HAVE_LOGW) +if(HAVE_LOGW AND LOG) + add_definitions(-DLOG) +endif() +CMAKE_DEPENDENT_OPTION(DEBUG_LOG "extra debug log info" OFF "LOGW" OFF) +if(DEBUG_LOG) + add_definitions(-DDEBUG) +endif() + +## check for and pass preprocessor flags +check_function_exists(cfmakeraw HAVE_CFMAKERAW) +if(HAVE_CFMAKERAW) + add_definitions(-DHAVE_CFMAKERAW) +endif() +check_function_exists(cfsetspeed HAVE_CFSETSPEED) +check_function_exists(cfsetispeed HAVE_CFSETISPEED) +if(HAVE_CFSETSPEED AND HAVE_CFSETISPEED) + add_definitions(-DHAVE_CFSETSPEED) +endif() +check_function_exists(time HAVE_TIME) +check_function_exists(localtime HAVE_LOCALTIME) +if(HAVE_TIME AND HAVE_LOCALTIME) + message("passing HRDATE to compiler space") + add_definitions(-DHRDATE) +endif() + +include(CheckLibraryExists) +find_library(LIB_UTIL NAMES libutil util) +check_library_exists(util tty_get_name LIB_UTIL HAVE_TTY_GET_NAME) +check_library_exists(util uu_lock LIB_UTIL HAVE_UU_LOCK) +if(LIB_UTIL AND HAVE_TTY_GET_NAME AND HAVE_UU_LOCK) + message("passing HAVE_LIBUTIL to compiler space") + add_definitions(-DHAVE_LIBUTIL) +endif() + + +set(mbusd_SOURCES + src/main.c + src/tty.c + src/log.c + src/cfg.c + src/conn.c + src/queue.c + src/modbus.c + src/crc16.c + src/state.c + src/sig.c + src/sock.c +) +add_executable(mbusd ${mbusd_SOURCES}) \ No newline at end of file diff --git a/README.md b/README.md index 10b6516..977a2e3 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,15 @@ $ make $ make clean +Compilation using cmake +
+$ git clone https://github.com/3cky/mbusd.git mbusd.git
+$ cd mbusd.git
+$ mkdir -p output.dir && cd output.dir
+$ cmake ../
+$ make
+
+ Usage: ------ diff --git a/src/globals.h b/src/globals.h index 5a2a1f1..dd206ba 100644 --- a/src/globals.h +++ b/src/globals.h @@ -63,15 +63,6 @@ # include #endif -/* - * Uncomment this for enabling logging facility - */ -#define LOG -#ifdef LOG -/* uncomment this line for extra debug log info */ -# define DEBUG -#endif - /* * Useful min/max macroses */ diff --git a/src/log.h b/src/log.h index 5ab271b..ba46b2e 100644 --- a/src/log.h +++ b/src/log.h @@ -46,6 +46,8 @@ extern int isdaemon; int log_init(char *logname); int log_app(char *logname, char *string); void logw(int level, char *fmt, ...); +#else + #define logw(fmt, ...) {} #endif #endif /* _LOG_H */ diff --git a/src/main.c b/src/main.c index d788180..1a74d5c 100644 --- a/src/main.c +++ b/src/main.c @@ -85,12 +85,12 @@ daemon(nochdir, noclose) if (!nochdir) (void)chdir("/"); - if (!noclose && (fd = _open("/dev/null", O_RDWR, 0)) != -1) { + if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); if (fd > 2) - (void)_close(fd); + (void)close(fd); } return (0); }