$(call ShakeNMake.CALL.CLEAN-SET,client-fnc)
ifneq (1,$(MAKING_CLEAN))
client-fnc: all
endif
DIR.fnc := $(DIR.client)/fnc
FNC.MAKEFILE := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
ifeq (,$(LIB_CURSES))
$(error Expecting LIB_CURSES to be set by the configure process.)
endif
fnc.CPPFLAGS += $(CFLAGS_CURSES)

########################################################################
# To build fnc, we need the curses and pthread libraries.
# -lz is for libfossil
# -liconv is for libfossil on macOS
# -lutil is... ???
# -lm is for sqlite3
FNC_LDFLAGS := $(LIBF_STATIC_CLIENT_LDFLAGS)
PLATFORM := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
ifneq ($(filter $(PLATFORM),Darwin),)
  FNC_LDFLAGS += -liconv
endif
FNC_LDFLAGS += $(LIB_CURSES) -lutil -lpthread
# This is needed for Mac builds, else they don't see the
# wide-char curses APIs:
fnc.CPPFLAGS += -D_XOPEN_SOURCE_EXTENDED

DFNC := $(DIR.fnc)/fnc
$(DFNC).BIN.OBJECTS += $(DFNC).o
$($(DFNC).BIN.OBJECTS): $(libfossil.h) $(FNC.MAKEFILE)
$(DFNC).BIN.LDFLAGS := $(FNC_LDFLAGS)
$(eval $(call ShakeNMake.CALL.RULES.BIN,$(DFNC)))
$($(DFNC).BIN): $(LIBF_STATIC_CLIENT_OBJ_DEPS)
all: $($(DFNC).BIN)
CLEAN.client-fnc := $($(DFNC).BIN) $($(DFNC).BIN.OBJECTS)
$(fnc.BIN.OBJECTS): $(LIBF_STATIC_CLIENT_OBJ_DEPS)
$(fnc.BIN.OBJECTS): CPPFLAGS+=$(fnc.CPPFLAGS)

ShakeNMake.install.bins += $($(DFNC).BIN)
ShakeNMake.install.man1 += $(DIR.fnc)/fnc.1
CLEAN.client-fnc += $(wildcard $(DIR.fnc)/*~)
