all:
########################################################################
# config.make includes common.make, which brings with it
# lots of utility code.
include config.make

FSL.SRC := \
	fossil2.c \
	fsl_appendf.c \
	fsl_buffer.c \
	fsl_db.c \
	fsl_fs.c \
	fsl_sha1.c \
	fsl_utf8.c

FSL.OBJ := $(subst .c,.o,$(FSL.SRC))

#fsl_sha1.o: CFLAGS+=-std=c89

########################################################################
# DLL/LIB...
libf2.LIB.OBJECTS := $(FSL.OBJ)
libf2.DLL.OBJECTS := $(libf2.LIB.OBJECTS)
$(eval $(call ShakeNMake.CALL.RULES.LIBS,libf2))
$(eval $(call ShakeNMake.CALL.RULES.DLLS,libf2))
all: $(libf2.LIB) $(libf2.DLL)

########################################################################
# Binary...
test.BIN.OBJECTS := test.o
test.BIN.LDFLAGS := -L. -lf2 -lsqlite3 -lz
$(eval $(call ShakeNMake.CALL.RULES.BIN,test))
all: $(test.BIN)

########################################################################
# A quick-n-dirty amalgamation build...
AMAL_C := libfossil2_amalgamation.c
AMAL_H := libfossil2_amalgamation.h
AMAL_C.SRC := \
	fsl_internal.h \
	$(FSL.SRC)

INCD := include/fossil
AMAL_H.SRC := $(INCD)/fossil.h

$(AMAL_H):
	@echo "Creating $@..."
	@{ \
		echo '#if !defined(FSL_AMALGAMATION_BUILD)'; \
		echo '#define FSL_AMALGAMATION_BUILD 1'; \
		echo '#endif'; \
	} > $@
	@{ \
		for i in $(AMAL_H.SRC); do \
			echo "/* start of file $$i */"; \
			cat $$i; \
			echo "/* end of file $$i */"; \
		done; \
	} | sed -e '/[ ]*#[ ]*include[ ]*.*fsl_.*\.h[">]/d' \
		 -e '/[ ]*#[ ]*include[ ]*.*fossil2.*\.h[">]/d' \
		>> $@

$(AMAL_C): $(AMAL_H)
	@echo "Creating $@..."
	@echo '#include "$(AMAL_H)"' > $@
	@{ \
		for i in $(AMAL_C.SRC); do \
			echo "/* start of file $$i */"; \
			cat $$i; \
			echo "/* end of file $$i */"; \
		done; \
	} | sed -e '/[ ]*#[ ]*include[ ]*.*fsl_.*\.h[">]/d' \
		 -e '/[ ]*#[ ]*include[ ]*.*fossil2.*\.h[">]/d' \
		>> $@

CLEAN_FILES += $(AMAL_H) $(AMAL_C)
amal: $(AMAL_C)
	gcc -c -pedantic -Wall -Werror -std=c89 $(AMAL_C)
# /amalgamation
########################################################################