aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: bffe525f37c08e5c1a543f89a6aa84f6b9d57a11 (plain) (blame)
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
#!/usr/bin/env sh
# configure script for nytpu's implementation of ed(1), in POSIX shell
# It should be pretty generic though, with just slight modifications
#
# Copyright (c) 2021 nytpu <alex@nytpu.com>
# SPDX-License-Identifier: MIT
# For more license details, see LICENSE_MIT or <https://spdx.org/licenses/MIT.html>.
set -eu

add_cflags() {
	echo "CFLAGS += $*"
}
add_ld() {
	echo "LDLIBS += $*"
}

set_macro() {
	add_cflags "-D'$1=\"$2\"'"
}

add_lib() {
	${pkgconfig} --print-errors "$@"
	add_cflags $(${pkgconfig} --cflags "$@")
	for lib in "$@"; do add_ld $(${pkgconfig} --libs "$lib"); done
}

# save stdout and redirec to config.mk
exec >config.mk

pkgconfig=pkg-config

echo "# Configuration for makefile for nytpu's implementation of ed(1)"
echo "# This file was generated automatically by configure. Don't edit."

for opt in "$@"; do
	case "${opt}" in
		--help | -h)
			exec 1>&2
			echo "Usage: $0 [--OPTION]..."
			echo
			echo "Options and variables: [defaults in brackets]"
			echo "  -h, --help           display this help text"
			echo "  --prefix=DIR         install into DIR [/usr/local]"
			echo "  --bindir=DIR         location to install executables [\$(PREFIX)/bin]"
			echo "  --mandir=DIR         location to install man pages [\$(PREFIX)/share/man]"
			echo "  --cc=COMPILER        command to invoke the C11 compiler [cc]"
			echo "  --cflags=FLAGS       command line options for the C compiler [-Wall -Wextra -pedantic -Wfatal-errors -std=c11 -O3 -Wno-missing-field-initializers -Wno-unused-parameter -Werror=return-type]"
			echo "  --ldflags=FLAGS      command line options for the linker []"
			echo "  --pkgconfig=COMMAND  command to run to configure packages [pkg-config]"
			exit 0
			;;
		--prefix=*) echo "PREFIX = ${opt#*=}" ;;
		--bindir=*) echo "BINDIR = ${opt#*=}" ;;
		--mandir=*) echo "MANDIR = ${opt#*=}" ;;
		--cc=*) echo "CC = ${opt#*=}" ;;
		--cflags=*) echo "CFLAGS = ${opt#*=}" ;;
		--ldflags=*) echo "LDFLAGS = ${opt#*=}" ;;
		--pkg-config=*) pkgconfig=${opt#*=} ;;
		*)
			echo "warning: unsupported option ${opt}" >&2
			exit 1
			;;
	esac
done