From c657ed047c9904504292a09f02c6866f055a8a40 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 19 May 2024 05:29:13 +0400 Subject: [PATCH] Made a proper Makefile as it should be fixing many errors, like ignoring VAR overwriting. Also, wherever meaningful, = was replaced with := that evaluates once. Also made use of so-called "Order-only prerequisites" in an install target to build a program if it is not already built. Also removed a dangerous rm -rf with rm -f for a LICENSE file and rmdir for a directory. --- Makefile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e8559da..ec8b48f 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ -TARGET=kwh-cost +TARGET := kwh-cost -DESTDIR:= -PREFIX:=/usr/local +DESTDIR ?= +PREFIX ?= /usr/local -CFLAGS=--std=c99 -O3 -Wall -Werror -Wextra -pedantic +CC ?= cc +CFLAGS := --std=c99 -O3 -Wall -Werror -Wextra -pedantic .PHONY: clean install uninstall test @@ -12,15 +13,16 @@ ${TARGET}: ${TARGET}.c ${CC} ${CFLAGS} ${LDFLAGS} $< -o $@ clean: - rm ${TARGET} + rm -f ${TARGET} -install: +install: | ${TARGET} install -Dm755 ${TARGET} ${DESTDIR}${PREFIX}/bin/${TARGET} install -Dm644 LICENSE ${DESTDIR}${PREFIX}/share/licenses/${TARGET}/LICENSE uninstall: rm -f ${DESTDIR}${PREFIX}/bin/${TARGET} - rm -rf ${DESTDIR}${PREFIX}/share/licenses/${TARGET} + rm -f ${DESTDIR}${PREFIX}/share/licenses/${TARGET}/LICENSE + rmdir ${DESTDIR}${PREFIX}/share/licenses/${TARGET} test: @echo -n "Does input \"3.68 120 30d\" gives 317.95? "