@@ -14,6 +14,17 @@ PG_INCLUDEDIR := $(shell $(PG_CONFIG) --includedir-server 2>/dev/null)
1414EXTENSION = cloudsync
1515EXTVERSION = 1.0
1616
17+ # Platform-specific PostgreSQL settings
18+ ifeq ($(OS),Windows_NT)
19+ PG_EXTENSION_LIB = $(EXTENSION).dll
20+ PG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
21+ PG_LDFLAGS = -shared -L$(shell $(PG_CONFIG) --libdir) -lpostgres
22+ else
23+ PG_EXTENSION_LIB = $(EXTENSION).so
24+ PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
25+ PG_LDFLAGS = -shared
26+ endif
27+
1728# Source files - core platform-agnostic code
1829PG_CORE_SRC = \
1930 src/cloudsync.c \
@@ -38,23 +49,24 @@ PG_OBJS = $(PG_ALL_SRC:.c=.o)
3849# Compiler flags
3950# Define POSIX macros as compiler flags to ensure they're defined before any includes
4051PG_CPPFLAGS = -I$(PG_INCLUDEDIR) -Isrc -Isrc/postgresql -Imodules/fractional-indexing -DCLOUDSYNC_POSTGRESQL_BUILD -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE
41- PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -O2
4252PG_DEBUG ?= 0
4353ifeq ($(PG_DEBUG),1)
54+ ifeq ($(OS),Windows_NT)
55+ PG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer
56+ else
4457PG_CFLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -std=c11 -g -O0 -fno-omit-frame-pointer
4558endif
46- PG_LDFLAGS = -shared
59+ endif
4760
4861# Output files
49- PG_EXTENSION_SO = $(EXTENSION).so
5062PG_EXTENSION_SQL = src/postgresql/$(EXTENSION)--$(EXTVERSION).sql
5163PG_EXTENSION_CONTROL = docker/postgresql/$(EXTENSION).control
5264
5365# ============================================================================
5466# PostgreSQL Build Targets
5567# ============================================================================
5668
57- .PHONY: postgres-check postgres-build postgres-install postgres-clean postgres-test \
69+ .PHONY: postgres-check postgres-build postgres-install postgres-package postgres- clean postgres-test \
5870 postgres-docker-build postgres-docker-build-asan postgres-docker-run postgres-docker-run-asan postgres-docker-stop postgres-docker-rebuild \
5971 postgres-docker-debug-build postgres-docker-debug-run postgres-docker-debug-rebuild \
6072 postgres-docker-shell postgres-dev-rebuild postgres-help unittest-pg \
@@ -78,16 +90,16 @@ postgres-build: postgres-check
7890 echo " CC $$src"; \
7991 $(CC) $(PG_CPPFLAGS) $(PG_CFLAGS) -c $$src -o $${src%.c}.o || exit 1; \
8092 done
81- @echo "Linking $(PG_EXTENSION_SO )..."
82- $(CC) $(PG_LDFLAGS) -o $(PG_EXTENSION_SO ) $(PG_OBJS)
83- @echo "Build complete: $(PG_EXTENSION_SO )"
93+ @echo "Linking $(PG_EXTENSION_LIB )..."
94+ $(CC) $(PG_LDFLAGS) -o $(PG_EXTENSION_LIB ) $(PG_OBJS)
95+ @echo "Build complete: $(PG_EXTENSION_LIB )"
8496
8597# Install extension to PostgreSQL
8698postgres-install: postgres-build
8799 @echo "Installing CloudSync extension to PostgreSQL..."
88100 @echo "Installing shared library to $(PG_PKGLIBDIR)/"
89101 install -d $(PG_PKGLIBDIR)
90- install -m 755 $(PG_EXTENSION_SO ) $(PG_PKGLIBDIR)/
102+ install -m 755 $(PG_EXTENSION_LIB ) $(PG_PKGLIBDIR)/
91103 @echo "Installing SQL script to $(PG_SHAREDIR)/extension/"
92104 install -d $(PG_SHAREDIR)/extension
93105 install -m 644 $(PG_EXTENSION_SQL) $(PG_SHAREDIR)/extension/
@@ -98,10 +110,21 @@ postgres-install: postgres-build
98110 @echo "To use the extension, run in psql:"
99111 @echo " CREATE EXTENSION $(EXTENSION);"
100112
113+ # Package extension files for distribution
114+ PG_DIST_DIR = dist/postgresql
115+
116+ postgres-package: postgres-build
117+ @echo "Packaging PostgreSQL extension..."
118+ @mkdir -p $(PG_DIST_DIR)
119+ cp $(PG_EXTENSION_LIB) $(PG_DIST_DIR)/
120+ cp $(PG_EXTENSION_SQL) $(PG_DIST_DIR)/
121+ cp $(PG_EXTENSION_CONTROL) $(PG_DIST_DIR)/
122+ @echo "Package ready in $(PG_DIST_DIR)/"
123+
101124# Clean PostgreSQL build artifacts
102125postgres-clean:
103126 @echo "Cleaning PostgreSQL build artifacts..."
104- rm -f $(PG_OBJS) $(PG_EXTENSION_SO )
127+ rm -f $(PG_OBJS) $(PG_EXTENSION_LIB )
105128 @echo "Clean complete"
106129
107130# Test extension (requires running PostgreSQL)
0 commit comments