NAME=gitlin
VERSION=1.0.0
#VERSION=$(cat utils/version.go | grep "var Ver" | awk '{print $4}' | sed "s/\"//g")
# Linux、Solaris、Haiku
PREFIX=/usr
# FreeBSD、OpenBSD
#PREFIX=/usr/local
# NetBSD
#PREFIX=/usr/pkg
# Linux、OpenBSD、Solaris、Haiku
CNFPREFIX=/etc
# FreeBSD
#CNFPREFIX=/usr/local/etc
# NetBSD
#CNFPREFIX=/usr/pkg/etc
CC=CGO_ENABLED=0 go build
# リリース。なし＝デバッグ。
RELEASE=-ldflags="-s -w" -buildvcs=false

all:
	${CC} ${RELEASE} -o ${NAME}

clean:
	rm -f ${NAME} ${NAME}-${VERSION}.tar.gz

dist: clean
	mkdir -p ${NAME}-${VERSION}
	cp -R LICENSE Makefile README.md CHANGELOG.md\
		cmd pages public serve utils views go.sum go.mod logo.png\
		main.go ${NAME}-${VERSION}
	tar zcfv ${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
	rm -rf ${NAME}-${VERSION}

install:
	mkdir -p ${DESTDIR}/var/${NAME}
	chmod 755 ${DESTDIR}/var/${NAME}
	cp -rf views ${DESTDIR}/var/${NAME}
	cp -rf public ${DESTDIR}/var/${NAME}
	mkdir -p ${DESTDIR}${PREFIX}/bin
	cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
	chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
	mkdir -p ${DESTDIR}${CNFPREFIX}/${NAME}
	chmod 755 ${DESTDIR}${CNFPREFIX}/${NAME}
	touch ${DESTDIR}${CNFPREFIX}/${NAME}/${NAME}.conf
	chmod 644 ${DESTDIR}${CNFPREFIX}/${NAME}/${NAME}.conf

uninstall:
	rm -f ${DESTDIOR}${PREFIX}/bin/${NAME}\
		${DESTDIR}${MANPREFIX}/man1/${NAME}.1\
		${DESTDIR}${CNFPREFIX}/${NAME}

.PHONY: all options clean dist install uninstall
