File: prepare-patch.sh

package info (click to toggle)
xenomai 2.6.3-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 58,208 kB
  • ctags: 39,132
  • sloc: ansic: 118,875; sh: 12,352; makefile: 2,265; xml: 1,356; asm: 764; php: 464; awk: 71; perl: 47
file content (182 lines) | stat: -rw-r--r-- 4,950 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#! /bin/bash

#----------------------------------------------------------------------
# Description: Hacked down & butchered scripts/prepare-kernel.sh..
#               Script to copy assorted sources to a temp directory and
#               generate a kernel patch without the need of a virgin
#               linux source tree.
#----------------------------------------------------------------------

set -e

unset CDPATH

patch_file=xenomai_all.patch

supported_arch="$*"

patch_append() {
    file="$1"

#    echo "diff -u1wbr orig/$file new/$file" >> $patch_file
    echo "--- linux/$file	1970-01-01 01:00:00.000000000 +0100" >> $patch_file
    echo "+++ linux-patched/$file	2007-03-06 17:55:58.000000000 +0000" >> $patch_file
    echo "@@ -500000,0 +500000,2 @@" >> $patch_file
    echo "+" >> $patch_file
    cat >> $patch_file
}

patch_link() {
    recursive="$1"              # "r" or "n"
    link_makefiles="$2"         # "m" or "n"
    target_dir="$3"
    link_dir="$4"

    (
        recursive_opt=""
        directorytype_opt=""
        if test x$recursive = xr; then
            recursive_opts="-mindepth 1"
            directorytype_opt="-type d -o"
        else
            recursive_opt="-maxdepth 1"
        fi
        link_makefiles_opt=""
        if test x$link_makefiles = xm; then
            link_makefiles_opt="-name Makefile -o"
        fi

        cd $xenomai_root/$target_dir &&
        find . $recursive_opt \( $link_makefiles_opt -name Kconfig -o -name '*.[chS]' \) |
        while read f; do
            f=`echo $f | cut -d/ -f2-`
            d=`dirname $f`
            if test ! -d  $temp_tree/$link_dir/$d ; then
                mkdir -p $temp_tree/$link_dir/$d
            fi
            cp $xenomai_root/$target_dir/$f $temp_tree/$link_dir/$f
        done
    )

}

generate_patch() {
    (
    cd "$temp_tree"
    find . -name demos -o -name snippets -exec rm -fR {} \+ &&
    find . -type f |
    while read f ; do
        diff -Naurd "$linux_tree/$f" "$f" |
        sed -e "s,^--- ${linux_tree}/\.\(/.*\)$,--- linux\1," \
            -e "s,^+++ \.\(/.*\)$,+++ linux-patched\1,"
    done
    )
}

diff_addons() {
    lines=`cat $xenomai_root/scripts/Kconfig.frag | wc -l`

    echo "--- linux/init/Kconfig	1970-01-01 01:00:00.000000000 +0100" >> $patch_file
    echo "+++ linux-patched/init/Kconfig	2007-03-06 17:55:58.000000000 +0000" >> $patch_file
    echo "@@ -500000,0 +500000,$lines @@" >> $patch_file
    sed -e "s,@LINUX_ARCH@,$linux_arch,g" $xenomai_root/scripts/Kconfig.frag | sed 's/^/+/' >> $patch_file
    echo " " >> $patch_file
}

xenomai_root=`dirname $0`/..
xenomai_root=`cd $xenomai_root && pwd`

rm -fR $xenomai_root/tmp
rm -f $patch_file

mkdir -p $xenomai_root/tmp/linux
mkdir -p $xenomai_root/tmp/linux.new
linux_tree="$xenomai_root/tmp/linux"
temp_tree="$xenomai_root/tmp/linux.new"


for linux_arch in $supported_arch ; do
    case $linux_arch in
        i386)
            base_arch=x86
            ;;
        x86_64)
            base_arch=x86
            ;;
        x86)
            base_arch=x86
            ;;
        *)
            base_arch=$linux_arch
            ;;
    esac

    patch_link r m ksrc/arch/$base_arch arch/$linux_arch/xenomai
    patch_link r n include/asm-$base_arch arch/$linux_arch/include/asm/xenomai

    p="+drivers-\$(CONFIG_XENOMAI)		+= arch/$linux_arch/xenomai/"
    echo $p | patch_append arch/$linux_arch/Makefile
    diff_addons
done

p="+obj-\$(CONFIG_XENOMAI)		+= xenomai/"
echo $p | patch_append drivers/Makefile

p="+obj-\$(CONFIG_XENOMAI)		+= xenomai/"
echo $p | patch_append kernel/Makefile

# Create local directories then symlink to the source files from
# there, so that we don't pollute the Xenomai source tree with
# compilation files.
patch_link n m ksrc/ kernel/xenomai
patch_link n m ksrc/arch kernel/xenomai/arch
patch_link r m ksrc/arch/generic kernel/xenomai/arch/generic
patch_link n m ksrc/nucleus kernel/xenomai/nucleus
patch_link r m ksrc/skins kernel/xenomai/skins
patch_link r m ksrc/drivers drivers/xenomai
patch_link r n include/asm-generic include/asm-generic/xenomai
patch_link n n include include/xenomai
cd $xenomai_root
for d in include/* ; do
    if test -d $d -a -z "`echo $d | grep '^include/asm-'`"; then
        destdir=`echo $d | sed -e 's,^\(include\)\(/.*\)$,\1/xenomai\2,'`
        patch_link r n $d $destdir
    fi
done

generate_patch >> $patch_file

cd $xenomai_root

find $xenomai_root/ksrc/ -name "*ipipe*-$supported_arch-*.patch" |
while read f ; do

    file=`basename $f`
    arch=`echo $file | cut -d- -f4`
    kver=`echo $file | cut -d- -f3`

    case $arch in
        arm)
            march=arm
        ;;
        i386)
            march=i386
        ;;
        ppc|ppc64|powerpc)
            march=powerpc
        ;;
        x86_64)
            march=amd64
        ;;
	x86)
	    march=i386
	;;
    esac

    cp $f $xenomai_root/$file
    cat $xenomai_root/$patch_file >> $xenomai_root/$file

done

exit 0