Skip to content

Commit

Permalink
Replace double colons with .PHONY targets
Browse files Browse the repository at this point in the history
  • Loading branch information
hmgle committed Feb 24, 2024
1 parent ded57d0 commit 09fa91f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 $@
24 changes: 13 additions & 11 deletions local/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@ 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

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
Expand All @@ -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)

0 comments on commit 09fa91f

Please sign in to comment.