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.

This commit is contained in:
Alexander Andreev 2024-05-19 05:29:13 +04:00
parent c083462a63
commit c657ed047c
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -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? "