# SumOffice C SDK example (macOS, Linux; on Windows use MinGW make or CMake).
#
#   make            build open_save against the SDK two folders up
#   make run        edit the three files in samples/ and write out/edited.*
#   make SDK=/opt/sumoffice-c-2026.4.5-linux-x64
#
# The libraries are found at run time through an rpath relative to the executable, so the
# SDK folder can be moved as a whole. Linking against the dynamic libraries is the only
# supported way: each core carries its own Rust runtime.
SDK    ?= ../..
CC     ?= cc
CFLAGS ?= -O2 -Wall -Wextra -std=c11

UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
  RPATH := -Wl,-rpath,@executable_path/$(SDK)/lib
else
  RPATH := -Wl,-rpath,'$$ORIGIN/$(SDK)/lib'
endif
LIBS := -L$(SDK)/lib -lsumsheet -lsumdoc -lsumslide

all: open_save

open_save: open_save.c
	$(CC) $(CFLAGS) -I$(SDK)/include $< $(LIBS) $(RPATH) -o $@

run: open_save
	mkdir -p out
	./open_save samples/sample.xlsx out/edited.xlsx
	./open_save samples/sample.docx out/edited.docx
	./open_save samples/sample.pptx out/edited.pptx

clean:
	rm -rf open_save out

.PHONY: all run clean
