source: mainline/tools/autogen2.sh@ 5af6cf3d

Last change on this file since 5af6cf3d was 5af6cf3d, 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
8echo $PWD
9
10input="$1"
11output="$2"
12toolsdir="$(readlink -f $(dirname "$0"))"
13awkscript="$toolsdir/autogen2.awk"
14
15# Set default value for $CC.
16if [ -z "${CC}" ]; then
17 CC=cc
18fi
19
20# If $CC is clang, we need to make sure integrated assembler is not used.
21if ( ${CC} --version | grep clang > /dev/null ) ; then
22 CFLAGS="${CFLAGS} -no-integrated-as"
23fi
24
25# Tell the compiler to generate makefile dependencies.
26CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
27
28# Generate defines
29defs=`$awkscript -- $input || exit 1`
30
31# Generate C file.
32cat > $output.c <<- EOF
33
34#include "`basename $input`"
35
36#define DEFINE_MEMBER(ls, us, lm, um) \
37 asm volatile ("/* #define "#us"_OFFSET_"#um" %0 */" :: "i" (__builtin_offsetof(struct ls, lm))); \
38 asm volatile ("/* #define "#us"_SIZE_"#um" %0 */" :: "i" (sizeof((struct ls){}.lm)));
39
40#define DEFINE_STRUCT(ls, us) \\
41 asm volatile ("/* #define "#us"_SIZE %0 */" :: "i" (sizeof(struct ls)));
42
43void autogen()
44{
45 $defs
46}
47
48EOF
49
50# Turn the C file into assembly.
51${CC} ${CFLAGS} -w -S -o $output.s $output.c || exit 1
52
53# Process the output.
54
55echo "/* Autogenerated file, do not modify. */" > $output
56echo "#pragma once" >> $output
57sed -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.