From d52c2a2c319ff866906f5072cc5730bf05e4bf35 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Mon, 9 Mar 2015 13:02:08 +0000 Subject: Update makefile to better standards and practices. Makefile now installs to /usr/local/bin by default. Makefile now uses lower-case bindir and prefix. Makefile name changed from makefile to Makefile. Added DEBUG mode with alternate CFLAGS to makefile. LDLIBS can now be used to specify link libraries. Removed redundant target which now uses implicit target. --- Makefile | 33 +++++++++++++++++++++++++++++++++ makefile | 27 --------------------------- 2 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 Makefile delete mode 100644 makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d6edc4 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +CFLAGS = -std=gnu11 -Wall -Wextra +LDFLAGS = -Wl,--as-needed + +ifeq ($(DEBUG), 1) + CFLAGS += -Og -g +else + CFLAGS += -O2 +endif + +INSTALL = install -m755 + +prefix = /usr/local +bindir = $(prefix)/bin + +all: + @echo 'Error, target not specified.' + @echo ' To compile .c `make `' + @echo ' To install `make target= install`' + @echo ' To uninstall `make target= uninstall`' + + +$(DESTDIR)$(bindir)/%: % + $(INSTALL) $^ $(DESTDIR)$(bindir) + +install: $(DESTDIR)$(bindir)/$(target) + +uninstall: + $(RM) "$(DESTDIR)$(bindir)/$(target)" + +clean: + find . -mindepth 1 -maxdepth 1 -executable -type f ! -name "prefix_header" -delete + +.PHONY : all install uninstall clean diff --git a/makefile b/makefile deleted file mode 100644 index 4bffe01..0000000 --- a/makefile +++ /dev/null @@ -1,27 +0,0 @@ -CFLAGS = -Wall -Wextra -Wpedantic -O2 -std=gnu11 - -PREFIX = /usr -BINDIR = /bin -INSPATH = $(DESTDIR)$(PREFIX)$(BINDIR) - -.PHONY : all install uninstall - -all: - @echo 'Error, target not specified.' - @echo ' To compile .c `make `' - @echo ' To install `make target= install`' - @echo ' To uninstall `make target= uninstall`' - -% : %.c - $(CC) $(CFLAGS) -o $@ $^ - -$(DESTDIR)$(PREFIX)$(BINDIR)/% : % - install -Dm755 "$^" "$@" - -install : $(DESTDIR)$(PREFIX)$(BINDIR)/$(target) - -uninstall : - rm "$(DESTDIR)$(PREFIX)$(BINDIR)/$(target)" - -clean : - find . -mindepth 1 -maxdepth 1 -executable -type f ! -name "prefix_header" -delete -- cgit v1.2.3-54-g00ecf