]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/buildtools/auto-config-h.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / buildtools / auto-config-h.sh
CommitLineData
7c673cae 1#!/bin/sh
11fdf7f2
TL
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright 2014-2015 6WIND S.A.
7c673cae
FG
4#
5# Crude script to detect whether particular types, macros and functions are
6# defined by trying to compile a file with a given header. Can be used to
7# perform cross-platform checks since the resulting object file is not
8# executed.
9#
10# Set VERBOSE=1 in the environment to display compiler output and errors.
11#
12# CC, CPPFLAGS, CFLAGS, EXTRA_CPPFLAGS and EXTRA_CFLAGS are taken from the
13# environment.
14#
15# AUTO_CONFIG_CFLAGS may append additional CFLAGS without modifying the
16# above variables.
17
18file=${1:?output file name required (config.h)}
19macro=${2:?output macro name required (HAVE_*)}
20include=${3:?include name required (foo.h)}
21type=${4:?object type required (define, enum, type, field, func)}
22name=${5:?define/type/function name required}
23
24: ${CC:=cc}
25
9f95a23c 26temp=$(mktemp -t dpdk.${0##*/}.c.XXXXXX)
7c673cae
FG
27
28case $type in
29define)
30 code="\
31#ifndef $name
32#error $name not defined
33#endif
34"
35 ;;
36enum)
37 code="\
38long test____ = $name;
39"
40 ;;
41type)
42 code="\
43$name test____;
44"
45 ;;
46field)
47 code="\
48void test____(void)
49{
50 ${name%%.*} test_____;
51
52 (void)test_____.${name#*.};
53}
54"
55 ;;
56func)
57 code="\
58void (*test____)() = (void (*)())$name;
59"
60 ;;
61*)
62 unset error
63 : ${error:?unknown object type \"$type\"}
64 exit
65esac
66
67if [ "${VERBOSE}" = 1 ]
68then
69 err=2
70 out=1
71 eol='
72'
73else
74 exec 3> /dev/null ||
75 exit
76 err=3
77 out=3
78 eol=' '
79fi &&
80printf 'Looking for %s %s in %s.%s' \
81 "${name}" "${type}" "${include}" "${eol}" &&
82printf "\
83#include <%s>
84
85%s
86" "$include" "$code" > "${temp}" &&
87if ${CC} ${CPPFLAGS} ${EXTRA_CPPFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} \
88 ${AUTO_CONFIG_CFLAGS} \
9f95a23c 89 -xc -c -o ${temp}.o "${temp}" 1>&${out} 2>&${err}
7c673cae 90then
11fdf7f2 91 rm -f "${temp}" "${temp}.o"
7c673cae
FG
92 printf "\
93#ifndef %s
94#define %s 1
95#endif /* %s */
96
97" "${macro}" "${macro}" "${macro}" >> "${file}" &&
98 printf 'Defining %s.\n' "${macro}"
99else
11fdf7f2 100 rm -f "${temp}" "${temp}.o"
7c673cae
FG
101 printf "\
102/* %s is not defined. */
103
104" "${macro}" >> "${file}" &&
105 printf 'Not defining %s.\n' "${macro}"
106fi
107
108exit