aboutsummaryrefslogtreecommitdiffstats
path: root/bs/bs-lib.sh
blob: 8b13653f2bd0dde0b17a5c8c8a25dd3cf52610d9 (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
#!/bin/sh
# common shell functions and variable setup for the bs build system,
# expect variables to be set and exported in bs.mk

test -z "$CC" && CC=cc
test -z "$CPP" && CPP='cc -E'
test -z "$PKGCONFIG" && PKGCONFIG=pkg-config

p ()
{
	echo >&2 "$@"
}

run_cc ()
{
	$CC $CPPFLAGS $CFLAGS $LDFLAGS \
		$cppflags $cflags $ldflags -o t.o t.c >/dev/null 2>&1
}

test_header ()
{
	cat > t.c <<EOF
#include <$1.h>
int main (void) { return 0; }
EOF
	run_cc
}

dep_paths ()
{
	name=$1
	eval "cflags=`echo '$'`${name}_cflags"
	eval "ldflags=`echo '$'`${name}_ldflags"
	eval "pfx=`echo '$'`${name}_pfx"
	if test -n "$pfx"; then
		cflags="$cflags -I$pfx/include"
		ldflags="$ldflags -L$pfx/lib"
	fi
}

test_compile ()
{
	h=shift
	cat > t.c <<EOF
#include <$h.h>
int main () { $@ return 0; }
EOF
	run_cc
}