src = $(wildcard src/*.c)
obj = $(src:.c=.o)
dep = $(obj:.o=.d)
lib_a = libpsys.a

ifeq ($(shell uname -s), Darwin)
	lib_so = psys.dylib
	shared = -dynamiclib
else
	somajor = 0
	sominor = 1
	soname = libpsys.so.$(somajor)
	lib_so = $(soname).$(sominor)
	solink = libpsys.so
	shared = -shared -Wl,-soname,$(soname)
endif


CC = gcc
AR = ar
CFLAGS = -std=c89 -pedantic -Wall -g -fPIC -Isrc
LDFLAGS = -lanim -limago -lvmath

.PHONY: all
all: $(lib_a) $(lib_so)

$(lib_a): $(obj)
	$(AR) rcs $@ $(obj)

$(lib_so): $(obj)
	$(CC) $(shared) -o $@ $(obj) $(LDFLAGS)

-include $(dep)

%.d: %.c
	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@


.PHONY: install
install: $(lib_a) $(lib_so)
	@echo TODO

.PHONY: uninstall
uninstall:
	@echo TODO

.PHONY: clean
clean:
	rm -f $(obj) $(lib_so) $(lib_a)
