1#!/bin/sh
2id='$Id: create_flat_tuneups.sh 331412 2011-08-16 18:55:10Z ucko $'
3
4PATH=/bin:/usr/bin
5export PATH
6
7exec > auto_flat_tuneups.mk
8
9cat <<EOF
10# This file was generated on `date`
11# by $id
12EOF
13
14LC_ALL=C
15export LC_ALL
16
17IFS="$IFS;"
18while read l; do
19    case "$l" in
20        *.*.real\ :*)
21            set _ $l
22            target=$2
23            ;;
24        *cd\ *MAKE*\ sources)
25            set _ $l
26            echo "$3 1 $target"
27            ;;
28        *cd\ *MAKE*_PROJ=*)
29            set _ $l
30            echo "$3 2 $target $2"
31            ;;
32        ptb_all.real\ :* )
33            echo '~~~'
34            ;;
35    esac
36done < Makefile.flat | sort | \
37while read dir phase target rest; do
38    if [ "$dir" \!= "$last_dir" ]; then
39        if [ -n "$last_dir" ]; then
40            if [ -n "$spec" ]; then
41                echo "$last_dir.files.real: $spec ;"
42                echo "spec_bearing_dirs += $last_dir"
43            else
44                echo "${type}_dirs += $last_dir"
45            fi
46        fi
47        [ -n "$phase" ]  ||  continue
48        echo
49        spec=''
50        type=expendable
51    fi
52    case "$phase:$spec:$rest" in
53        1::* )
54            echo "$target: override MAKE := \$(DO_MAKE)"
55            spec=$target
56            ;;
57        1:* )
58            echo "$target: override MAKE := : \$(MAKE)"
59            echo "$target: $spec";
60            ;;
61        2::*-*cd)
62            echo "$target: $dir.files"
63            ;;
64        2::* )
65            echo "$target: $dir.files"
66            type=plain
67            ;;
68        2:* )
69            echo "$target: $spec"
70            ;;
71    esac
72    last_dir=$dir
73done
74
75exit 0
76