Makefile improvements

- Respect system/port flags by default.
- Be verbose and do not hide output. This makes it easier to debug a build.
- Remove the "options" target.
- Remove config.mk: just edit the Makefile or override flags if needed.
- dist: no need to clean before packaging files.
- dist: pipe directly to gzip without an intermediate tarball file.
- Define and add a POSIX marker to the Makefile.
This commit is contained in:
Hiltjo Posthuma 2021-05-06 01:39:46 +02:00
parent 81533f966e
commit f2c5daa9fe
3 changed files with 46 additions and 64 deletions

View File

@ -1,58 +1,59 @@
# sic - simple irc client .POSIX:
include config.mk NAME = sic
VERSION = 1.3
SRC = sic.c # paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
# use system flags.
SIC_CFLAGS = ${CFLAGS}
SIC_LDFLAGS = ${LDFLAGS}
SIC_CPPFLAGS = ${LDFLAGS} -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
BIN = sic
SRC = ${BIN:=.c}
OBJ = ${SRC:.c=.o} OBJ = ${SRC:.c=.o}
MAN1 = ${BIN:=.1}
all: options sic all: ${BIN}
options: ${BIN}: ${@:=.o}
@echo sic build options:
@echo "CFLAGS = ${CFLAGS}" ${OBJ}: config.h strlcpy.c util.c
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}" .o:
${CC} -o $@ $< ${SIC_LDFLAGS}
.c.o: .c.o:
@echo CC $< ${CC} -c ${SIC_CFLAGS} ${SIC_CPPFLAGS} -o $@ -c $<
@${CC} -c ${CFLAGS} $<
${OBJ}: config.h config.mk strlcpy.c util.c
config.h: config.h:
@echo creating $@ from config.def.h cp config.def.h $@
@cp config.def.h $@
sic: ${OBJ}
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
clean: clean:
@echo cleaning rm -f ${BIN} ${OBJ} "${NAME}-${VERSION}.tar.gz"
@rm -f sic ${OBJ} sic-${VERSION}.tar.gz
dist: clean dist:
@echo creating dist tarball mkdir -p "${NAME}-${VERSION}"
@mkdir -p sic-${VERSION} cp -fR LICENSE Makefile README arg.h config.def.h \
@cp -R LICENSE Makefile README arg.h config.def.h config.mk sic.1 sic.c util.c strlcpy.c sic-${VERSION} ${MAN1} ${SRC} util.c strlcpy.c "${NAME}-${VERSION}"
@tar -cf sic-${VERSION}.tar sic-${VERSION} tar -cf - "${NAME}-${VERSION}" | \
@gzip sic-${VERSION}.tar gzip -c > "${NAME}-${VERSION}.tar.gz"
@rm -rf sic-${VERSION} rm -rf "${NAME}-${VERSION}"
install: all install: all
@echo installing executable file to ${DESTDIR}${PREFIX}/bin mkdir -p ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin cp -f ${BIN} "${DESTDIR}${PREFIX}/bin"
@cp -f sic ${DESTDIR}${PREFIX}/bin chmod 755 "${DESTDIR}${PREFIX}/bin/${BIN}"
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic mkdir -p "${DESTDIR}${MANPREFIX}/man1"
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < ${MAN1} > "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
@mkdir -p ${DESTDIR}${MANPREFIX}/man1 chmod 644 "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
@sed "s/VERSION/${VERSION}/g" < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
uninstall: uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin rm -f \
@rm -f ${DESTDIR}${PREFIX}/bin/sic "${DESTDIR}${PREFIX}/bin/${BIN}"\
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
@rm -f ${DESTDIR}${MANPREFIX}/man1/sic.1
.PHONY: all options clean dist install uninstall .PHONY: all clean dist install uninstall

7
README
View File

@ -8,13 +8,14 @@ different channel buffers, that's actually a feature.
Installation Installation
------------ ------------
Edit config.mk to match your local setup. sic is installed into Edit the Makefile or override the flags to match your local setup. sic is
/usr/local by default. installed into /usr/local by default.
Afterwards enter the following command to build and install sic Afterwards enter the following command to build and install sic
(if necessary as root): (if necessary as root):
$ make clean install $ make
# make install
Running sic Running sic

View File

@ -1,20 +0,0 @@
# sic version
VERSION = 1.3
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
# includes and libs
INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
# compiler and linker
CC = cc