Skip to content

Commit

Permalink
change(build): mild improvements
Browse files Browse the repository at this point in the history
I'm really regretting writing my own configure script. Some lessons you need to learn the hard way...
  • Loading branch information
eddieantonio committed Oct 30, 2023
1 parent 24880ef commit f0c3723
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions configure
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh

# A handwritten ./configure script, because I kind of hate autotools.
# © 2020 Eddie Antonio Santos <easantos@ualberta.ca>
# Update (2023): Autotools=still awful. But writing this was a mistake.
# © 2020–2023 Eddie Antonio Santos <hello@eddieantonio.ca>

set -e

Expand Down Expand Up @@ -129,7 +130,7 @@ require_system_header() {

use_cxxflag() {
flag="$1"
printf "checking to compile C++ with ${flag}... "
printf 'checking to compile C++ with %s...' "${flag}"

compile_test_cxx_program "${flag}" <<EOF
int main(void) {
Expand All @@ -148,11 +149,11 @@ link_lib_against_test_program() {

printf 'checking to link with lib%s [using %s()]... ' "$lib" "$funcname"
compile_test_program -l"${lib}" <<EOF
char ${funcname}(void);
char ${funcname}(void);
int main(void) {
return ${funcname}();
}
int main(void) {
return ${funcname}();
}
EOF
}

Expand All @@ -164,21 +165,25 @@ link_lib_against_test_program_using_pkgconfig() {
lib=$2

printf 'checking to link with lib%s using pkg-config [using %s()]... ' "$lib" "$funcname"
compile_test_program $(pkg-config --cflags --libs lib${lib}) <<EOF
char ${funcname}(void);
# Contrary to best practices, pkg-config actually depends on its output
# being broken by spaces to create multiple arguments from one invocation,
# so ignore the lint:
# shellcheck disable=SC2046
compile_test_program $(pkg-config --cflags --libs "lib${lib}") <<EOF
char ${funcname}(void);
int main(void) {
return ${funcname}();
}
int main(void) {
return ${funcname}();
}
EOF
}

# Add the appropriate flags for the given library using pkg-config(1)
extend_libs_and_includes_using_pkgconfig() {
lib=$1

libs="${libs} $(pkg-config --libs lib${lib})"
includes="${includes} $(pkg-config --cflags lib${lib})"
libs="${libs} $(pkg-config --libs "lib${lib}")"
includes="${includes} $(pkg-config --cflags "lib${lib}")"
}

# Check if the program is on the path.
Expand Down Expand Up @@ -217,11 +222,11 @@ compile_with_header() {
# term.h on newer macOS.
# See: https://github.com/eddieantonio/imgcat/issues/51
compile_test_program -c <<EOF
#ifdef __APPLE__
#include <Availability.h>
#endif
#ifdef __APPLE__
#include <Availability.h>
#endif
#include <${header}>
#include <${header}>
EOF
}

Expand Down

0 comments on commit f0c3723

Please sign in to comment.