fix_includes.sh 5.3 KB

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