commit b3741d9b801de57de4bff7e91bf2f88064b8b411 parent bfe40b1849339039727903c1037db44c59580e6e Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Fri, 22 Nov 2019 16:57:58 +0100 improve Makefile - add make dist rule. - add README to install rule. - remove config.mk - cleanup Diffstat:
M | Makefile | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
D | config.mk | | | 25 | ------------------------- |
2 files changed, 61 insertions(+), 54 deletions(-)
diff --git a/Makefile b/Makefile @@ -1,48 +1,80 @@ -include config.mk +.POSIX: -SRC = sob.c +NAME = sob +VERSION = 0.2 + +# paths +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/man +DOCPREFIX = ${PREFIX}/share/doc/${NAME} + +SOB_CFLAGS = ${CFLAGS} +SOB_LDFLAGS = ${LDFLAGS} +SOB_CPPFLAGS = -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=200809L\ + -D_BSD_SOURCE -D_XOPEN_SOURCE=700 + +BIN = ${NAME} + +SRC = ${NAME}.c HDR = arg.h config.def.h + OBJ = ${SRC:.c=.o} -all: options sob +MAN1 = ${NAME}.1 +DOC = \ + LICENSE\ + README -options: - @echo sob build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" +all: sob .c.o: - @echo CC $< - @${CC} -c ${CFLAGS} $< + ${CC} -c ${SOB_CFLAGS} $< -${OBJ}: config.mk config.h +${OBJ}: config.h config.h: - @echo creating $@ from config.def.h - @cp config.def.h $@ + cp config.def.h $@ sob: ${OBJ} - @echo CC -o $@ - @${CC} -o $@ ${OBJ} ${LDFLAGS} + ${CC} -o $@ ${OBJ} ${SOB_LDFLAGS} + +dist: + rm -rf "${NAME}-${VERSION}" + mkdir -p "${NAME}-${VERSION}" + cp -f ${MAN1} ${DOC} ${HDR} \ + ${SRC} \ + Makefile \ + "${NAME}-${VERSION}" + # make tarball + tar -cf - "${NAME}-${VERSION}" | \ + gzip -c > "${NAME}-${VERSION}.tar.gz" + rm -rf "${NAME}-${VERSION}" clean: - @echo cleaning - @rm -f sob ${OBJ} + rm -f ${BIN} ${OBJ} install: all - @echo installing executable file to ${DESTDIR}${PREFIX}/bin - @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f sob ${DESTDIR}${PREFIX}/bin - @chmod 755 ${DESTDIR}${PREFIX}/bin/sob - @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 - @mkdir -p ${DESTDIR}${MANPREFIX}/man1 - @sed "s/VERSION/${VERSION}/g" < sob.1 > ${DESTDIR}${MANPREFIX}/man1/sob.1 + # installing executable files. + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f ${BIN} "${DESTDIR}${PREFIX}/bin" + for f in ${BIN}; do chmod 755 "${DESTDIR}${PREFIX}/bin/$$f"; done + # installing example files. + mkdir -p "${DESTDIR}${DOCPREFIX}" + cp -f README \ + "${DESTDIR}${DOCPREFIX}" + # installing manual pages. + mkdir -p ${DESTDIR}${MANPREFIX}/man1 + cp -f ${MAN1} "${DESTDIR}${MANPREFIX}/man1" + for m in ${MAN1}; do chmod 644 "${DESTDIR}${MANPREFIX}/man1/$$m"; done uninstall: - @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/sob - @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 - @rm -f ${DESTDIR}${MANPREFIX}/man1/sob.1 + # removing executable files. + for f in ${BIN}; do rm -f "${DESTDIR}${PREFIX}/bin/$$f"; done + # removing example files. + rm -f \ + "${DESTDIR}${DOCPREFIX}/README" + -rmdir "${DESTDIR}${DOCPREFIX}" + # removing manual pages. + for m in ${MAN1}; do rm -f "${DESTDIR}${MANPREFIX}/man1/$$m"; done -.PHONY: all options clean dist install uninstall +.PHONY: all clean dist install uninstall diff --git a/config.mk b/config.mk @@ -1,25 +0,0 @@ -VERSION = 0.2 - -# 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_POSIX_C_SOURCE=200809 -D_BSD_SOURCE -D_XOPEN_SOURCE=700 - -# debug -#CFLAGS = -g -std=c99 -pedantic -Wall -Wextra -O0 ${INCS} ${CPPFLAGS} -#LDFLAGS = ${LIBS} - -# release -CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os ${INCS} ${CPPFLAGS} -LDFLAGS = -s ${LIBS} - -# compiler and linker -CC = cc