mk

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

commit 8344d73c1544a41ec03314c22a0559e73d08671b
Author: Christos Margiolis <christos@margiolis.net>
Date:   Mon, 29 Mar 2021 23:21:14 +0300

initial commit

Diffstat:
ALICENSE | 20++++++++++++++++++++
AMakefile_ARDUINO_BSD.mk | 7+++++++
AMakefile_C_CPP_FULL.mk | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakefile_C_CPP_SIMPLE.mk | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakefile_C_CPP_STATIC_LIB.mk | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakefile_SCRIPT.mk | 47+++++++++++++++++++++++++++++++++++++++++++++++
AREADME | 3+++
Aconfig.mk | 39+++++++++++++++++++++++++++++++++++++++
8 files changed, 285 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,20 @@ +MIT License + +(c) 2020-Present Christos Margiolis <christos@christosmarg.xyz> + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile_ARDUINO_BSD.mk b/Makefile_ARDUINO_BSD.mk @@ -0,0 +1,7 @@ +ARDUINO_DIR = /usr/local/arduino +ARDMK_DIR = /usr/local/arduino-mk +ARDUINO_LIBS = /usr/local/arduino/libraries +ARDUINO_PORT = /dev/cuaU0 +ARDUINO_BOARD = uno + +include /usr/local/arduino-mk/Arduino.mk diff --git a/Makefile_C_CPP_FULL.mk b/Makefile_C_CPP_FULL.mk @@ -0,0 +1,61 @@ +# 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 @@ -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} ${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 @@ -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} ${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 @@ -0,0 +1,47 @@ +# 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/README b/README @@ -0,0 +1,3 @@ +This repo contains Makefiles I use regularly in my projects. +The <++> is a placeholder I've set up for Vim, it's not Makefile +related. Replace each <++> with the appropriate data. diff --git a/config.mk b/config.mk @@ -0,0 +1,39 @@ +# See LICENSE file for copyright and license details. +# <++> version +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 + +# includes and libs +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 +#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