PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/work/compile_plugins.sh

http://github.com/tybor/Liberty
Shell | 131 lines | 95 code | 30 blank | 6 comment | 13 complexity | 1912d64604147bb5b180f8e5ef9f0151 MD5 | raw file
  1#!/usr/bin/env bash
  2
  3cd ${0%/*}/..
  4export LIBERTY_HOME=$(pwd)
  5cd target
  6
  7export LOG=${LOG:-$LIBERTY_HOME/work/compile_plugins.log}
  8
  9. $LIBERTY_HOME/work/tools.sh
 10
 11eval `se -environment | grep -v '^#'`
 12SE_SYS=${SE_SYS%/}
 13export SE_SYS
 14
 15n1=$(find $SE_SYS/plugins -name c -type d | wc -l)
 16n2=$(find $SE_SYS/runtime -name basic_\*.[ch] | sed 's/\.[ch]$//' | uniq | wc -l)
 17n=$((n1+n2))
 18i=0
 19
 20do_generate()
 21{
 22    plugin_name="$1"
 23    plugin_h="$2"
 24    plugin_c="$3"
 25    plugin_so="$4"
 26    plugin_dir="$5"
 27    location="$6"
 28    plugin_pattern="$7"
 29    plugin_source="$8"
 30
 31    test -d $plugin_dir || mkdir -p $plugin_dir
 32
 33    progress 30 $((i*3)) $((n*3)) "Generating header file for $plugin_so"
 34
 35    {
 36        cat <<EOF
 37#ifndef __LIBERTY_PLUGIN__
 38#define __LIBERTY_PLUGIN__
 39
 40#include "base.h"
 41#include <errno.h>
 42
 43EOF
 44        if [ "$(echo ${plugin_pattern}*.h)" != "$plugin_pattern"'*.h' ]; then
 45            for f in ${plugin_pattern}*.h; do
 46                echo '#include "'${f##*/}'"'
 47            done
 48        fi
 49
 50        echo
 51
 52        find $path_liberty -name \*.e -exec grep -Hn 'location: "${sys}/'$location'"' {} \; | \
 53            awk -F: '{print $1}' | uniq | \
 54            xargs -n1 awk '/module_name: "'$plugin_name'"/ { i=1 } /feature_name: "[^"]*"/ { if (i) printf("%s %s\n", ARGV[1], $2); i=0 }' | \
 55            sed 's/"\([^"]*\)"/\1/g' | sort -u | \
 56        while read file symbol; do
 57            {
 58                cat $file | grep "$symbol" | grep ' is$'
 59                cat $file | grep -C3 'feature_name: "'$symbol'"'
 60            } | $LIBERTY_HOME/work/find_feature.py header $symbol ${file##*/}
 61        done | sort -u
 62
 63        echo '#endif'
 64    } > $plugin_h
 65
 66    progress 30 $((i*3+1)) $((n*3)) "Generating code file for $plugin_so"
 67
 68    {
 69        cat <<EOF
 70#include "${plugin_h##*/}"
 71
 72EOF
 73        if [ "$(echo ${plugin_pattern}*.c)" != "$plugin_pattern"'*.c' ]; then
 74            for f in ${plugin_pattern}*.c; do
 75                echo '#include "'${f##*/}'"'
 76            done
 77        fi
 78
 79        echo
 80
 81        find $path_liberty -name \*.e -exec grep -Hn 'location: "${sys}/'"$location"'"' {} \; | \
 82            awk -F: '{print $1}' | uniq | \
 83            xargs -n1 awk '/module_name: "'$plugin_name'"/ { i=1 } /feature_name: "[^"]*"/ { if (i) printf("%s %s\n", ARGV[1], $2); i=0 }' | \
 84            sed 's/"\([^"]*\)"/\1/g' | sort -u | \
 85        while read file symbol; do
 86            {
 87                cat $file | grep -E "^[[:space:]]*$symbol(|[:([:space:]].*) is$"
 88                cat $file | grep -C3 'feature_name: "'$symbol'"'
 89            } | $LIBERTY_HOME/work/find_feature.py code $symbol ${file##*/}
 90        done | sort -u
 91    } > $plugin_c
 92
 93    progress 30 $((i*3+2)) $((n*3)) "Building $plugin_so"
 94
 95    run gcc -iquote $SE_SYS/runtime/c -iquote $plugin_source -shared -fpic -fvisibility=hidden -o $plugin_so $plugin_c
 96}
 97
 98find $SE_SYS/runtime -name basic_\*.[ch] | sed 's/\.[ch]$//' | uniq | while read basic_plugin; do
 99    plugin_dir=${basic_plugin#$SE_SYS/}
100    plugin_dir=$(echo $plugin_dir | sed 's=/c/=/=')
101    plugin_name=${plugin_dir##*/}
102    plugin_h=${plugin_dir}~.h
103    plugin_c=${plugin_dir}~.c
104    plugin_so=${plugin_dir}.so
105    plugin_dir=${plugin_dir%/*}
106
107    do_generate "$plugin_name" "$plugin_h" "$plugin_c" "$plugin_so" "$plugin_dir" "runtime" "$basic_plugin" "$SE_SYS/runtime/c"
108
109    cp -a $plugin_so ${basic_plugin}.so
110
111    i=$((i+1))
112done
113
114find $SE_SYS/plugins -name c -type d | while read plugin; do
115    plugin_dir=${plugin#$SE_SYS/}
116    plugin_dir=${plugin_dir%/c}
117    plugin_name=${plugin_dir##*/}
118    plugin_so=${plugin_dir}.so
119    plugin_h=${plugin_dir}~.h
120    plugin_c=${plugin_dir}~.c
121    plugin_dir=${plugin_dir%/*}
122
123    do_generate "$plugin_name" "$plugin_h" "$plugin_c" "$plugin_so" "$plugin_dir" "plugins" "$plugin/" "$plugin"
124
125    mkdir -p ${plugin%/c}/run
126    cp -a $plugin_so ${plugin%/c}/run/${plugin_name}.so
127
128    i=$((i+1))
129done
130
131progress 30 $n $n "done."