mk

Makefile templates
git clone git://git.christosmarg.xyz
Log | Files | Refs | README | LICENSE

commit 1737f37646b85331c0591f8d6c0b0298c1eb8ec6
parent 8344d73c1544a41ec03314c22a0559e73d08671b
Author: Christos Margiolis <christos@margiolis.net>
Date:   Mon, 24 May 2021 20:30:32 +0300

better

Diffstat:
DMakefile_C_CPP_FULL.mk | 61-------------------------------------------------------------
DMakefile_C_CPP_SIMPLE.mk | 53-----------------------------------------------------
DMakefile_C_CPP_STATIC_LIB.mk | 55-------------------------------------------------------
DMakefile_SCRIPT.mk | 47-----------------------------------------------
RMakefile_ARDUINO_BSD.mk -> arduino_fbsd.mk | 0
Ac.mk | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Ac_lib.mk | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mconfig.mk | 30+++++++++---------------------
Ash.mk | 37+++++++++++++++++++++++++++++++++++++
9 files changed, 154 insertions(+), 237 deletions(-)

diff --git a/Makefile_C_CPP_FULL.mk b/Makefile_C_CPP_FULL.mk @@ -1,61 +0,0 @@ -# See LICENSE file for copyright and license details. -# <++> -.POSIX: - -include config.mk - -BIN = <++> -DIST = ${BIN}-${VERSION} -MAN1 = ${BIN}.1 - -SRC_DIR = <++> -OBJ_DIR = <++> -BIN_DIR = <++> - -SRC = <++> -OBJ = ${SRC:${SRC_DIR}.<++>=${OBJ_DIR}.o} - -all: options ${BIN} - -options: - @echo ${BIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -${BIN}: ${OBJ} - ${MKDIR} ${BIN_DIR} - ${CC} ${LDFLAGS} ${OBJ} -o $@ - ${MV} ${BIN} ${BIN_DIR} - -.<++>.o: - ${MKDIR} ${OBJ_DIR} - ${CC} -c ${CFLAGS} $< - -dist: clean - ${MKDIR} ${DIST} - ${CP} -R <++> ${DIST} - ${TAR} ${DIST}.tar ${DIST} - ${GZIP} ${DIST}.tar - ${RM_DIR} ${DIST} - -run: - ./${BIN_DIR}/${BIN} - -install: all - ${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR} - ${CP} ${BIN_DIR}/${BIN} ${BIN_DIR} - ${CP} ${MAN1} ${DESTDIR}${MAN_DIR} - sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1} - chmod 755 ${DESTDIR}${BIN_DIR}/${BIN} - chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} - -uninstall: - ${RM} ${DESTDIR}${BIN_DIR}/${BIN} - ${RM} ${DESTDIR}${MAN_DIR}/${MAN1} - -clean: - ${RM_DIR} ${BIN_DIR} ${OBJ_DIR} - ${RM} ${DIST}.tar.gz - -.PHONY: all options clean dist install uninstall run diff --git a/Makefile_C_CPP_SIMPLE.mk b/Makefile_C_CPP_SIMPLE.mk @@ -1,53 +0,0 @@ -# See LICENSE file for copyright and license details. -# <++> -.POSIX: - -include config.mk - -BIN = <++> -DIST = ${BIN}-${VERSION} -MAN1 = ${BIN}.1 - -SRC = <++> -OBJ = ${SRC:.<++>=.o} - -all: options ${BIN} - -options: - @echo ${BIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -${BIN}: ${OBJ} - ${CC} ${LDFLAGS} ${OBJ} -o $@ - -.<++>.o: - ${CC} -c ${CFLAGS} $< - -dist: clean - ${MKDIR} ${DIST} - ${CP} -R <++> ${DIST} - ${TAR} ${DIST}.tar ${DIST} - ${GZIP} ${DIST}.tar - ${RM_DIR} ${DIST} - -run: - ./${BIN} - -install: all - ${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR} - ${CP} ${BIN} ${BIN_DIR} - ${CP} ${MAN1} ${DESTDIR}${MAN_DIR} - sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1} - chmod 755 ${DESTDIR}${BIN_DIR}/${BIN} - chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} - -uninstall: - ${RM} ${DESTDIR}${BIN_DIR}/${BIN} - ${RM} ${DESTDIR}${MAN_DIR}/${MAN1} - -clean: - ${RM} ${BIN} ${OBJ} ${DIST}.tar.gz - -.PHONY: all options clean dist install uninstall run diff --git a/Makefile_C_CPP_STATIC_LIB.mk b/Makefile_C_CPP_STATIC_LIB.mk @@ -1,55 +0,0 @@ -# See LICENSE file for copyright and license details. -# <++> -.POSIX: - -include config.mk - -LIB = <++> -DIST = ${LIB}-${VERSION} -MAN3 = ${LIB}.3 - -SRC = <++> -OBJ = ${SRC:.<++>=.o} - -all: options ${LIB} - -options: - @echo ${LIB} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "ARFLAGS = ${ARFLAGS}" - @echo "CC = ${CC}" - @echo "AR = ${AR}" - -${LIB}: ${OBJ} - ${AR} ${ARFLAGS} lib${LIB}.a ${OBJ} - -.<++>.o: - ${CC} -c ${CFLAGS} $< - -dist: clean - ${MKDIR} ${DIST} - ${CP} -R <++> ${DIST} - ${TAR} ${DIST}.tar ${DIST} - ${GZIP} ${DIST}.tar - ${RM_DIR} ${DIST} - -install: all - ${MKDIR} ${DESTDIR}${LIB_DIR} ${DESTDIR}${INC_DIR} ${DESTDIR}${MAN_DIR} - ${CP} ${LIB}.h ${DESTDIR}${INC_DIR} - ${CP} lib${LIB}.a ${DESTDIR}${LIB_DIR} - ${CP} ${MAN3} ${DESTDIR}${MAN_DIR} - sed "s/VERSION/${VERSION}/g" < ${MAN3} > ${DESTDIR}${MAN_DIR}/${MAN3} - chmod 755 ${DESTDIR}${INC_DIR}/${LIB}.h - chmod 644 ${DESTDIR}${LIB_DIR}/lib${LIB}.a - chmod 644 ${DESTDIR}${MAN_DIR}/${MAN3} - -uninstall: - ${RM} ${DESTDIR}${INC_DIR}/${LIB}.h - ${RM} ${DESTDIR}${LIB_DIR}/lib${LIB}.a - ${RM} ${DESTDIR}${MAN_DIR}/${MAN3} - -clean: - ${RM} ${LIB} ${OBJ} lib${LIB}.a ${DIST}.tar.gz - -.PHONY: all options clean dist install uninstall diff --git a/Makefile_SCRIPT.mk b/Makefile_SCRIPT.mk @@ -1,47 +0,0 @@ -# See LICENSE file for copyright and license details. -# <++> -.POSIX: - -# maybe move to config.mk - -BIN = <++> -VERSION = <++> -DIST = ${BIN}-${VERSION} -MAN1 = ${BIN}.1 -PREFIX = /usr/local -MAN_DIR = ${PREFIX}/share/man/man1 -BIN_DIR = ${PREFIX}/bin - -CP = cp -f -RM = rm -f -RM_DIR = rm -rf -MKDIR = mkdir -p -TAR = tar -cf -GZIP = gzip - -all: ${BIN} - chmod +x ${BIN} - -dist: - ${MKDIR} ${DIST} - ${CP} -R <++> ${DIST} - ${TAR} ${DIST}.tar ${DIST} - ${GZIP} ${DIST}.tar - ${RM_DIR} ${DIST} - -install: all - ${MKDIR} ${DESTDIR}${BIN_DIR} ${DESTDIR}${MAN_DIR} - ${CP} ${BIN} ${DESTDIR}${BIN_DIR} - ${CP} ${MAN1} ${DESTDIR}${MAN_DIR} - sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MAN_DIR}/${MAN1} - chmod 755 ${DESTDIR}${BIN_DIR}/${BIN} - chmod 644 ${DESTDIR}${MAN_DIR}/${MAN1} - -uninstall: - ${RM} ${DESTDIR}${BIN_DIR}/${BIN} - ${RM} ${DESTDIR}${MAN_DIR}/${MAN1} - -clean: - ${RM} ${DIST}.tar.gz - -.PHONY: all clean dist install uninstall diff --git a/Makefile_ARDUINO_BSD.mk b/arduino_fbsd.mk diff --git a/c.mk b/c.mk @@ -0,0 +1,53 @@ +# See LICENSE file for copyright and license details. +# <++> +.POSIX: + +include config.mk + +BIN = <++> +DIST = ${BIN}-${VERSION} +MAN1 = ${BIN}.1 + +SRC = <++> +OBJ = ${SRC:.<++>=.o} + +all: options ${BIN} + +options: + @echo ${BIN} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + +${BIN}: ${OBJ} + ${CC} ${LDFLAGS} ${OBJ} -o $@ + +.<++>.o: + ${CC} -c ${CFLAGS} $< + +dist: clean + mkdir -p ${DIST} + cp -R <++> ${DIST} + tar -cf ${DIST}.tar ${DIST} + gzip ${DIST}.tar + rm -rf ${DIST} + +run: + ./${BIN} + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANPREFIX}/man1 + cp -f ${BIN} ${DESTDIR}${PREFIX}/bin + cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1 + sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MANPREFIX}/man1/${MAN1} + chmod 755 ${DESTDIR}${PREFIX}/bin/${BIN} + chmod 644 ${DESTDIR}${MANPREFIX}/man1/${MAN1} + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/${BIN} \ + ${DESTDIR}${MANPREFIX}/man1/${MAN1} + +clean: + rm -f ${BIN} ${OBJ} ${DIST}.tar.gz *.core + +.PHONY: all options clean dist install uninstall run diff --git a/c_lib.mk b/c_lib.mk @@ -0,0 +1,55 @@ +# See LICENSE file for copyright and license details. +# <++> +.POSIX: + +include config.mk + +LIB = <++> +DIST = ${LIB}-${VERSION} +MAN3 = ${LIB}.3 + +SRC = <++> +OBJ = ${SRC:.<++>=.o} + +all: options ${LIB} + +options: + @echo ${LIB} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "ARFLAGS = ${ARFLAGS}" + @echo "CC = ${CC}" + @echo "AR = ${AR}" + +${LIB}: ${OBJ} + ${AR} ${ARFLAGS} lib${LIB}.a ${OBJ} + +.<++>.o: + ${CC} -c ${CFLAGS} $< + +dist: clean + mkdir -p ${DIST} + cp -R <++> ${DIST} + tar -cf ${DIST}.tar ${DIST} + gzip ${DIST}.tar + rm -rf ${DIST} + +install: all + mkdir -p ${DESTDIR}${LIBDIR} ${DESTDIR}${INCDIR} ${DESTDIR}${MANPREFIX}/man3 + cp -f ${LIB}.h ${DESTDIR}${INCDIR} + cp -f lib${LIB}.a ${DESTDIR}${LIBDIR} + cp -f ${MAN3} ${DESTDIR}${MANPREFIX}/man3 + sed "s/VERSION/${VERSION}/g" < ${MAN3} > ${DESTDIR}${MANPREFIX}/man3/${MAN3} + chmod 755 ${DESTDIR}${INC_DIR}/${LIB}.h + chmod 644 ${DESTDIR}${LIB_DIR}/lib${LIB}.a + chmod 644 ${DESTDIR}${MANPREFIX}/man3/${MAN3} + +uninstall: + rm -f ${DESTDIR}${INCDIR}/${LIB}.h \ + ${DESTDIR}${LIBDIR}/lib${LIB}.a \ + ${DESTDIR}${MANPREFIX}/man3/${MAN3} + +clean: + rm -f ${LIB} ${OBJ} lib${LIB}.a ${DIST}.tar.gz *.core + +.PHONY: all options clean dist install uninstall diff --git a/config.mk b/config.mk @@ -4,36 +4,24 @@ VERSION = <++> # paths PREFIX = /usr/local -MAN_DIR = ${PREFIX}/share/man/man1 -BIN_DIR = ${PREFIX}/bin -# uncomment if you're making a library -#MAN_DIR = ${PREFIX}/share/man/man3 -#INC_DIR = ${PREFIX}/include -#LIB_DIR = ${PREFIX}/lib +MANPREFIX = ${PREFIX}/share/man +# uncomment if you're building a library +#INCDIR = ${PREFIX}/include +#LIBDIR = ${PREFIX}/lib # includes and libs -INCS = -Iinclude -LIBS = -Llib <++> +INCS = -Iinclude +LIBS = -Llib # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L \ -D_XOPEN_SOURCE=700 -DVERSION=\"${VERSION}\" CFLAGS = -std=<++> -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} -# uncomment if you're making a library +# uncomment if you're building a library #ARFLAGS = rs -# utils -CP = cp -f -RM = rm -f -RM_DIR = rm -rf -MV = mv -MKDIR = mkdir -p -RM_DIR = rm -rf -TAR = tar -cf -GZIP = gzip - # compiler CC = <++> -# uncomment if you're making a library -#AR = ar +# uncomment if you're building a library +#AR = <++> diff --git a/sh.mk b/sh.mk @@ -0,0 +1,37 @@ +# See LICENSE file for copyright and license details. +# <++> +.POSIX: + +SH = <++> +VERSION = <++> +DIST = ${SH}-${VERSION} +MAN1 = ${SH}.1 +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +all: ${SH} + chmod +x ${SH} + +dist: + mkdir -p ${DIST} + cp -R <++> ${DIST} + tar -cf ${DIST}.tar ${DIST} + gzip ${DIST}.tar + rm -rf ${DIST} + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANPREFIX}/man1 + cp -f ${SH} ${DESTDIR}${PREFIX}/bin + cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1 + sed "s/VERSION/${VERSION}/g" < ${MAN1} > ${DESTDIR}${MANPREFIX}/man1/${MAN1} + chmod 755 ${DESTDIR}${PREFIX}/bin/${SH} + chmod 644 ${DESTDIR}${MANPREFIX}/man1/${MAN1} + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/${SH} \ + ${DESTDIR}${MANPREFIX}/man1/${MAN1} + +clean: + rm -f ${DIST}.tar.gz + +.PHONY: all clean dist install uninstall