Skip to content

Commit 472e06e

Browse files
committed
Makefile: modernize with usual conventions
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 482ed94 commit 472e06e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

Makefile

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
prefix = /usr/local
2-
1+
PREFIX ?= /usr
2+
DESTDIR ?=
3+
BINDIR ?= $(PREFIX)/bin
34
CFLAGS ?= -g -O2
4-
55
INSTALL ?= install
66
PKG_CONFIG ?= pkg-config
77

88
ifeq ($(shell $(PKG_CONFIG) --exists libsystemd || echo NO),)
9-
DEFS += -DHAVE_SYSTEMD_SD_DAEMON_H $(shell $(PKG_CONFIG) --cflags libsystemd)
10-
LDADD += $(shell $(PKG_CONFIG) --libs libsystemd)
9+
CPPFLAGS += -DHAVE_SYSTEMD_SD_DAEMON_H $(shell $(PKG_CONFIG) --cflags libsystemd)
10+
LDLIBS += $(shell $(PKG_CONFIG) --libs libsystemd)
1111
endif
1212

13-
CPPFLAGS += $(DEFS) $(INCLUDES)
13+
CFLAGS += -MMD -MP
14+
CFLAGS += -Wall -Wextra
1415

1516
OBJECTS := log.o network.o utils.o udptunnel.o
1617

17-
all: depend udptunnel
18+
ifneq ($(V),1)
19+
BUILT_IN_LINK.o := $(LINK.o)
20+
LINK.o = @echo " LD $@";
21+
LINK.o += $(BUILT_IN_LINK.o)
22+
BUILT_IN_COMPILE.c := $(COMPILE.c)
23+
COMPILE.c = @echo " CC $@";
24+
COMPILE.c += $(BUILT_IN_COMPILE.c)
25+
endif
26+
27+
all: udptunnel
1828

19-
install:
20-
$(INSTALL) -d $(BASEDIR)$(prefix)/sbin/
21-
$(INSTALL) -m 0755 udptunnel $(BASEDIR)$(prefix)/sbin/
29+
install: udptunnel
30+
@$(INSTALL) -v -d "$(DESTDIR)$(BINDIR)" && install -v -m 0755 udptunnel "$(DESTDIR)$(BINDIR)/udptunnel"
2231

2332
clean:
24-
rm -f Makefile.depend $(OBJECTS) udptunnel
25-
26-
%.o: %.c
27-
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
33+
@$(RM) -vf $(OBJECTS) $(OBJECTS:%.o=%.d) udptunnel
2834

2935
udptunnel: $(OBJECTS)
30-
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDADD) $(LIBS)
31-
32-
depend: Makefile.depend
33-
Makefile.depend:
34-
$(CC) $(CPPFLAGS) $(CFLAGS) -MM -MG *.c > $@
3536

36-
-include Makefile.depend
37+
.PHONY: all install clean
38+
-include *.d

0 commit comments

Comments
 (0)