
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo


SUFFIXES = .go
OBJEXT= none

if DEV_MODE
noinst_PROGRAMS = webservd
else
sbin_PROGRAMS = webservd
endif

BUILD = $(shell date -u '+%Y-%m-%d-%H%M')
GOFLAGS = -v -ldflags='-s -w -X webserv/internal/config.defaultBuild=$(BUILD)'

webservd_SOURCES = cmd/webservd/main.go
webservd$(EXEEXT): $(webservd_SOURCES) $(EXTRA_webservd_SOURCES)
	env CGO_ENABLED=0 $(GO) build $(GOFLAGS) -o webservd$(EXEEXT) $(webservd_SOURCES)


EXTRA_webservd_SOURCES = 

EXTRA_DIST = $(EXTRA_webservd_SOURCES) 

gformat:
	for dir in $$(find internal pkg cmd -type d); do \
	  (cd $$dir && $(GO) fmt .); \
	done

run:
	env CGO_ENABLED=0 $(GO) run $(GOFLAGS) ./cmd/webservd/...

distclean-local:
	rm -rf autom4te.cache

SWAG_OUTDIR = ./pkg/swaginfo
SWAG_OPTS = -q --parseDependency \
	--parseInternal \
	--parseDepth 2 \
	--exclude pkg,works,assets \
	--outputTypes go,json \
	--generatedTime \
	--output $(SWAG_OUTDIR)

swag:
	mkdir -p $(SWAG_OUTDIR)
	swag init $(SWAG_OPTS) -g ./cmd/webservd/main.go 


FREEBSD_LOCALBASE = /usr/local
FREEBSD_RCDIR = $(FREEBSD_LOCALBASE)/etc/rc.d
LINUX_SYSTEMDDIR = /lib/systemd/system


install-data-local:
	test -z $(DESTDIR)$(srv_logdir) || $(MKDIR_P) $(DESTDIR)$(srv_logdir)
	test -z $(DESTDIR)$(srv_rundir) || $(MKDIR_P) $(DESTDIR)$(srv_rundir)
	test -z $(DESTDIR)$(srv_datadir) || $(MKDIR_P) $(DESTDIR)$(srv_datadir)
if FREEBSD_OS
	test -z $(DESTDIR)$(FREEBSD_RCDIR) || $(MKDIR_P) $(DESTDIR)$(FREEBSD_RCDIR)
	$(INSTALL_DATA) initrc/webservd $(DESTDIR)$(FREEBSD_RCDIR)
	chmod a+x $(DESTDIR)$(FREEBSD_RCDIR)/webservd
endif
if LINUX_OS
if SYSTEMD
	test -z $(DESTDIR)$(LINUX_SYSTEMDDIR) || $(MKDIR_P) $(DESTDIR)$(LINUX_SYSTEMDDIR)
	$(INSTALL_DATA) initrc/webservd.service $(DESTDIR)$(LINUX_SYSTEMDDIR)
endif
endif



clean-local:
	rm -rf autom4te.cache
	rm -f cmd/webservd/webservd
	rm -f cmd/webservctl/webservctl
	rm -f webservd.log
	rm -f webservd.pid
