source: mainline/tools/autogen2.sh@ 95aed62

Last change on this file since 95aed62 was 95aed62, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

todo

  • Property mode set to 100755
File size: 1.6 KB
Line 
1#!/bin/sh
2
3# There's a bunch of restriction. The script assumes that the structure definition begins with "typedef struct struct_name {",
4# ends with "struct_name_t;", and that every word in between that ends with ";" is a struct member name with optional
5# array subscript. Error handling is mostly omitted for simplicity, so any input that does not follow these rules will result
6# in cryptic errors.
7
8input="$1"
9output="$2"
10toolsdir="$(readlink -f $(dirname "$0"))"
11awkscript="$toolsdir/autogen2.awk"
12
13# Set default value for $CC.
14if [ -z "${CC}" ]; then
15 CC=cc
16fi
17
18# If $CC is clang, we need to make sure integrated assembler is not used.
19if ( ${CC} --version | grep clang > /dev/null ) ; then
20 CFLAGS="${CFLAGS} -no-integrated-as"
21fi
22
23# Tell the compiler to generate makefile dependencies.
24CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
25
26# Generate defines
27defs=`$awkscript -- $input || exit 1`
28
29# Generate C file.
30cat > $output.c <<- EOF
31
32#include "`basename $input`"
33
34#define DEFINE_MEMBER(ls, us, lm, um) \
35 asm volatile ("/* #define "#us"_OFFSET_"#um" %0 */" :: "i" (__builtin_offsetof(struct ls, lm))); \
36 asm volatile ("/* #define "#us"_SIZE_"#um" %0 */" :: "i" (sizeof((struct ls){}.lm)));
37
38#define DEFINE_STRUCT(ls, us) \\
39 asm volatile ("/* #define "#us"_SIZE %0 */" :: "i" (sizeof(struct ls)));
40
41void autogen()
42{
43 $defs
44}
45
46EOF
47
48# Turn the C file into assembly.
49${CC} ${CFLAGS} -w -S -o $output.s $output.c || exit 1
50
51# Process the output.
52
53echo "/* Autogenerated file, do not modify. */" > $output
54echo "#pragma once" >> $output
55sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' < $output.s > $output || exit 1
Note: See TracBrowser for help on using the repository browser.