COMMIT_REV ?= $(shell git describe  --always --abbrev=12)
CFLAGS += -I. -I$(shell pwd)/../../syno-mem-saving-driver -DCOMMIT_REV="\"$(COMMIT_REV)\"" -g
ifeq ($(SYNO_FLASHCACHE), 1)
PROGRAMS += flashcache_create flashcache_destroy flashcache_load flashcache_expand flashcache_rescue flashcache_enable flashcache_disable
else
PROGRAMS += flashcache_create flashcache_destroy flashcache_load
endif
ifeq ($(SUPPORT_4K_CACHE), 1)
CFLAGS +=-DSUPPORT_4K_CACHE
endif

INSTALL_DIR = $(DESTDIR)/sbin/

.PHONY:all
ifeq ($(SYNO_FLASHCACHE), 1)
all: $(PROGRAMS)
else
all: $(PROGRAMS)
endif

flashcache_create: flashcache_create.o load_modules.o
	$(CC) $^ -o $@

-include flashcache_create.d

flashcache_destroy: flashcache_destroy.o
	$(CC) $^ -o $@

-include flashcache_destroy.d

flashcache_load: flashcache_load.o load_modules.o
	$(CC) $^ -o $@

-include flashcache_load.d

ifeq ($(SYNO_FLASHCACHE), 1)
flashcache_expand: flashcache_expand.o
	$(CC) $^ -o $@

-include flashcache_expand.d

flashcache_rescue: flashcache_rescue.o
	$(CC) $^ -o $@

-include flashcache_rescue.d

flashcache_enable: flashcache_enable.o
	$(CC) $^ -o $@

-include flashcache_enable.d

flashcache_disable: flashcache_disable.o
	$(CC) $^ -o $@

-include flashcache_disable.d
endif

%.o: %.c
	$(CC) -c $(CFLAGS) $*.c -o $*.o
	@$(CC) -MM $(CFLAGS) -MF $*.d -MT $*.o $*.c

.PHONY: install
install: $(PROGRAMS)
	install -d -m 755 $(INSTALL_DIR)
	install -m 755 $(PROGRAMS) $(INSTALL_DIR)

.PHONY: clean
clean:
	rm -f *.[od] $(PROGRAMS)

