]> Eric's Git Repo - listv4.git/commitdiff
more updates to get linux build to work
authorEric Wertz <ericwertz@Erics-MacBook-Pro.local>
Fri, 30 May 2025 23:57:34 +0000 (19:57 -0400)
committerEric Wertz <ericwertz@Erics-MacBook-Pro.local>
Fri, 30 May 2025 23:57:34 +0000 (19:57 -0400)
Makefile
backend/main.cpp

index cb3cdf00bb5cec9af5e61a74ed1e37327dbf0715..4da2277dd4c47de7028b9b7963dc81dce2a2ebc2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,10 +16,10 @@ CFLAGS = -Wall -Wextra -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-strong
 INCLUDES = -I$(SRC_DIR) -I$(OPENSSL_PATH)/include
 
 # Link flags
-LDFLAGS_BASE = -L$(OPENSSL_PATH)/lib -lssl -lcrypto -framework Security
+LDFLAGS_BASE = -L$(OPENSSL_PATH)/lib -lssl -lcrypto
 
 ifeq ($(OS),Darwin)
-  LDFLAGS_OS_SPECIFIC = -Wl,-dead_strip
+  LDFLAGS_OS_SPECIFIC = -Wl,-dead_strip -framework Security
 else # Default to Linux/GNU ld behavior (e.g., Linux)
   LDFLAGS_OS_SPECIFIC = -Wl,--gc-sections
 endif
@@ -82,8 +82,17 @@ $(BUILD_DIR)/sqlite3.o: $(SRC_DIR)/sqlite3.c
 $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
        $(CC) $(CFLAGS) $(INCLUDES) -MMD -MP -c $< -o $@
 
+# Frontend dependencies installation
+frontend-deps:
+       @if [ ! -d "$(FRONTEND_SRC)/node_modules" ]; then \
+               echo "Installing frontend dependencies..."; \
+               cd $(FRONTEND_SRC) && npm install; \
+       else \
+               echo "Frontend dependencies already installed."; \
+       fi
+
 # Frontend build
-frontend:
+frontend: frontend-deps
        rm -rf $(BUILD_DIR)/www/*
        cd $(FRONTEND_SRC) && NODE_ENV=production node esbuild.config.js || (echo "Frontend build failed" && exit 1)
        @if [ ! -f $(BUILD_DIR)/www/bundle.js ]; then \
@@ -119,4 +128,4 @@ run-decrypt: $(DECRYPT_TARGET)
 -include $(DEPS)
 
 # Phony targets
-.PHONY: all clean setup run frontend run-decrypt 
\ No newline at end of file
+.PHONY: all clean setup run frontend frontend-deps run-decrypt 
\ No newline at end of file
index c572ca3a61a280d4711b56c9d40db32b4df52035..aba716fdb4e13a699dc5fa97df9bc4a4f23d576a 100644 (file)
@@ -14,8 +14,6 @@
 #include "HTTPRequest.h"
 #include "HTTPRequestRouter.h"
 
-const int PORT = 9000;
-
 std::map<int,std::thread> threadMap;
 std::vector<int> completeThreads;
 std::mutex threadMapLock;
@@ -52,7 +50,41 @@ void handle_client(int thread_id, int client_socket) {
     lk.unlock();
 }
 
-int main() {
+void print_usage(const char* program_name) {
+    std::cout << "Usage: " << program_name << " [options]\n";
+    std::cout << "Options:\n";
+    std::cout << "  -p <port>    Port to listen on (default: 9000)\n";
+    std::cout << "  -h           Show this help message\n";
+}
+
+int main(int argc, char* argv[]) {
+    int port = 9000;  // Default port
+    
+    // Parse command line arguments
+    for (int i = 1; i < argc; i++) {
+        if (strcmp(argv[i], "-p") == 0) {
+            if (i + 1 < argc) {
+                port = atoi(argv[i + 1]);
+                if (port <= 0 || port > 65535) {
+                    std::cerr << "Error: Invalid port number. Must be between 1 and 65535.\n";
+                    return 1;
+                }
+                i++; // Skip the next argument since we've used it as the port number
+            } else {
+                std::cerr << "Error: -p flag requires a port number.\n";
+                print_usage(argv[0]);
+                return 1;
+            }
+        } else if (strcmp(argv[i], "-h") == 0) {
+            print_usage(argv[0]);
+            return 0;
+        } else {
+            std::cerr << "Error: Unknown argument " << argv[i] << "\n";
+            print_usage(argv[0]);
+            return 1;
+        }
+    }
+
     int server_socket;
     struct sockaddr_in server_address;
 
@@ -66,7 +98,7 @@ int main() {
     // Set up the server address
     server_address.sin_family = AF_INET;
     server_address.sin_addr.s_addr = INADDR_ANY;
-    server_address.sin_port = htons(PORT);
+    server_address.sin_port = htons(port);
 
     // Bind the socket to the port
     if (bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) {
@@ -80,7 +112,7 @@ int main() {
         return 1;
     }
 
-    std::cout << "Server is running on port " << PORT << "\n";
+    std::cout << "Server is running on port " << port << "\n";
 
     unsigned int threadId = 0;
     while (true) {