fix build on macos

Thu, 23 Feb 2023 21:09:33 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 23 Feb 2023 21:09:33 +0100
changeset 453
4586d534f9b5
parent 452
ce359a2b51fe
child 454
e03d4a00427a

fix build on macos

configure file | annotate | diff | comparison | revisions
make/clang.mk file | annotate | diff | comparison | revisions
make/project.xml file | annotate | diff | comparison | revisions
src/server/Makefile file | annotate | diff | comparison | revisions
src/server/config/acl.c file | annotate | diff | comparison | revisions
src/server/config/conf.c file | annotate | diff | comparison | revisions
src/server/config/keyfile.c file | annotate | diff | comparison | revisions
src/server/config/logging.c file | annotate | diff | comparison | revisions
src/server/config/logging.h file | annotate | diff | comparison | revisions
src/server/config/mimeconf.c file | annotate | diff | comparison | revisions
src/server/config/objconf.c file | annotate | diff | comparison | revisions
src/server/config/objs.mk file | annotate | diff | comparison | revisions
src/server/daemon/acl.c file | annotate | diff | comparison | revisions
src/server/daemon/httplistener.c file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
src/ucx/Makefile file | annotate | diff | comparison | revisions
--- a/configure	Sun Dec 04 13:01:00 2022 +0100
+++ b/configure	Thu Feb 23 21:09:33 2023 +0100
@@ -283,14 +283,6 @@
         return 0
     done
 	
-    # dependency openssl 
-    while true
-    do
-        LDFLAGS="$LDFLAGS -lssl -lcrypto"    
-		echo yes
-        return 0
-    done
-	
 	echo no
 	return 1
 }
@@ -313,6 +305,19 @@
         return 0
     done
 	
+    # dependency libxml2 
+    while true
+    do
+        xml2-config --cflags > /dev/null
+        if [ $? -eq 0 ]; then
+            CFLAGS="$CFLAGS `xml2-config --cflags`"
+        else
+            break
+        fi
+		echo yes
+        return 0
+    done
+	
 	echo no
 	return 1
 }
@@ -341,6 +346,10 @@
 LIB_EXT = .so
 APP_EXT =
 
+# ld flags
+UCX_SO_NAME =
+RPATH_WS_LIB_FLAG = -Wl,-rpath,'$$ORIGIN/../lib'
+
 __EOF__
         
         break
@@ -370,6 +379,10 @@
 LIB_EXT = .so
 APP_EXT =
 
+# ld flags
+UCX_SO_NAME =
+RPATH_WS_LIB_FLAG = -Wl,-rpath,'$$ORIGIN/../lib'
+
 __EOF__
         
         break
@@ -396,6 +409,10 @@
 LIB_EXT = .dylib
 APP_EXT =
 
+# ld flags
+UCX_SO_NAME = -install_name @rpath/libucx.dylib
+RPATH_WS_LIB_FLAG = -rpath @loader_path/../lib
+
 __EOF__
         
         break
--- a/make/clang.mk	Sun Dec 04 13:01:00 2022 +0100
+++ b/make/clang.mk	Thu Feb 23 21:09:33 2023 +0100
@@ -3,7 +3,10 @@
 #
 
 CFLAGS = -g
-LDFLAGS = -rdynamic -Wl,-R,'$$ORIGIN/../lib'
+LDFLAGS = -rdynamic
+#LDFLAGS = -rdynamic -Wl,-rpath,@loader_path/../lib
+LDFLAGS = -rpath @loader_path/../lib 
+
 
 SHLIB_CFLAGS = -fPIC
 SHLIB_LDFLAGS = -shared
--- a/make/project.xml	Sun Dec 04 13:01:00 2022 +0100
+++ b/make/project.xml	Thu Feb 23 21:09:33 2023 +0100
@@ -19,6 +19,10 @@
 OBJ_EXT = .o
 LIB_EXT = .so
 APP_EXT =
+
+# ld flags
+UCX_SO_NAME =
+RPATH_WS_LIB_FLAG = -Wl,-rpath,'$$ORIGIN/../lib'
 		</make>
 	</dependency>
 	
@@ -33,6 +37,10 @@
 OBJ_EXT = .o
 LIB_EXT = .so
 APP_EXT =
+
+# ld flags
+UCX_SO_NAME =
+RPATH_WS_LIB_FLAG = -Wl,-rpath,'$$ORIGIN/../lib'
 		</make>
 	</dependency>
 	
@@ -47,6 +55,10 @@
 OBJ_EXT = .o
 LIB_EXT = .dylib
 APP_EXT =
+
+# ld flags
+UCX_SO_NAME = -install_name @rpath/libucx.dylib
+RPATH_WS_LIB_FLAG = -rpath @loader_path/../lib
 		</make>
 	</dependency>
 	
@@ -68,15 +80,21 @@
 	<dependency name="libxml2">
 		<pkgconfig>libxml-2.0</pkgconfig>
 	</dependency>
+	<dependency name="libxml2">
+		<cflags type="exec">xml2-config --cflags</cflags>
+		<lfglags type="exec">xml2-config --libs</lfglags>
+	</dependency>
 	
 	<dependency name="openssl">
 		<pkgconfig>openssl</pkgconfig>
 	</dependency>
 	
+	<!--
 	<dependency name="openssl">
 		<ldflags>-lssl -lcrypto</ldflags>
 	</dependency>
-	
+	-->
+
 	<!-- optional dependencies -->
 	<dependency name="libpq">
 		<pkgconfig>libpq</pkgconfig>
--- a/src/server/Makefile	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/Makefile	Thu Feb 23 21:09:33 2023 +0100
@@ -70,11 +70,12 @@
 $(MK_OBJ_DIRS):
 	mkdir -p $@
 
-$(MAIN_TARGET): preparation $(MAINOBJS) $(DAEMON_STARTOBJ)
-	$(CC) -o $(MAIN_TARGET) $(MAINOBJS) $(DAEMON_STARTOBJ) -L$(BUILD_ROOT)/build/lib $(LDFLAGS)
+$(MAIN_TARGET): preparation $(MAINOBJS) $(DAEMON_STARTOBJ) $(LIB_WSCFG)
+	$(CC) -o $(MAIN_TARGET) $(MAINOBJS) $(DAEMON_STARTOBJ) -L$(BUILD_ROOT)/build/lib $(LDFLAGS) $(RPATH_WS_LIB_FLAG)
 
 $(LIB_WSCFG): $(CONFOBJS)
-	$(CC) $(SHLIB_LDFLAGS) -o $@ $(CONFOBJS)
+	$(CC) $(SHLIB_LDFLAGS) -o $@ $(CONFOBJS) -L$(BUILD_ROOT)/build/lib -lucx
+
 
 $(TEST_TARGET): $(TESTOBJS) $(PLUGINS)
 	$(CC) -o $(TEST_TARGET) $(TESTOBJS) -L$(BUILD_ROOT)/build/lib $(LDFLAGS) $(TEST_PLUGIN_LDFLAGS)
--- a/src/server/config/acl.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/acl.c	Thu Feb 23 21:09:33 2023 +0100
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "acl.h"
+#include "logging.h"
 
 ACLFile* load_acl_file(const char *file) {
     FILE *in = fopen(file, "r");
@@ -115,7 +116,7 @@
     cxstring *tk = NULL; 
     ssize_t tkn = cx_strsplit_a(mp, cx_strcast(line), cx_str(":"), ACE_MAX_TOKENS, &tk);
     if(!tk || tkn < 3) {
-        log_ereport(LOG_FAILURE, "parse_ace: to few tokens: %.*s", (int)line.length, line.ptr);
+        ws_cfg_log(LOG_FAILURE, "parse_ace: to few tokens: %.*s", (int)line.length, line.ptr);
         return 1;
     }
     
@@ -158,7 +159,7 @@
     
     if(n >= tkn) {
         // to few tokens
-        log_ereport(LOG_FAILURE, "parse_ace: ace incomplete");
+        ws_cfg_log(LOG_FAILURE, "parse_ace: ace incomplete");
         return 1;
     }
     s = tk[n];
@@ -214,7 +215,7 @@
     }
     
     if(!complete) {
-        log_ereport(LOG_FAILURE, "parse_ace: ace incomplete");
+        ws_cfg_log(LOG_FAILURE, "parse_ace: ace incomplete");
         return 1;
     }
     
--- a/src/server/config/conf.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/conf.c	Thu Feb 23 21:09:33 2023 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "conf.h"
+#include "logging.h"
 
 #include <string.h>
 
@@ -271,7 +272,7 @@
  */
 ConfigDirective* cfg_parse_directive(cxmutstr line, CxAllocator *mp) {
     if(line.length < 6) {
-        log_ereport(LOG_FAILURE, "cfg_parse_directive: line too short");
+        ws_cfg_log(LOG_FAILURE, "cfg_parse_directive: line too short");
         return NULL; // line too short
     }
 
--- a/src/server/config/keyfile.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/keyfile.c	Thu Feb 23 21:09:33 2023 +0100
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 
 #include "keyfile.h"
+#include "logging.h"
 
 #define KEYFILE_MAX_TOKENS 4096
 
@@ -114,7 +115,7 @@
         entry->hashtype = KEYFILE_SSHA512;
     } else {
         // unkown hash type
-        log_ereport(
+        ws_cfg_log(
                 LOG_FAILURE,
                 "keyfile_parse: unknown hash type: %s",
                 cx_strdup_a(mp, hash_type).ptr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/config/logging.c	Thu Feb 23 21:09:33 2023 +0100
@@ -0,0 +1,27 @@
+//
+// Created by Olaf Wintermann on 23.02.23.
+//
+
+#include "logging.h"
+
+
+#include <stdio.h>
+
+int default_log_func(int degree, const char *format, va_list args) {
+    vprintf(format, args);
+    return 0;
+}
+
+static cfg_logfunc logfunc = default_log_func;
+
+int ws_cfg_log(int degree, const char *format, ...) {
+    va_list args;
+    va_start(args, format);
+    int ret = logfunc(degree, format, args);
+    va_end(args);
+    return ret;
+}
+
+void ws_cfg_set_logfunc(cfg_logfunc func) {
+    logfunc = func;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/config/logging.h	Thu Feb 23 21:09:33 2023 +0100
@@ -0,0 +1,48 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2023 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef CFG_LOGGING_H
+#define CFG_LOGGING_H
+
+#include <stdarg.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef int (*cfg_logfunc)(int degree, const char *format, va_list args);
+
+int ws_cfg_log(int degree, const char *format, ...);
+
+void ws_cfg_set_logfunc(cfg_logfunc func);
+
+
+#ifdef    __cplusplus
+}
+#endif
+
+#endif /* CFG_LOGGING_H */
--- a/src/server/config/mimeconf.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/mimeconf.c	Thu Feb 23 21:09:33 2023 +0100
@@ -32,13 +32,14 @@
 
 #include <cx/mempool.h>
 #include "mimeconf.h"
+#include "logging.h"
 
 #define MIMECONFIG_MAX_TOKENS 4096
 
 MimeConfig *load_mime_config(const char *file) {
     FILE *in = fopen(file, "r");
     if(in == NULL) {
-        log_ereport(LOG_FAILURE, "Cannot load mime config file %s: %s", file, strerror(errno));
+        ws_cfg_log(LOG_FAILURE, "Cannot load mime config file %s: %s", file, strerror(errno));
         return NULL;
     }
     
@@ -49,7 +50,7 @@
     conf->ntypes = 0;
     int r = cfg_parse_basic_file((ConfigParser*)conf, in);
     if(r != 0) {
-        log_ereport(LOG_FAILURE, "Cannot parse mime config file %s", file);
+        ws_cfg_log(LOG_FAILURE, "Cannot parse mime config file %s", file);
         fclose(in);
         free(conf);
         // TODO: free
--- a/src/server/config/objconf.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/objconf.c	Thu Feb 23 21:09:33 2023 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "objconf.h"
+#include "logging.h"
 
 #include <string.h>
 
@@ -233,7 +234,7 @@
         case LINE_BEGIN_TAG: {
             ConfigTag *tag = cfg_parse_begin_tag(line, conf->parser.mp);
             if(tag == NULL) {
-                log_ereport(LOG_FAILURE, "Parse error in %s", conf->file);
+                ws_cfg_log(LOG_FAILURE, "Parse error in %s", conf->file);
                 exit(-1); // TODO: better error handling
             }
             tag->begin = begin;
@@ -346,7 +347,7 @@
             break;
         }
         default: {
-            log_ereport(LOG_FAILURE, "objconf: unknown tag");
+            ws_cfg_log(LOG_FAILURE, "objconf: unknown tag");
             return 1;
         }
     }
@@ -357,7 +358,7 @@
 int objconf_on_end_tag(ObjectConfig *conf, cxmutstr tagname) {
     int type = cfg_get_tag_type(cx_strcast(tagname));
     if(type == -1) {
-        log_ereport(LOG_FAILURE, "objconf: unknown tag");
+        ws_cfg_log(LOG_FAILURE, "objconf: unknown tag");
         return 1;
     } else {
         if(type == TAG_OBJECT) {
--- a/src/server/config/objs.mk	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/config/objs.mk	Thu Feb 23 21:09:33 2023 +0100
@@ -37,6 +37,7 @@
 CONFOBJ += acl.o
 CONFOBJ += keyfile.o
 CONFOBJ += serverconfig.o
+CONFOBJ += logging.o
 
 CONFOBJS = $(CONFOBJ:%=$(CONF_OBJPRE)%)
 CONFSOURCE = $(CONFOBJ:%.o=config/%.c)
--- a/src/server/daemon/acl.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/daemon/acl.c	Thu Feb 23 21:09:33 2023 +0100
@@ -573,7 +573,7 @@
  */
 #ifdef OSX
 
-int fs_acl_check(SysACL *acl, User *user, char *path, uint32_t access_mask) {
+int fs_acl_check(SysACL *acl, User *user, const char *path, uint32_t access_mask) {
     return 1;
 }
 
@@ -587,7 +587,7 @@
 
 #endif
 
-#ifdef BSD
+#if defined(BSD) && !defined(OSX)
 
 int fs_acl_check(SysACL *acl, User *user, const char *path, uint32_t access_mask) {
     return 1;
--- a/src/server/daemon/httplistener.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/daemon/httplistener.c	Thu Feb 23 21:09:33 2023 +0100
@@ -73,7 +73,7 @@
  */
 static CxMap *listener_socket_map;
 
-static pthread_mutex_t listener_mutex;
+static pthread_mutex_t listener_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 
 int http_listener_global_init(void) {
@@ -82,8 +82,6 @@
         return 1;
     }
     
-    listener_mutex = PTHREAD_MUTEX_INITIALIZER;
-    
     return 0;
 }
 
--- a/src/server/webdav/webdav.c	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/server/webdav/webdav.c	Thu Feb 23 21:09:33 2023 +0100
@@ -1284,7 +1284,7 @@
         buf[HTTP_DATE_LEN] = 0;
         
         struct tm mtms;
-        struct tm *mtm = system_gmtime(&s->st_mtim.tv_sec, &mtms);
+        struct tm *mtm = system_gmtime(&s->st_mtime, &mtms);
         
         if(mtm) {
             strftime(buf, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm);
@@ -1307,7 +1307,7 @@
             96,
             "\"%x-%x\"",
             (int)s->st_size,
-            (int)s->st_mtim.tv_sec);
+            (int)s->st_mtime);
         if(webdav_resource_add_dav_stringproperty(res, pool, "getetag", buf, strlen(buf))) {
             return 1;
         }
--- a/src/ucx/Makefile	Sun Dec 04 13:01:00 2022 +0100
+++ b/src/ucx/Makefile	Thu Feb 23 21:09:33 2023 +0100
@@ -50,7 +50,7 @@
 all: $(BUILD_ROOT)/build/ucx $(BUILD_ROOT)/build/lib/libucx$(LIB_EXT)
 
 $(BUILD_ROOT)/build/lib/libucx$(LIB_EXT): $(OBJ)
-	$(CC) $(SHLIB_LDFLAGS) -o $@ $(OBJ)
+	$(CC) $(SHLIB_LDFLAGS) -o $@ $(OBJ) $(UCX_SO_NAME)
 
 $(BUILD_ROOT)/build/ucx/%$(OBJ_EXT): %.c
 	$(CC) $(CFLAGS) $(SHLIB_CFLAGS) -c -o $@ $<

mercurial