2016-10-14 14:03:30 +02:00
|
|
|
;; Makefile
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
(add-hook-and-eval
|
2017-05-08 12:02:07 +02:00
|
|
|
'makefile-mode-hook
|
2014-08-28 13:24:08 +02:00
|
|
|
(lambda ()
|
|
|
|
(local-set-key (kbd "C-c c") 'makefile-config)
|
|
|
|
(local-set-key (kbd "C-c d") 'makefile-doc)
|
|
|
|
(local-set-key (kbd "C-c m") 'makefile-main)
|
2014-11-18 10:56:51 +01:00
|
|
|
(local-set-key (kbd "C-c s") 'makefile-c)))
|
2014-03-20 13:53:57 +01:00
|
|
|
|
|
|
|
(define-skeleton makefile-main
|
2014-08-28 13:24:08 +02:00
|
|
|
"Insert root Makefile." nil
|
2014-11-18 10:56:51 +01:00
|
|
|
"ROOT = .
|
|
|
|
include ${ROOT}/config.mk
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-08-28 13:24:08 +02:00
|
|
|
################################################################################
|
|
|
|
## Build.
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: app doc
|
|
|
|
|
|
|
|
.PHONY: app
|
|
|
|
app:
|
|
|
|
${MAKE} -C ${srcdir}
|
|
|
|
|
|
|
|
.PHONY: doc
|
|
|
|
doc:
|
2014-11-18 10:56:51 +01:00
|
|
|
${MAKE} -C ${docsrcdir}
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
.PHONY: debug
|
|
|
|
debug:
|
|
|
|
CFLAGS+=\"-g3 -O0 -DDEBUG=9\" ${MAKE}
|
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
${MAKE} -C ${testdir}
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-08-28 13:24:08 +02:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
${MAKE} -C ${srcdir} clean
|
2014-11-18 10:56:51 +01:00
|
|
|
${MAKE} -C ${docsrcdir} clean
|
2014-08-28 13:24:08 +02:00
|
|
|
${MAKE} -C ${testdir} clean
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
## Install / Uninstall.
|
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
INSTALL ?= install
|
2014-08-28 13:24:08 +02:00
|
|
|
INSTALL_DATA ?= ${INSTALL} -m644
|
2014-11-18 10:56:51 +01:00
|
|
|
INSTALL_DIR ?= ${INSTALL} -d
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
prefix ?= /usr/local
|
|
|
|
exec_prefix ?= ${prefix}
|
|
|
|
datarootdir ?= ${prefix}/share
|
2014-11-18 10:56:51 +01:00
|
|
|
|
|
|
|
bindir ?= ${exec_prefix}/bin
|
2014-08-28 13:24:08 +02:00
|
|
|
datadir ?= ${datarootdir}
|
2014-11-18 10:56:51 +01:00
|
|
|
docdir ?= ${datarootdir}/doc
|
2014-08-28 13:24:08 +02:00
|
|
|
includedir ?= ${prefix}/include
|
|
|
|
infodir ?= ${datarootdir}/info
|
|
|
|
libdir ?= ${exec_prefix}/lib
|
2014-11-18 10:56:51 +01:00
|
|
|
libexecdir ?= ${exec_prefix}/libexecdir
|
|
|
|
licensedir ?= ${datarootdir}/licenses
|
2014-08-28 13:24:08 +02:00
|
|
|
localedir ?= ${datarootdir}/locale
|
2014-11-18 10:56:51 +01:00
|
|
|
localstatedir ?= ${prefix}/var
|
2014-08-28 13:24:08 +02:00
|
|
|
mandir ?= ${datarootdir}/man
|
2014-11-18 10:56:51 +01:00
|
|
|
runstatedir ?= ${prefix}/run
|
|
|
|
sbindir ?= ${exec_prefix}/sbin
|
|
|
|
sharedstatedir ?= ${prefix}/com
|
|
|
|
sysconfdir ?= ${perfix}/etc
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
.PHONY: install
|
2014-11-18 10:56:51 +01:00
|
|
|
install:
|
|
|
|
${MAKE}
|
|
|
|
${INSTALL_DIR} ${DESTDIR}${bindir}
|
|
|
|
${INSTALL} ${srcdir}/${cmdname} ${DESTDIR}${bindir}/${cmdname}
|
|
|
|
${INSTALL_DIR} ${DESTDIR}${mandir}/man1
|
|
|
|
${INSTALL_DATA} ${docsrcdir}/${cmdname}.1 ${DESTDIR}${mandir}/man1/${cmdname}.1
|
|
|
|
${INSTALL_DIR} ${DESTDIR}${licensedir}/${cmdname}
|
|
|
|
${INSTALL_DATA} LICENSE ${DESTDIR}${licensedir}/${cmdname}/LICENSE
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
.PHONY: uninstall
|
|
|
|
uninstall:
|
2014-11-18 10:56:51 +01:00
|
|
|
-rm -f ${DESTDIR}${bindir}/${cmdname}
|
|
|
|
-rmdir -p ${DESTDIR}${bindir}
|
|
|
|
-rm -f ${DESTDIR}${mandir}/${cmdname}.${mansection}.gz
|
|
|
|
-rmdir -p ${DESTDIR}${mandir}
|
2014-11-23 17:24:22 +01:00
|
|
|
-rm -f ${DESTDIR}${licensedir}/${cmdname}/LICENSE
|
|
|
|
-rmdir -p ${DESTDIR}${licensedir}/${cmdname}
|
2014-08-28 13:24:08 +02:00
|
|
|
" > \n)
|
|
|
|
|
|
|
|
(define-skeleton makefile-doc
|
|
|
|
"Insert documentation Makefile." nil
|
2014-11-18 10:56:51 +01:00
|
|
|
".SUFFIXES: .in
|
|
|
|
|
|
|
|
ROOT ?= ..
|
2014-08-28 13:24:08 +02:00
|
|
|
include ${ROOT}/config.mk
|
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
manpages = ${cmdname}.1
|
|
|
|
|
|
|
|
all: ${manpages}
|
|
|
|
|
|
|
|
.in:
|
|
|
|
awk -v date=`date '+%Y-%m-%d'` 'BEGIN {section=\"$@\"; sub (/.*\\./, \"\", section); manname=toupper(\"$@\"); sub(/\\.[^.]+$$/, \"\", manname); print \".ds appname ${appname}\\n.ds authors ${authors}\\n.ds cmdname ${cmdname}\\n.ds date \" date \"\\n.ds manname \" manname \"\\n.ds section \" section \"\\n.ds version ${version}\\n.ds year ${year}\\n.\"}' > $@
|
|
|
|
cat $< >> $@
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
clean:
|
2014-11-18 10:56:51 +01:00
|
|
|
rm -f ${manpages}
|
2014-08-28 13:24:08 +02:00
|
|
|
" > \n)
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-08-28 13:24:08 +02:00
|
|
|
(define-skeleton makefile-c
|
|
|
|
"Insert Makefile for building c." nil
|
2014-11-18 10:56:51 +01:00
|
|
|
"ROOT ?= ..
|
2014-08-28 13:24:08 +02:00
|
|
|
include ${ROOT}/config.mk
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
CPPFLAGS += -DAUTHORS=\"${authors}\" -DVERSION=${version} -DYEAR=${year}
|
|
|
|
CPPFLAGS += -D_POSIX_C_SOURCE=200809L
|
|
|
|
CPPFLAGS += -DHAVE_INLINE
|
|
|
|
LDLIBS += -lm
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
${cmdname}: ${cmdname}.o
|
|
|
|
|
|
|
|
.PHONY: debug
|
|
|
|
debug:
|
|
|
|
CFLAGS+=\"-g3 -O0 -DDEBUG=9\" ${MAKE}
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
.PHONY: clean
|
2014-03-20 13:53:57 +01:00
|
|
|
clean:
|
2014-11-18 10:56:51 +01:00
|
|
|
rm -f ${cmdname} *.d *.o
|
2014-08-28 13:24:08 +02:00
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
## Generate prerequisites automatically. GNU Make only.
|
|
|
|
## The 'awk' part is used to add the .d file itself to the target, so that it
|
|
|
|
## gets updated on changes. The -MQ option is to add full path to object files
|
|
|
|
## in subfolders. (-MM strips parent directories.)
|
2014-08-28 13:24:08 +02:00
|
|
|
%.d: %.c
|
2014-11-18 10:56:51 +01:00
|
|
|
${CC} -MM -MQ ${<:.c=.o} ${CPPFLAGS} $< | awk -v stem=$* -v target=$@ '{gsub (stem \".o[ :]*\", stem \".o \" target \" : \")} 1' > $@
|
2014-08-28 13:24:08 +02:00
|
|
|
|
2014-11-18 10:56:51 +01:00
|
|
|
sources = $(wildcard *.c)
|
|
|
|
deps = ${sources:.c=.d}
|
|
|
|
-include ${deps}
|
2014-08-28 13:24:08 +02:00
|
|
|
" > \n)
|
2014-03-20 13:53:57 +01:00
|
|
|
|
2014-08-28 13:24:08 +02:00
|
|
|
(define-skeleton makefile-config
|
|
|
|
"Insert Makefile config." nil
|
2014-11-18 10:56:51 +01:00
|
|
|
"## This file is included by all (sub-)makefiles.
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
## Properties.
|
2014-11-18 10:56:51 +01:00
|
|
|
appname = Name
|
|
|
|
authors = Pierre Neidhardt
|
|
|
|
cmdname = name
|
|
|
|
url = http://ambrevar.bitbucket.org/
|
2014-08-28 13:24:08 +02:00
|
|
|
version = 1.0
|
2014-11-18 10:56:51 +01:00
|
|
|
year = 2014
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
## Folders.
|
|
|
|
srcdir = src
|
2014-11-18 10:56:51 +01:00
|
|
|
docsrcdir = doc
|
|
|
|
testdir = tests
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
## USER SETTINGS
|
|
|
|
|
|
|
|
## Optional compilation flags.
|
2014-11-18 10:56:51 +01:00
|
|
|
CFLAGS ?= -pedantic -std=c99 -Wall -Wextra -Wshadow
|
2014-08-28 13:24:08 +02:00
|
|
|
|
|
|
|
## END OF USER SETTINGS
|
|
|
|
" > \n)
|
2014-03-20 13:53:57 +01:00
|
|
|
|
|
|
|
(provide 'mode-makefile)
|