fix_includes.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/sh
  2. # Copyright (C) 2003 Erik Andersen <andersen@uclibc.org>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later
  8. # version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Library General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Library General
  16. # Public License along with this program; if not, write to the
  17. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. # Boston, MA 02111-1307 USA
  19. usage () {
  20. echo ""
  21. echo "usage: "`basename $0`" -k KERNEL_SOURCE_DIRECTORY -t TARGET_ARCH"
  22. echo ""
  23. echo "This utility scans the KERNEL_SOURCE_DIRECTORY directory and"
  24. echo "checks that it contains well formed kernel headers suitable"
  25. echo "for inclusion as the include/linux/ directory provided by"
  26. echo "uClibc."
  27. echo ""
  28. echo "If the specified kernel headers are present and already"
  29. echo "configured for the architecture specified by TARGET_ARCH,"
  30. echo "they will be used as-is."
  31. echo ""
  32. echo "If the specified kernel headers are missing entirely, this"
  33. echo "script will return an error."
  34. echo ""
  35. echo "If the specified kernel headers are present, but are either"
  36. echo "not yet configured or are configured for an architecture"
  37. echo "different than that specified by TARGET_ARCH, this script"
  38. echo "will attempt to 'fix' the kernel headers and make them"
  39. echo "suitable for use by uClibc. This fixing process may fail."
  40. echo "It is therefore best to always provide kernel headers that"
  41. echo "are already configured for the selected architecture."
  42. echo ""
  43. echo "Most Linux distributions provide 'kernel-headers' packages"
  44. echo "that are suitable for use by uClibc."
  45. echo ""
  46. echo ""
  47. exit 1;
  48. }
  49. HAS_MMU="y";
  50. while [ -n "$1" ]; do
  51. case $1 in
  52. -k ) shift; if [ -n "$1" ]; then KERNEL_SOURCE=$1; shift; else usage; fi; ;;
  53. -t ) shift; if [ -n "$1" ]; then TARGET_ARCH=$1; shift; else usage; fi; ;;
  54. -n ) shift; HAS_MMU="n"; ;;
  55. -* ) usage; ;;
  56. * ) usage; ;;
  57. esac;
  58. done;
  59. if [ ! -f "$KERNEL_SOURCE/Makefile" -a ! -f "$KERNEL_SOURCE/include/linux/version.h" ]; then
  60. echo "";
  61. echo "";
  62. echo "The file $KERNEL_SOURCE/Makefile or $KERNEL_SOURCE/include/linux/version.h is missing!";
  63. echo "Perhaps your kernel source is broken?"
  64. echo "";
  65. echo "";
  66. exit 1;
  67. fi;
  68. if [ ! -d "$KERNEL_SOURCE" ]; then
  69. echo "";
  70. echo "";
  71. echo "$KERNEL_SOURCE is not a directory";
  72. echo "";
  73. echo "";
  74. exit 1;
  75. fi;
  76. if [ -f "$KERNEL_SOURCE/Makefile" ] ; then
  77. # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
  78. eval `sed -n -e 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' -e 's/^\([A-Z]*\) = \(-[-a-z0-9]*\)$/\1=\2/p' $KERNEL_SOURCE/Makefile`
  79. else
  80. ver=`grep UTS_RELEASE $KERNEL_SOURCE/include/linux/version.h | cut -d '"' -f 2`
  81. VERSION=`echo "$ver" | cut -d '.' -f 1`
  82. PATCHLEVEL=`echo "$ver" | cut -d '.' -f 2`
  83. if echo "$ver" | grep -q '-' ; then
  84. SUBLEVEL=`echo "$ver" | sed "s/${VERSION}.${PATCHLEVEL}.//" | cut -d '-' -f 1`
  85. EXTRAVERSION=`echo "$ver" | sed "s/${VERSION}.${PATCHLEVEL}.${SUBLEVEL}-//"`
  86. else
  87. SUBLEVEL=`echo "$ver" | cut -d '.' -f 3`
  88. #EXTRAVERSION=
  89. fi
  90. fi
  91. if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
  92. then
  93. echo "Unable to determine version for kernel headers"
  94. echo -e "\tprovided in directory $KERNEL_SOURCE"
  95. exit 1
  96. fi
  97. if [ "$MAKE_IS_SILENT" != "y" ]; then
  98. echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"
  99. echo -e "\n"
  100. echo "Using kernel headers from $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} for architecture '$TARGET_ARCH'"
  101. echo -e "\tprovided in directory $KERNEL_SOURCE"
  102. echo -e "\n"
  103. fi
  104. # Create a symlink to include/asm
  105. rm -f include/asm*
  106. if [ ! -d "$KERNEL_SOURCE/include/asm" ]; then
  107. echo "";
  108. echo "";
  109. echo "The symlink $KERNEL_SOURCE/include/asm is missing\!";
  110. echo "Perhaps you forgot to configure your kernel source?";
  111. echo "You really should configure your kernel source tree so I";
  112. echo "do not have to try and guess about this sort of thing.";
  113. echo ""
  114. echo "Attempting to guess a usable value....";
  115. echo ""
  116. echo "";
  117. sleep 1;
  118. if [ "$TARGET_ARCH" = "powerpc" ];then
  119. set -x;
  120. ln -fs $KERNEL_SOURCE/include/asm-ppc include/asm;
  121. set +x;
  122. elif [ "$TARGET_ARCH" = "mips" ];then
  123. set -x;
  124. ln -fs $KERNEL_SOURCE/include/asm-mips include/asm;
  125. set +x;
  126. elif [ "$TARGET_ARCH" = "arm" ];then
  127. set -x;
  128. ln -fs $KERNEL_SOURCE/include/asm-arm include/asm;
  129. set +x;
  130. if [ ! -L $KERNEL_SOURCE/include/asm-arm/proc ] ; then
  131. if [ ! -L proc ] ; then
  132. (cd include/asm;
  133. ln -fs proc-armv proc;
  134. ln -fs arch-ebsa285 arch);
  135. fi
  136. fi;
  137. elif [ "$TARGET_ARCH" = "cris" ]; then
  138. set -x;
  139. ln -fs $KERNEL_SOURCE/include/asm-cris include/asm;
  140. set +x;
  141. elif [ "$HAS_MMU" != "y" ]; then
  142. if [ -d $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu ] ; then
  143. set -x;
  144. ln -fs $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu include/asm;
  145. set +x;
  146. else
  147. set -x;
  148. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm;
  149. set +x;
  150. fi;
  151. else
  152. set -x;
  153. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm;
  154. set +x;
  155. fi;
  156. else
  157. # No guessing required.....
  158. ln -fs $KERNEL_SOURCE/include/asm include/asm
  159. if [ -e $KERNEL_SOURCE/include/asm-$TARGET_ARCH ] ; then
  160. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm-$TARGET_ARCH
  161. fi
  162. fi;
  163. # Annoyingly, 2.6.x kernel headers also need an include/asm-generic/ directory
  164. if [ $VERSION -eq 2 ] && [ $PATCHLEVEL -ge 6 ] ; then
  165. ln -fs $KERNEL_SOURCE/include/asm-generic include/asm-generic
  166. fi;
  167. # Create the include/linux symlink.
  168. rm -f include/linux
  169. ln -fs $KERNEL_SOURCE/include/linux include/linux