ii

git clone https://orangeshoelaces.net/git/ii.git

e32415744c0e7f2d75d4669addefc1b50f977cd6

Author: Quentin Rameau on 05/29/2018

Committer: Hiltjo Posthuma on 06/02/2018

Refactor Makefile

Declare it as POSIX-compliant
Use $() instead of ${}
Separate stock CFLAGS from user CFLAGS

Stats

Makefile  | 53 ++++----
config.mk | 24 +---
2 files changed, 31 insertions(+), 46 deletions(-)

Patch

diff --git a/Makefile b/Makefile
index 8e0d89d..3f9669f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,50 +1,49 @@
 # See LICENSE file for copyright and license details.
+.POSIX:
+
 include config.mk
 
 SRC = ii.c strlcpy.c
-OBJ = ${SRC:.c=.o}
+OBJ = $(SRC:.c=.o)
+
+IICFLAGS = -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE $(CFLAGS)
 
 all: ii
 
 options:
 	@echo ii build options:
-	@echo "CFLAGS   = ${CFLAGS}"
-	@echo "LDFLAGS  = ${LDFLAGS}"
-	@echo "CC       = ${CC}"
-
-.o:
-	$(LD) -o $@ $< $(LDFLAGS)
+	@echo "CFLAGS   = $(IICFLAGS)"
+	@echo "LDFLAGS  = $(LDFLAGS)"
+	@echo "CC       = $(CC)"
 
 .c.o:
-	$(CC) -c -o $@ $< $(CFLAGS)
+	$(CC) $(IICFLAGS) -c $<
 
-ii: ${OBJ}
-	${CC} -o $@ ${OBJ} ${LDFLAGS}
+ii: $(OBJ)
+	$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
 
-${OBJ}: arg.h
+$(OBJ): arg.h
 
 install: all
-	mkdir -p ${DESTDIR}${DOCDIR}
-	mkdir -p ${DESTDIR}${BINDIR}
-	mkdir -p ${DESTDIR}${MAN1DIR}
-	install -d ${DESTDIR}${BINDIR} ${DESTDIR}${MAN1DIR}
-	install -m 644 CHANGES README FAQ LICENSE ${DESTDIR}${DOCDIR}
-	install -m 775 ii ${DESTDIR}${BINDIR}
-	sed "s/VERSION/${VERSION}/g" < ii.1 > ${DESTDIR}${MAN1DIR}/ii.1
-	chmod 644 ${DESTDIR}${MAN1DIR}/ii.1
+	mkdir -p $(DESTDIR)$(PREFIX)/bin
+	mkdir -p $(DESTDIR)$(MANPREFIX)/man1
+	mkdir -p $(DESTDIR)$(DOCPREFIX)/ii
+	install -m 644 CHANGES README FAQ LICENSE $(DESTDIR)$(DOCPREFIX)/ii
+	install -m 775 ii $(DESTDIR)$(PREFIX)/bin
+	sed "s/VERSION/$(VERSION)/g" < ii.1 > $(DESTDIR)$(MANPREFIX)/man1/ii.1
+	chmod 644 $(DESTDIR)$(MANPREFIX)/man1/ii.1
 
 uninstall: all
-	rm -f ${DESTDIR}${MAN1DIR}/ii.1 \
-		${DESTDIR}${BINDIR}/ii
-	rm -rf ${DESTDIR}${DOCDIR}
+	rm -f $(DESTDIR)$(MANPREFIX)/man1/ii.1 $(DESTDIR)$(PREFIX)/bin/ii
+	rm -rf $(DESTDIR)$(DOCPREFIX)/ii
 
 dist: clean
-	mkdir -p ii-${VERSION}
+	mkdir -p ii-$(VERSION)
 	cp -R Makefile CHANGES README FAQ LICENSE strlcpy.c arg.h \
-		config.mk ii.c ii.1 ii-${VERSION}
-	tar -cf ii-${VERSION}.tar ii-${VERSION}
-	gzip ii-${VERSION}.tar
-	rm -rf ii-${VERSION}
+		config.mk ii.c ii.1 ii-$(VERSION)
+	tar -cf ii-$(VERSION).tar ii-$(VERSION)
+	gzip ii-$(VERSION).tar
+	rm -rf ii-$(VERSION)
 
 clean:
 	rm -f ii *.o
diff --git a/config.mk b/config.mk
index d8a2841..3b629db 100644
--- a/config.mk
+++ b/config.mk
@@ -2,24 +2,10 @@
 VERSION = 1.8
 
 # paths
-PREFIX   = /usr/local
-BINDIR   = ${PREFIX}/bin
-MANDIR   = ${PREFIX}/share/man
-MAN1DIR  = ${MANDIR}/man1
-DOCDIR   = ${PREFIX}/share/doc/ii
+PREFIX    = /usr/local
+MANPREFIX = ${PREFIX}/share/man
+DOCPREFIX = ${PREFIX}/share/doc
 
-# includes and libs
-INCLUDES = -I. -I/usr/include
+CFLAGS   = -Os
+LDFLAGS  = -s
 LIBS     =
-
-# compiler
-CC       = cc
-
-# debug
-#CFLAGS  = -g -O0 -pedantic -Wall ${INCLUDES} -DVERSION=\"${VERSION}\" \
-#	-std=c99 -D_DEFAULT_SOURCE
-#LDFLAGS = ${LIBS}
-
-# release
-CFLAGS   = -Os ${INCLUDES} -DVERSION=\"${VERSION}\" -std=c99 -D_DEFAULT_SOURCE
-LDFLAGS  = -s ${LIBS}