Updated PCI IDs to latest snapshot.
[tangerine.git] / tools / fd2inline / cross / bin / gg-fix-includes.in
blob1825db87af02a2cb1927afbaa6469bb01f3b244c
1 #!/bin/sh
3 prefix=@prefix@
4 exec_prefix=@exec_prefix@
5 bindir=@bindir@
6 datadir=@datadir@
7 fd2inlinedir=${datadir}/fd2inline
8 FD2INLINE=${bindir}/fd2inline
9 SPLITASM="awk -f ${fd2inlinedir}/splitasm.awk"
11 ERROR="\e[31m"
12 INFO="\e[32m"
13 NORMAL="\e[0m"
15 if [ $# -eq 1 ]; then
16 case "$1" in
17 --include)
18 STUBS=no
20 --lib)
21 STUBS=yes
23 esac
26 if [ -z "$STUBS" ]; then
27 echo "Usage: $0 [--include] [--lib]"
28 exit
31 if [ "${STUBS}" = "yes" ]; then
32 build_dir=`mktemp -qd /tmp/gg-fix-includes.XXXXXX`
34 if [ -z "${build_dir}" ]; then
35 echo "Error: Unable to create temporary directory."
36 exit
40 for gcc in ${bindir}/*-*-gcc; do
41 target=`echo "${gcc}" | sed -e "s,.*/\(.*\)-gcc,\1,"`
43 if test -d ${prefix}/${target}; then
44 case "${target}" in
45 i?86be-amithlon)
46 CC="${target}-gcc -Os -fomit-frame-pointer"
47 AS="${target}-as"
48 AR="${target}-ar"
49 FD2INLINE_OS="ix86be-amithlon"
50 FIXINCLUDE="perl ${fd2inlinedir}/geninclude.pl"
52 m68k-amigaos)
53 CC="${target}-gcc -Os -fomit-frame-pointer"
54 AS="${target}-as"
55 AR="${target}-ar"
56 FD2INLINE_OS="${target}"
57 FIXINCLUDE="cat"
59 ppc-morphos)
60 CC="${target}-gcc -Os -fomit-frame-pointer"
61 AS="${target}-as"
62 AR="${target}-ar"
63 FD2INLINE_OS="${target}"
64 FIXINCLUDE="perl ${fd2inlinedir}/geninclude.pl"
67 FD2INLINE_OS="X"
69 esac
71 echo -e "${ERROR}"
73 if test "$FD2INLINE_OS" == "X"; then
74 echo -e "${target}: Unsupported target."
75 else
77 echo -e "${INFO}*** Target ${target}${ERROR}"
79 if [ "${STUBS}" = "no" ]; then
80 rm -r ${prefix}/${target}/sys-include
81 echo "The sys-include directory is automatically generated. Do no edit!" > ${prefix}/${target}/sys-include.readme
82 mkdir ${prefix}/${target}/sys-include
83 mkdir ${prefix}/${target}/sys-include/inline
84 mkdir ${prefix}/${target}/sys-include/proto
85 else
86 rm ${prefix}/${target}/lib/libamigastubs.a
87 fi;
89 for fd_dir in ${prefix}/os-lib/fd/*; do
90 package=`echo "${fd_dir}" | sed -e "s,.*/,,"`
92 if test -d ${fd_dir}; then
93 echo -e "${INFO} *** Package ${package}${ERROR}"
95 if [ "${STUBS}" = "no" ]; then
96 echo -e "${INFO} *** Patching and installing header files${ERROR}"
98 for dir in `cd ${prefix}/os-include/${package} &&
99 find * -type d \
100 -and -not -ipath "ppcinline*" \
101 -and -not -ipath "ppcpragma*" \
102 -and -not -ipath "ppcproto*" \
103 -and -not -ipath "inline*" \
104 -and -not -ipath "pragma*" \
105 -and -not -ipath "proto*"`; do
106 test -d ${prefix}/${target}/sys-include/${dir} || \
107 mkdir ${prefix}/${target}/sys-include/${dir}
108 done
110 for header in `cd ${prefix}/os-include/${package} &&
111 find * -iname "*.h" -and -type f \
112 -and -not -ipath "ppcinline*" \
113 -and -not -ipath "ppcpragma*" \
114 -and -not -ipath "ppcproto*" \
115 -and -not -ipath "inline*" \
116 -and -not -ipath "pragma*" \
117 -and -not -ipath "proto*"`; do
118 echo -ne "${NORMAL}[${header}] ${ERROR}"
119 ${FIXINCLUDE} ${prefix}/os-include/${package}/${header} \
120 > ${prefix}/${target}/sys-include/${header}
121 done
123 echo; echo
124 echo -e "${INFO} *** Generating inlines and proto files${ERROR}"
126 for fd in ${fd_dir}/*_*.[Ff][Dd]; do
127 base=`echo "${fd}" | sed -e "s,${fd_dir}/\(.*\)_\(.*\)\...,\1,"`
128 clib="${prefix}/os-include/${package}/clib/${base}_protos.h"
130 if test ! -r ${clib}; then
131 echo "Warning: ${clib} is missing."
132 else
133 echo -ne "${NORMAL}[${base}] ${ERROR}"
134 ${FD2INLINE} --quiet --new --target=${FD2INLINE_OS} ${fd} ${clib} \
135 -o ${prefix}/${target}/sys-include/inline/${base}.h
137 ${FD2INLINE} --quiet --proto --target=${FD2INLINE_OS} ${fd} \
138 -o ${prefix}/${target}/sys-include/proto/${base}.h
140 done
142 cp ${fd2inlinedir}/stubs.h ${fd2inlinedir}/${FD2INLINE_OS}/* \
143 ${prefix}/${target}/sys-include/inline/
145 else
146 echo; echo
147 echo -e "${INFO} *** Generating stub libraries${ERROR}"
149 # Note that we cannot compile the stubs until inlines and prototypes
150 # has been generated!
152 for fd in ${fd_dir}/*_*.[Ff][Dd]; do
153 base=`echo "${fd}" | sed -e "s,${fd_dir}/\(.*\)_\(.*\)\...,\1,"`
154 clib="${prefix}/os-include/${package}/clib/${base}_protos.h"
156 if test ! -r ${clib}; then
157 echo "Warning: ${clib} is missing."
158 else
159 echo -ne "${NORMAL}[${base}] ${ERROR}"
160 ${FD2INLINE} --quiet --stubs --target=${FD2INLINE_OS} ${fd} ${clib} \
161 -o ${build_dir}/-stubs.c
163 ${CC} -D__CLIB_TYPES__ -S ${build_dir}/-stubs.c \
164 -o ${build_dir}/-stubs.s || exit
166 ${SPLITASM} -v dest=${build_dir} ${build_dir}/-stubs.s
168 done
171 echo; echo
173 done
175 if [ "${STUBS}" = "yes" ]; then
176 rm ${build_dir}/-stubs.s ${build_dir}/-stubs.c
178 echo -e "${INFO} *** Assembling files${ERROR}"
180 for stub in ${build_dir}/*.s; do
181 base=`basename ${stub} .s`
182 ${AS} $stub -o ${build_dir}/${base}.o
183 rm $stub
184 echo -ne "${NORMAL}[${base}] ${ERROR}"
185 done
187 echo; echo
189 # This line can get pretty long, so we get rid of the path at least ...
190 ( cd ${build_dir} && ${AR} -rs ${prefix}/${target}/lib/libamigastubs.a *.o; \
191 rm *.o )
195 done
197 if [ "${STUBS}" = "yes" ]; then
198 rmdir ${build_dir}
201 echo -e "${INFO}Done!${NORMAL}"