2
0
Эх сурвалжийг харах

Add a macro to add the dynamic library extension depending on the OS.

mingodad 10 жил өмнө
parent
commit
90b51aae80

+ 8 - 0
SquiLu-ext/dynamic_library.h

@@ -1,6 +1,14 @@
 #ifndef DYNAMIC_LIBRAY_H
 #ifndef DYNAMIC_LIBRAY_H
 #define DYNAMIC_LIBRAY_H
 #define DYNAMIC_LIBRAY_H
 
 
+#if defined(WIN32)
+#define DYNLIB_FOR_OS(fn) #fn ".dll"
+#elif defined(__APPLE__)
+#define DYNLIB_FOR_OS(fn) #fn ".dylib"
+#else
+#define DYNLIB_FOR_OS(fn) #fn ".so"
+#endif
+
 class DynamicLibrary
 class DynamicLibrary
 {
 {
 protected:
 protected:

+ 5 - 9
SquiLu-ext/sq_libclang.cpp

@@ -113,16 +113,12 @@ typedef CXType (*clang_getResultType_t)(CXType);
 static clang_getResultType_t dlclang_getResultType = 0;
 static clang_getResultType_t dlclang_getResultType = 0;
 // generated-code:end
 // generated-code:end
 
 
-#ifdef WIN32
-#define DYNLIB_NAME "libclang.dll"
-#else
-#define DYNLIB_NAME "libclang.so"
-#endif
+static const char *dynamicLibName = DYNLIB_FOR_OS(libclang);
 
 
 static bool load_dynamicLib()
 static bool load_dynamicLib()
 {
 {
     if(dlclang_createIndex) return true;
     if(dlclang_createIndex) return true;
-    if(dynamicLib.open(DYNLIB_NAME))
+    if(dynamicLib.open(dynamicLibName))
     {
     {
         //@write_dynamic_functions_load();
         //@write_dynamic_functions_load();
 // generated-code:begin
 // generated-code:begin
@@ -188,11 +184,11 @@ static SQRESULT get_libclang_instance(HSQUIRRELVM v, SQInteger idx, MyLibClang *
 	return _rc_;
 	return _rc_;
 }
 }
 
 
-#define GET_libclang_INSTANCE_AT(idx) \
-	MyLibClang *self=NULL; \
+#define GET_libclang_INSTANCE_AT(idx) \
+	MyLibClang *self=NULL; \
 	if((_rc_ = get_libclang_instance(v,idx,&self)) < 0) return _rc_;
 	if((_rc_ = get_libclang_instance(v,idx,&self)) < 0) return _rc_;
 
 
-#define GET_libclang_INSTANCE() GET_libclang_INSTANCE_AT(1)
+#define GET_libclang_INSTANCE() GET_libclang_INSTANCE_AT(1)
 
 
 static void release_visitor_cb(MyLibClang *self)
 static void release_visitor_cb(MyLibClang *self)
 {
 {

+ 3 - 6
SquiLu-ext/sq_mysql.cpp

@@ -143,16 +143,13 @@ static mysql_stmt_close_t dlmysql_stmt_close = 0;
 typedef const char * (*mysql_stmt_error_t)(MYSQL_STMT * stmt);
 typedef const char * (*mysql_stmt_error_t)(MYSQL_STMT * stmt);
 static mysql_stmt_error_t dlmysql_stmt_error = 0;
 static mysql_stmt_error_t dlmysql_stmt_error = 0;
 // generated-code:end
 // generated-code:end
-#ifdef WIN32
-#define DYNLIB_NAME "libmysqlclient.dll"
-#else
-#define DYNLIB_NAME "libmysqlclient.so"
-#endif
+
+static const char *dynamicLibName = DYNLIB_FOR_OS(libmysqlclient);
 
 
 static bool load_libmysqlclient()
 static bool load_libmysqlclient()
 {
 {
     if(dlmysql_init) return true;
     if(dlmysql_init) return true;
-    if(libmysqlclient.open(DYNLIB_NAME))
+    if(libmysqlclient.open(dynamicLibName))
     {
     {
         //@write_mysql_functions_load();
         //@write_mysql_functions_load();
 // generated-code:begin
 // generated-code:begin

+ 3 - 6
SquiLu-ext/sq_postgresql.cpp

@@ -206,16 +206,13 @@ static lo_export_t dllo_export = 0;
 typedef PGconn * (*PQconnectdb_t)(const char *conninfo);
 typedef PGconn * (*PQconnectdb_t)(const char *conninfo);
 static PQconnectdb_t dlPQconnectdb = 0;
 static PQconnectdb_t dlPQconnectdb = 0;
 // generated-code:end
 // generated-code:end
-#ifdef WIN32
-#define LIBPQ_NAME "libpq.dll"
-#else
-#define LIBPQ_NAME "libpq.so"
-#endif
+
+static const char *dynamicLibName = DYNLIB_FOR_OS(libpq);
 
 
 static bool load_libpq()
 static bool load_libpq()
 {
 {
     if(dlPQconnectdb) return true;
     if(dlPQconnectdb) return true;
-    if(libpq.open(LIBPQ_NAME))
+    if(libpq.open(dynamicLibName))
     {
     {
         //@write_pgsql_functions_load();
         //@write_pgsql_functions_load();
 // generated-code:begin
 // generated-code:begin