Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

TARGET = pg_query
ARLIB = $(TARGET).lib
SOLIB = lib$(TARGET).dll
DEF = lib$(TARGET).def
PWSH_EXE = pwsh.exe
GENERATE_DEF_SCRIPT = scripts/generate_def.ps1

SRC_FILES = src/*.c src/postgres/*.c vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c

Expand All @@ -13,16 +17,27 @@ all: examples test build

build: $(ARLIB)

build_shared: $(SOLIB)

clean:
$(RM) *.obj
$(RM) pg_query.lib
if exist *.obj $(RM) *.obj
if exist $(ARLIB) $(RM) $(ARLIB)
if exist $(SOLIB) $(RM) $(SOLIB)
if exist $(DEF) $(RM) $(DEF)

create_def:
$(PWSH_EXE) $(GENERATE_DEF_SCRIPT)

.PHONY: all clean build build_shared extract_source examples test install
.PHONY: all clean build build_shared extract_source examples test install create_def

$(ARLIB): clean $(SRC_FILES)
$(CC) $(CFLAGS) /c $(SRC_FILES)
lib /OUT:pg_query.lib *.obj

$(SOLIB): clean create_def $(SRC_FILES)
$(CC) $(CFLAGS) /c $(SRC_FILES)
link /DLL /DEF:$(DEF) /OUT:$(SOLIB) *.obj

EXAMPLES = examples/simple examples/scan examples/normalize examples/simple_error examples/normalize_error examples/simple_plpgsql
examples: $(EXAMPLES)
.\examples\simple
Expand Down
18 changes: 18 additions & 0 deletions scripts/generate_def.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env pwsh

$functions = Get-Content pg_query.h | ForEach-Object {
if ($_ -cmatch '\b(pg_query_\w+)\s*\(') {
$fn = $matches[1]
if ($fn -ne "pg_query_init") {
" $fn"
}
}
}

$output = @(
"LIBRARY libpg_query"
"EXPORTS"
) + $functions

$output | Set-Content libpg_query.def