tenseleyflow/gitswitch / a888e45

Browse files

mac os needs platform flags

Authored by espadonne
SHA
a888e45f5afffca8116c766f536460908712f45f
Parents
6da7240
Tree
24d5e1d

1 changed file

StatusFile+-
M Makefile 30 10
Makefilemodified
@@ -14,21 +14,41 @@ BINDIR = $(BUILDDIR)/bin
1414
 TESTDIR = tests
1515
 DOCDIR = docs
1616
 
17
+# Platform detection
18
+UNAME_S := $(shell uname -s)
19
+
1720
 # Compiler and flags
1821
 CC = gcc
1922
 CFLAGS = -std=c11 -Wall -Wextra -Wstrict-prototypes \
2023
          -Wmissing-prototypes -Wold-style-definition -Wredundant-decls \
21
-         -Wbad-function-cast -Wnested-externs -Winit-self -Wlogical-op \
24
+         -Wbad-function-cast -Wnested-externs -Winit-self \
2225
          -Wshadow -Wwrite-strings -Wcast-align -Wstrict-aliasing=2 \
23
-         -Wmissing-include-dirs -Wdate-time -Wformat=2 -Winit-self \
26
+         -Wmissing-include-dirs -Wformat=2 -Winit-self \
2427
          -Wswitch-default -Wunused -Werror-implicit-function-declaration
2528
 
26
-# Security hardening flags
27
-SECURITY_FLAGS_DEBUG = -fstack-protector-strong -fstack-clash-protection -fcf-protection \
28
-                      -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
29
-SECURITY_FLAGS_RELEASE = -D_FORTIFY_SOURCE=2 -fstack-protector-strong \
30
-                        -fstack-clash-protection -fcf-protection \
31
-                        -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
29
+# Platform-specific flags
30
+ifeq ($(UNAME_S),Linux)
31
+    # GCC-specific warnings
32
+    CFLAGS += -Wlogical-op -Wdate-time
33
+    # Linux-specific security flags
34
+    SECURITY_FLAGS_DEBUG = -fstack-protector-strong -fstack-clash-protection -fcf-protection \
35
+                          -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
36
+    SECURITY_FLAGS_RELEASE = -D_FORTIFY_SOURCE=2 -fstack-protector-strong \
37
+                            -fstack-clash-protection -fcf-protection \
38
+                            -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack
39
+endif
40
+
41
+ifeq ($(UNAME_S),Darwin)
42
+    # macOS-specific security flags (no cf-protection, stack-clash-protection, or Linux linker flags)
43
+    SECURITY_FLAGS_DEBUG = -fstack-protector-strong
44
+    SECURITY_FLAGS_RELEASE = -D_FORTIFY_SOURCE=2 -fstack-protector-strong
45
+    # macOS OpenSSL paths (Homebrew)
46
+    OPENSSL_PREFIX := $(shell brew --prefix openssl@3 2>/dev/null || brew --prefix openssl 2>/dev/null)
47
+    ifneq ($(OPENSSL_PREFIX),)
48
+        INCLUDES += -I$(OPENSSL_PREFIX)/include
49
+        LDFLAGS += -L$(OPENSSL_PREFIX)/lib
50
+    endif
51
+endif
3252
 
3353
 # Debug/Release configurations  
3454
 DEBUG_FLAGS = -g -O0 -DDEBUG -fsanitize=address -fsanitize=undefined \
@@ -92,7 +112,7 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(OBJDIR)
92112
 # Link main executable
93113
 $(BINDIR)/$(TARGET): $(OBJECTS) | $(BINDIR)
94114
 	@echo "Linking $@..."
95
-	$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LIBS)
115
+	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)
96116
 	@echo "Build complete: $@"
97117
 
98118
 # Install target
@@ -118,7 +138,7 @@ $(OBJDIR)/test_%.o: $(TESTDIR)/%.c $(HEADERS) | $(OBJDIR)
118138
 # Test executables (exclude main.o to avoid multiple main functions)
119139
 $(BINDIR)/test_%: $(OBJDIR)/test_%.o $(filter-out $(OBJDIR)/main.o,$(OBJECTS)) | $(BINDIR)
120140
 	@echo "Linking test $@..."
121
-	$(CC) $(CFLAGS) $^ -o $@ $(LIBS)
141
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
122142
 
123143
 # Build and run tests
124144
 .PHONY: test