diff --git a/Makefile b/Makefile index 22c46ab..5e074ad 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,8 @@ SRC := $(wildcard *.c) GRAFTCP_LOCAL_BIN = local/graftcp-local local/mgraftcp TARGET = graftcp $(GRAFTCP_LOCAL_BIN) -all:: $(TARGET) +.PHONY: all clean +all: $(TARGET) graftcp: main.o graftcp.o util.o cidr-trie.o conf.o @@ -73,30 +74,31 @@ local/graftcp-local: local/mgraftcp: libgraftcp.a $(MAKE) -C $(dir $@) VERSION=$(VERSION) CC=$(CC) CXX=$(CXX) AR=$(AR) $(notdir $@) -install:: graftcp $(GRAFTCP_LOCAL_BIN) +.PHONY: install uninstall install_graftcp uninstall_graftcp install_graftcp_local uninstall_graftcp_local + +install: graftcp $(GRAFTCP_LOCAL_BIN) $(INSTALL) $< $(DESTDIR)$(BINDIR)/$< $(MAKE) -C local $@ -uninstall:: +uninstall: -rm -f $(DESTDIR)$(BINDIR)/graftcp $(MAKE) -C local $@ -install_graftcp:: graftcp +install_graftcp: graftcp $(INSTALL) $< $(DESTDIR)$(BINDIR)/$< -uninstall_graftcp:: +uninstall_graftcp: -rm -f $(DESTDIR)$(BINDIR)/graftcp -install_systemd:: - $(MAKE) -C local install_systemd +.PHONY: install_systemd enable_systemd disable_systemd uninstall_systemd -uninstall_systemd:: - $(MAKE) -C local uninstall_systemd +%_systemd: + $(MAKE) -C local $@ -install_graftcp_local:: +install_graftcp_local: $(MAKE) -C local install -uninstall_graftcp_local:: +uninstall_graftcp_local: $(MAKE) -C local uninstall sinclude $(SRC:.c=.d) @@ -107,6 +109,6 @@ sinclude $(SRC:.c=.d) sed 's,\(.*\)\.o[:]*,\1.o $@:,' < $@.$$$$ > $@; \ rm -f $@.$$$$ -clean:: +clean: -rm -f *.o *.a graftcp *.d $(MAKE) -C local $@ diff --git a/local/Makefile b/local/Makefile index 8110bd0..0f0daf4 100644 --- a/local/Makefile +++ b/local/Makefile @@ -22,7 +22,9 @@ INSTALL = install -D TARGET = graftcp-local mgraftcp -all:: $(TARGET) +.PHONY: all clean ../libgraftcp.a install install_systemd enable_systemd disable_systemd uninstall_systemd uninstall install_service uninstall_service + +all: $(TARGET) graftcp-local: $(wildcard *.go cmd/graftcp-local/*.go) ${GO_BUILD_PREFIX_FLAGS} go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/graftcp-local @@ -30,15 +32,15 @@ graftcp-local: $(wildcard *.go cmd/graftcp-local/*.go) mgraftcp: $(wildcard *.go cmd/mgraftcp/*.go) ../libgraftcp.a ${GO_BUILD_PREFIX_FLAGS} ${CGO_FLAGS} go build -ldflags "-s -w -X main.version=${VERSION}" ./cmd/mgraftcp -../libgraftcp.a:: +../libgraftcp.a: $(MAKE) -C .. libgraftcp.a -install:: $(TARGET) +install: $(TARGET) $(INSTALL) $^ $(DESTDIR)$(BINDIR)/ SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null) -install_systemd:: install +install_systemd: install $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) test -f $(DESTDIR)/etc/graftcp-local/graftcp-local.conf || \ install -Dm644 example-graftcp-local.conf $(DESTDIR)/etc/graftcp-local/graftcp-local.conf @@ -47,26 +49,26 @@ ifneq ($(PREFIX),/usr/) sed -i -re 's#/usr/bin/graftcp-local#$(subst #,\#,${PREFIX})/bin/graftcp-local#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/graftcp-local.service endif -enable_systemd:: +enable_systemd: @echo "Enable and start the graftcp-local systemd unit" systemctl daemon-reload && systemctl --now enable graftcp-local.service -disable_systemd:: +disable_systemd: @echo "Disable and stop the graftcp-local systemd unit" systemctl disable --now graftcp-local.service -uninstall_systemd:: disable_systemd +uninstall_systemd: disable_systemd $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/graftcp-local.service -uninstall:: +uninstall: -rm -f $(DESTDIR)$(BINDIR)/mgraftcp $(DESTDIR)$(BINDIR)/graftcp-local -install_service:: graftcp-local +install_service: graftcp-local graftcp-local -service install && graftcp-local -service start -uninstall_service:: graftcp-local +uninstall_service: graftcp-local graftcp-local -service stop && graftcp-local -service uninstall -clean:: +clean: -rm -rf $(TARGET)