1#! /bin/sh
2#
3# mkbltnmlst.sh: generate boot code for linked-in modules
4#
5# Written by Andrew Main
6#
7
8srcdir=${srcdir-`echo $0|sed 's%/[^/][^/]*$%%'`}
9test "x$srcdir" = "x$0" && srcdir=.
10test "x$srcdir" = "x"   && srcdir=.
11CFMOD=${CFMOD-$srcdir/../config.modules}
12
13bin_mods="`grep ' link=static' $CFMOD | sed -e '/^#/d' \
14-e 's/ .*/ /' -e 's/^name=/ /'`"
15
16x_mods="`grep ' load=yes' $CFMOD | sed -e '/^#/d' -e '/ link=no/d' \
17-e 's/ .*/ /' -e 's/^name=/ /'`"
18
19trap "rm -f $1; exit 1" 1 2 15
20
21exec > $1
22
23for x_mod in $x_mods; do
24    modfile="`grep '^name='$x_mod' ' $CFMOD | sed -e 's/^.* modfile=//' \
25      -e 's/ .*//'`"
26    if test "x$modfile" = x; then
27	echo >&2 "WARNING: no name for \`$x_mod' in $CFMOD (ignored)"
28	continue
29    fi
30    case "$bin_mods" in
31    *" $x_mod "*)
32        echo "/* linked-in known module \`$x_mod' */"
33	linked=yes
34	;;
35    *)
36        echo "#ifdef DYNAMIC"
37        echo "/* non-linked-in known module \`$x_mod' */"
38	linked=no
39    esac
40    unset moddeps autofeatures autofeatures_emu
41    . $srcdir/../$modfile
42    if test "x$autofeatures" != x; then
43        if test "x$autofeatures_emu" != x; then
44            echo "  {"
45	    echo "    char *zsh_features[] = { "
46	    for feature in $autofeatures; do
47		echo "      \"$feature\","
48	    done
49	    echo "      NULL"
50	    echo "    }; "
51	    echo "    char *emu_features[] = { "
52	    for feature in $autofeatures_emu; do
53		echo "      \"$feature\","
54	    done
55	    echo "      NULL"
56	    echo "    }; "
57	    echo "    autofeatures(\"zsh\", \"$x_mod\","
58	    echo "       EMULATION(EMULATE_ZSH) ? zsh_features : emu_features,"
59	    echo "       0, 1);"
60	    echo "  }"
61        else
62	    echo "  if (EMULATION(EMULATE_ZSH)) {"
63	    echo "    char *features[] = { "
64	    for feature in $autofeatures; do
65		echo "      \"$feature\","
66	    done
67	    echo "      NULL"
68	    echo "    }; "
69	    echo "    autofeatures(\"zsh\", \"$x_mod\", features, 0, 1);"
70	    echo "  }"
71	fi
72    fi
73    for dep in $moddeps; do
74	echo "  add_dep(\"$x_mod\", \"$dep\");"
75    done
76    test "x$linked" = xno && echo "#endif"
77done
78
79echo
80done_mods=" "
81for bin_mod in $bin_mods; do
82    q_bin_mod=`echo $bin_mod | sed 's,Q,Qq,g;s,_,Qu,g;s,/,Qs,g'`
83    modfile="`grep '^name='$bin_mod' ' $CFMOD | sed -e 's/^.* modfile=//' \
84      -e 's/ .*//'`"
85    echo "/* linked-in module \`$bin_mod' */"
86    unset moddeps
87    . $srcdir/../$modfile
88    for dep in $moddeps; do
89	# This assumes there are no circular dependencies in the builtin
90	# modules.  Better ordering of config.modules would be necessary
91	# to enforce stricter dependency checking.
92	case $bin_mods in
93	    *" $dep "*)
94		echo "    /* depends on \`$dep' */" ;;
95	    *)	echo >&2 "ERROR: linked-in module \`$bin_mod' depends on \`$dep'"
96		rm -f $1
97		exit 1 ;;
98	esac
99    done
100    echo "    {"
101    echo "        extern int setup_${q_bin_mod} _((Module));"
102    echo "        extern int boot_${q_bin_mod} _((Module));"
103    echo "        extern int features_${q_bin_mod} _((Module,char***));"
104    echo "        extern int enables_${q_bin_mod} _((Module,int**));"
105    echo "        extern int cleanup_${q_bin_mod} _((Module));"
106    echo "        extern int finish_${q_bin_mod} _((Module));"
107    echo
108    echo "        register_module(\"$bin_mod\","
109    echo "                        setup_${q_bin_mod},"
110    echo "                        features_${q_bin_mod},"
111    echo "                        enables_${q_bin_mod},"
112    echo "                        boot_${q_bin_mod},"
113    echo "                        cleanup_${q_bin_mod}, finish_${q_bin_mod});"
114    echo "    }"
115    done_mods="$done_mods$bin_mod "
116done
117