-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
69 lines (55 loc) · 2.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
.PHONY: clean generate uninstall scons src/Makefile src/cxx
NAME := cxx
ALIAS := autocompile
# the directory of this Makefile
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SRCDIR := ${ROOTDIR}/src
# macOS detection
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
PREFIX ?= /usr/local
MAKE ?= make
else ifeq ($(UNAME_S),FreeBSD)
PREFIX ?= /usr/local
MAKE ?= gmake
else
PREFIX ?= /usr
MAKE ?= make
endif
VERSION := $(shell grep -F '* Version: ' README.md | cut -d' ' -f3)
# used by the "pkg" target
ifeq ($$pkgdir,)
pkgdir := $$pkgdir
else
pkgdir ?= ${PWD}/pkg
endif
generate: src/Makefile src/cxx
src/Makefile: src/Makefile.in
@sed "s,@@PREFIX@@,${PREFIX},g;s,@@MAKE@@,${MAKE},g;s,@@VERSION@@,${VERSION},g" "${ROOTDIR}/$<" > "${ROOTDIR}/$@"
src/cxx: src/cxx.in
@sed "s,@@PREFIX@@,${PREFIX},g;s,@@MAKE@@,${MAKE},g;s,@@VERSION@@,${VERSION},g" "${ROOTDIR}/$<" > "${ROOTDIR}/$@"
install: scons generate
@install -d "${DESTDIR}${PREFIX}/bin"
@install -m755 "${SRCDIR}/${NAME}" "${DESTDIR}${PREFIX}/bin/${NAME}"
@ln -sf "${PREFIX}/bin/${NAME}" "${DESTDIR}${PREFIX}/bin/${ALIAS}"
@install -d "${DESTDIR}${PREFIX}/share/${NAME}"
@install -m644 "${SRCDIR}/Makefile" "${DESTDIR}${PREFIX}/share/${NAME}/Makefile"
@install -m644 "${SRCDIR}/build.py" "${DESTDIR}${PREFIX}/share/${NAME}/build.py"
@install -d "${DESTDIR}${PREFIX}/share/licenses/${NAME}"
@install -m644 "${ROOTDIR}/LICENSE" "${DESTDIR}${PREFIX}/share/licenses/${NAME}/LICENSE" || true
scons:
@scons --version 2>/dev/null 1>/dev/null || (echo 'please install scons'; exit 1)
uninstall:
@-rm -f "${DESTDIR}${PREFIX}/bin/${NAME}"
@-rm -f "${DESTDIR}${PREFIX}/bin/${ALIAS}"
@-rmdir "${DESTDIR}${PREFIX}/bin" 2>/dev/null || true
@-rm -f "${DESTDIR}${PREFIX}/share/${NAME}/Makefile"
@-rm -f "${DESTDIR}${PREFIX}/share/${NAME}/build.py"
@-rmdir "${DESTDIR}${PREFIX}/share/${NAME}" 2>/dev/null || true
@-rm -f "${DESTDIR}${PREFIX}/share/licenses/${NAME}/LICENSE" || true
@-rmdir "${DESTDIR}${PREFIX}/share/licenses/${NAME}" 2>/dev/null || true
clean:
@-rm -f src/Makefile src/cxx
# like install, but override DESTDIR in order to place everything in "${pkgdir}"
pkg: DESTDIR ?= ${pkgdir}
pkg: install