aboutsummaryrefslogtreecommitdiff
path: root/config.rc
blob: f09b44c7e5c1256370b08b296d11e3316d630084 (plain)
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
70
71
72
73
# -*- mode: redo -*-
# See LICENSE for copyright information

setv() {
    # Set variables if unset. Works similar to the Makefile syntax.
    [ "$3" ] || {
        printf '%s\n' "Faulty variable syntax" >&2
        exit 1
    }
    var=$1; sym=$2; shift 2
    case "$sym" in
        \?=|=) eval "[ \"\$$var\" ]" || export "$var=$*" ;;
        +=)    eval "export \"$var=\$$var $*\""
    esac
}

setv VERSION = 5.1.1

# Paths
setv PREFIX    = /usr/local
setv BINDIR    = "${PREFIX}/bin"
setv SHAREDIR  = "${PREFIX}/share"
setv DOCDIR    = "${SHAREDIR}/doc"
setv CPTDOC    = "${DOCDIR}/cpt"
setv MANPREFIX = "${SHAREDIR}/man"
setv MAN1      = "${MANPREFIX}/man1"

# Flags
setv CFLAGS = -std=c99 -Wpedantic -Wall -Os
setv CFLAGS += -D_XOPEN_SOURCE=700
setv LDFLAGS = -s -static
setv LIBS    = -lc

setv CC = cc
setv LD = "${CC}"

# Documentation tools
setv EMACS    = emacs
setv MAKEINFO = makeinfo

# Helper functions
redo_clean() {
    # Clean function for various redo implementations
    [ -r .do_built ] && {
        while read -r file; do
            [ -d "$file" ] || rm -f "$file"
        done < .do_built
    }
    find . -type f \( -name '*.tmp' -o -name '*.did' -o -name '.dep*' -o -name '.target*' \) \
         -exec rm -f -- {} +
    [ "$DO_BUILT" ]  || find . -name '.do_built*' -exec rm -rf -- {} +
    [ "$REDO_BASE" ] || rm -rf -- .redo
}

PHONY() {
    # Function that resembles the .PHONY: target on the classic 'make' build
    # system.
    [ "$1" ] || {
        trap 'rm -f $3' EXIT INT
        return 0
    }
    setv PHONY += "$@"
    trap 'case " $PHONY " in *" $1 "*) rm -f $3; esac' EXIT INT
}

getbin() {
    # Function to get all executables
    find src contrib bin -name 'cpt-*' ! -name '*.in' ! -name '*.[coh]'
}


# Phony targets
PHONY all dist clean install uninstall test