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
RevLine 
[d5e5fd1]1#!/bin/sh
2
[5af6cf3d]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.
[d5e5fd1]7
[5af6cf3d]8input="$1"
9output="$2"
10toolsdir="$(readlink -f $(dirname "$0"))"
11awkscript="$toolsdir/autogen2.awk"
[d5e5fd1]12
[5af6cf3d]13# Set default value for $CC.
[d5e5fd1]14if [ -z "${CC}" ]; then
15 CC=cc
16fi
17
[5af6cf3d]18# If $CC is clang, we need to make sure integrated assembler is not used.
[d5e5fd1]19if ( ${CC} --version | grep clang > /dev/null ) ; then
20 CFLAGS="${CFLAGS} -no-integrated-as"
21fi
22
[5af6cf3d]23# Tell the compiler to generate makefile dependencies.
24CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
[d5e5fd1]25
[5af6cf3d]26# Generate defines
27defs=`$awkscript -- $input || exit 1`
[d5e5fd1]28
[5af6cf3d]29# Generate C file.
30cat > $output.c <<- EOF
[d5e5fd1]31
[5af6cf3d]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)));
[d5e5fd1]40
41void autogen()
42{
[5af6cf3d]43 $defs
[d5e5fd1]44}
45
46EOF
[5af6cf3d]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.