fix_includes.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"
  87. echo -e "\n"
  88. echo "Using kernel headers from $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} for architecture '$TARGET_ARCH'"
  89. echo -e "\tprovided in directory $KERNEL_SOURCE"
  90. echo -e "\n"
  91. fi
  92. # Create a symlink to include/asm
  93. rm -f include/asm*
  94. if [ ! -d "$KERNEL_SOURCE/include/asm" ]; then
  95. echo "";
  96. echo "";
  97. echo "The symlink $KERNEL_SOURCE/include/asm is missing\!";
  98. echo "Perhaps you forgot to configure your kernel source?";
  99. echo "You really should configure your kernel source tree so I";
  100. echo "do not have to try and guess about this sort of thing.";
  101. echo ""
  102. echo "Attempting to guess a usable value....";
  103. echo ""
  104. echo "";
  105. sleep 1;
  106. if [ "$TARGET_ARCH" = "powerpc" ];then
  107. set -x;
  108. ln -fs $KERNEL_SOURCE/include/asm-ppc include/asm;
  109. set +x;
  110. elif [ "$TARGET_ARCH" = "mips" ];then
  111. set -x;
  112. ln -fs $KERNEL_SOURCE/include/asm-mips include/asm;
  113. set +x;
  114. elif [ "$TARGET_ARCH" = "arm" ];then
  115. set -x;
  116. ln -fs $KERNEL_SOURCE/include/asm-arm include/asm;
  117. set +x;
  118. if [ ! -L $KERNEL_SOURCE/include/asm-arm/proc ] ; then
  119. if [ ! -L proc ] ; then
  120. (cd include/asm;
  121. ln -fs proc-armv proc;
  122. ln -fs arch-ebsa285 arch);
  123. fi
  124. fi;
  125. elif [ "$TARGET_ARCH" = "cris" ]; then
  126. set -x;
  127. ln -fs $KERNEL_SOURCE/include/asm-cris include/asm;
  128. set +x;
  129. elif [ "$HAS_MMU" != "y" ]; then
  130. if [ -d $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu ] ; then
  131. set -x;
  132. ln -fs $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu include/asm;
  133. set +x;
  134. else
  135. set -x;
  136. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm;
  137. set +x;
  138. fi;
  139. else
  140. set -x;
  141. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm;
  142. set +x;
  143. fi;
  144. else
  145. # No guessing required.....
  146. ln -fs $KERNEL_SOURCE/include/asm include/asm
  147. if [ -e $KERNEL_SOURCE/include/asm-$TARGET_ARCH ] ; then
  148. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm-$TARGET_ARCH
  149. fi
  150. fi;
  151. # Annoyingly, 2.6.x kernel headers also need an include/asm-generic/ directory
  152. if [ $VERSION -eq 2 ] && [ $PATCHLEVEL -ge 6 ] ; then
  153. ln -fs $KERNEL_SOURCE/include/asm-generic include/asm-generic
  154. fi;
  155. # Create the include/linux symlink.
  156. rm -f include/linux
  157. ln -fs $KERNEL_SOURCE/include/linux include/linux