Refactor Makefile

Declare it as POSIX-compliant
Use $() instead of ${}
Separate stock CFLAGS from user CFLAGS
This commit is contained in:
Quentin Rameau 2018-05-29 18:27:36 +02:00 committed by Hiltjo Posthuma
parent 25ee995ead
commit e32415744c
2 changed files with 31 additions and 46 deletions

View File

@ -1,50 +1,49 @@
# See LICENSE file for copyright and license details. # See LICENSE file for copyright and license details.
.POSIX:
include config.mk include config.mk
SRC = ii.c strlcpy.c SRC = ii.c strlcpy.c
OBJ = ${SRC:.c=.o} OBJ = $(SRC:.c=.o)
IICFLAGS = -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE $(CFLAGS)
all: ii all: ii
options: options:
@echo ii build options: @echo ii build options:
@echo "CFLAGS = ${CFLAGS}" @echo "CFLAGS = $(IICFLAGS)"
@echo "LDFLAGS = ${LDFLAGS}" @echo "LDFLAGS = $(LDFLAGS)"
@echo "CC = ${CC}" @echo "CC = $(CC)"
.o:
$(LD) -o $@ $< $(LDFLAGS)
.c.o: .c.o:
$(CC) -c -o $@ $< $(CFLAGS) $(CC) $(IICFLAGS) -c $<
ii: ${OBJ} ii: $(OBJ)
${CC} -o $@ ${OBJ} ${LDFLAGS} $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
${OBJ}: arg.h $(OBJ): arg.h
install: all install: all
mkdir -p ${DESTDIR}${DOCDIR} mkdir -p $(DESTDIR)$(PREFIX)/bin
mkdir -p ${DESTDIR}${BINDIR} mkdir -p $(DESTDIR)$(MANPREFIX)/man1
mkdir -p ${DESTDIR}${MAN1DIR} mkdir -p $(DESTDIR)$(DOCPREFIX)/ii
install -d ${DESTDIR}${BINDIR} ${DESTDIR}${MAN1DIR} install -m 644 CHANGES README FAQ LICENSE $(DESTDIR)$(DOCPREFIX)/ii
install -m 644 CHANGES README FAQ LICENSE ${DESTDIR}${DOCDIR} install -m 775 ii $(DESTDIR)$(PREFIX)/bin
install -m 775 ii ${DESTDIR}${BINDIR} sed "s/VERSION/$(VERSION)/g" < ii.1 > $(DESTDIR)$(MANPREFIX)/man1/ii.1
sed "s/VERSION/${VERSION}/g" < ii.1 > ${DESTDIR}${MAN1DIR}/ii.1 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/ii.1
chmod 644 ${DESTDIR}${MAN1DIR}/ii.1
uninstall: all uninstall: all
rm -f ${DESTDIR}${MAN1DIR}/ii.1 \ rm -f $(DESTDIR)$(MANPREFIX)/man1/ii.1 $(DESTDIR)$(PREFIX)/bin/ii
${DESTDIR}${BINDIR}/ii rm -rf $(DESTDIR)$(DOCPREFIX)/ii
rm -rf ${DESTDIR}${DOCDIR}
dist: clean dist: clean
mkdir -p ii-${VERSION} mkdir -p ii-$(VERSION)
cp -R Makefile CHANGES README FAQ LICENSE strlcpy.c arg.h \ cp -R Makefile CHANGES README FAQ LICENSE strlcpy.c arg.h \
config.mk ii.c ii.1 ii-${VERSION} config.mk ii.c ii.1 ii-$(VERSION)
tar -cf ii-${VERSION}.tar ii-${VERSION} tar -cf ii-$(VERSION).tar ii-$(VERSION)
gzip ii-${VERSION}.tar gzip ii-$(VERSION).tar
rm -rf ii-${VERSION} rm -rf ii-$(VERSION)
clean: clean:
rm -f ii *.o rm -f ii *.o

View File

@ -3,23 +3,9 @@ VERSION = 1.8
# paths # paths
PREFIX = /usr/local PREFIX = /usr/local
BINDIR = ${PREFIX}/bin MANPREFIX = ${PREFIX}/share/man
MANDIR = ${PREFIX}/share/man DOCPREFIX = ${PREFIX}/share/doc
MAN1DIR = ${MANDIR}/man1
DOCDIR = ${PREFIX}/share/doc/ii
# includes and libs CFLAGS = -Os
INCLUDES = -I. -I/usr/include LDFLAGS = -s
LIBS = 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}