aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: 7d8079bd04cf1d785a58bd5553fd1a8c77ac9dc9 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh -eu
#
# DFM configure script.
#
# Copyright (c) 2026 Dylan Araps - MIT License
#
# The configure script takes three forms of arguments.
#
# 1) Long-opts:           --prefix=/usr --help
# 2) Variables:           CC=/bin/cc CFLAGS="-O3" CONFIG_TINY=1
# 3) C macro definitions: -DMACRO -DMACRO=VALUE -UMACRO
#
# Everything below, as well as in the Makefile.in and config.h.in files can be
# configured via this script. Alternatively, you can edit the files directly,
# refer to them for more information.
#

#
# Program configuration.
#
export CFG_NAME=dfm
export CFG_VERSION=1.0.0
export c_version=c99

#
# DPP configuration.
#
export CFG_DPP_INCLUDE=./configure
CFG_DPP_CMD="$(command -v dpp 2>/dev/null || echo bin/dpp)"
export CFG_DPP_CMD
export PATH="$PWD/bin:$PATH"

#
# Make configuration.
#
export CFG_MAKE_FILE=Makefile
export CFG_MAKE_CONFIG=Makefile.in
export CFG_MANUAL=README.txt
export CFG_BUILD=config.h.in
export CFG_BUILD_GEN=config.h
export CFG_INPUT=config_key.h.in
export CFG_INPUT_GEN=config_key.h
export CFG_COMMAND_GEN=config_cmd.h
export CFG_COMMAND=config_cmd.h.in
export CFG_MACRO_GEN=.config_macro.h
export CFG_MAKE_DEP="*/*.[ch] *.[ch] $CFG_MAKE_FILE $CFG_MAKE_CONFIG $CFG_DPP_INCLUDE"
export CFG_IGNORE=.gitignore

#
# Installation
#
export prefix=/usr/local

#
# Build commands.
#
export RM="${RM:-rm}"
export MKDIR="${MKDIR:-mkdir}"
export CP="${CP:-cp}"
export CC="${CC:-cc}"
export STRIP="${STRIP:-strip}"

#
# Compiler flags.
#
export cc_flags="-std=$c_version -O2 -pipe"
export cc_flags="$cc_flags -Wall -Wextra -pedantic -Wshadow"

#///////////////////////////////////////////////////////////////////////////////
#
# NOTE: Do not edit below this line.
#
case ${DPP_LEVEL:-} in '')
  #
  # Handle command-line arguments.
  #
  # '--prefix=/usr' -> 'export prefix=/usr'
  # 'prefix=/usr'   -> 'export prefix=/usr'
  # '-DWORD'        -> 'export WORD' '#undef WORD\n#define WORD'
  # '-DWORD=val'    -> 'export WORD' '#undef WORD\n#define WORD val'
  # '-UWORD'        -> 'unset WORD'  'CFLAGS+=-UWORD'
  #
  for a do case $a in
    --help) cat "$0"; exit 0 ;;
       -D*) mo="${mo:-}$a
" _a=${a#-D}; export "${_a%%=*}="  ;;
       -U*) cc_flags="$cc_flags $a"; unset  "${a#-U}" ;;
     *?=?*) export "${a#--}" ;;
  esac done

  #
  # Build configurations.
  #
  case ${CONFIG_SMALL:=${CONFIG_TINY:=0}} in 1)
    cc_flags="$cc_flags -Os -DNDEBUG"
    cc_flags="$cc_flags -fno-asynchronous-unwind-tables -fno-unwind-tables"
    cc_flags="$cc_flags -Wl,-z,norelro"
    cc_flags="$cc_flags -no-pie"
    cc_flags="$cc_flags -fno-plt"
    strip_flags="${strip_flags:-} -s -R .comment -R .note"
    strip_flags="$strip_flags --remove-section=.eh_frame"
    strip_flags="$strip_flags --remove-section=.eh_frame_hdr"
    export strip_flags

    case ${CONFIG_TINY:=0} in 1)
      cc_flags="$cc_flags -Oz"
    esac
  esac

  #
  # Generate macro overrides.
  #
  while IFS== read -r k v; do
    echo "${k:+#undef ${k#-D}
#define ${k#-D} $v}"
  done <<EOF > "$CFG_MACRO_GEN"
${mo:-}
EOF

  #
  # Generate .gitignore.
  #
  cat <<EOF > "$CFG_IGNORE"
$CFG_IGNORE
$CFG_NAME
$CFG_MACRO_GEN
$CFG_BUILD_GEN
$CFG_COMMAND_GEN
$CFG_INPUT_GEN
$CFG_MAKE_FILE
EOF

  #
  # Generate Makefile
  #
  "$CFG_DPP_CMD" < "$CFG_MAKE_CONFIG" > "$CFG_MAKE_FILE"
esac