From: Eric Wertz Date: Fri, 30 May 2025 23:57:34 +0000 (-0400) Subject: more updates to get linux build to work X-Git-Url: https://ericdwertz.com/git/?a=commitdiff_plain;h=ce89a9bca494fda197b055667f439b517c148d5f;p=listv4.git more updates to get linux build to work --- diff --git a/Makefile b/Makefile index cb3cdf0..4da2277 100644 --- 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 diff --git a/backend/main.cpp b/backend/main.cpp index c572ca3..aba716f 100644 --- a/backend/main.cpp +++ b/backend/main.cpp @@ -14,8 +14,6 @@ #include "HTTPRequest.h" #include "HTTPRequestRouter.h" -const int PORT = 9000; - std::map threadMap; std::vector 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 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) {