fix_includes.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #
  38. # Parse our arguments
  39. #
  40. HAS_MMU="y"
  41. KERNEL_SOURCE=""
  42. TARGET_ARCH=""
  43. while [ -n "$1" ]; do
  44. case $1 in
  45. -k ) shift; if [ -n "$1" ]; then KERNEL_SOURCE=$1; shift; else usage; fi; ;;
  46. -t ) shift; if [ -n "$1" ]; then TARGET_ARCH=$1; shift; else usage; fi; ;;
  47. -n ) shift; HAS_MMU="n"; ;;
  48. -* ) usage; ;;
  49. * ) usage; ;;
  50. esac
  51. done
  52. #
  53. # Perform some sanity checks on our kernel sources
  54. #
  55. if [ ! -f "$KERNEL_SOURCE/Makefile" -a ! -f "$KERNEL_SOURCE/include/linux/version.h" ]; then
  56. echo ""
  57. echo ""
  58. echo "The file $KERNEL_SOURCE/Makefile or $KERNEL_SOURCE/include/linux/version.h is missing!"
  59. echo "Perhaps your kernel source is broken?"
  60. echo ""
  61. echo ""
  62. exit 1
  63. fi
  64. if [ ! -d "$KERNEL_SOURCE" ]; then
  65. echo ""
  66. echo ""
  67. echo "$KERNEL_SOURCE is not a directory"
  68. echo ""
  69. echo ""
  70. exit 1
  71. fi
  72. #
  73. # Create a symlink to include/asm
  74. #
  75. rm -f include/asm*
  76. if [ ! -d "$KERNEL_SOURCE/include/asm" ]; then
  77. echo ""
  78. echo ""
  79. echo "The symlink $KERNEL_SOURCE/include/asm is missing\!"
  80. echo "Perhaps you forgot to configure your kernel source?"
  81. echo "You really should configure your kernel source tree so I"
  82. echo "do not have to try and guess about this sort of thing."
  83. echo ""
  84. echo "Attempting to guess a usable value...."
  85. echo ""
  86. echo ""
  87. sleep 1
  88. if [ "$TARGET_ARCH" = "powerpc" ]; then
  89. set -x
  90. ln -fs $KERNEL_SOURCE/include/asm-ppc include/asm
  91. set +x
  92. elif [ "$TARGET_ARCH" = "mips" ]; then
  93. set -x
  94. ln -fs $KERNEL_SOURCE/include/asm-mips include/asm
  95. set +x
  96. elif [ "$TARGET_ARCH" = "arm" ]; then
  97. set -x
  98. ln -fs $KERNEL_SOURCE/include/asm-arm include/asm
  99. set +x
  100. if [ ! -L $KERNEL_SOURCE/include/asm-arm/proc ]; then
  101. if [ ! -L proc ]; then
  102. (
  103. cd include/asm
  104. ln -fs proc-armv proc
  105. ln -fs arch-ebsa285 arch
  106. )
  107. fi
  108. fi
  109. elif [ "$TARGET_ARCH" = "cris" ]; then
  110. set -x
  111. ln -fs $KERNEL_SOURCE/include/asm-cris include/asm
  112. set +x
  113. elif [ "$HAS_MMU" != "y" ]; then
  114. if [ -d $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu ]; then
  115. set -x
  116. ln -fs $KERNEL_SOURCE/include/asm-${TARGET_ARCH}nommu include/asm
  117. set +x
  118. else
  119. set -x
  120. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm
  121. set +x
  122. fi
  123. else
  124. set -x
  125. ln -fs $KERNEL_SOURCE/include/asm-$TARGET_ARCH include/asm
  126. set +x
  127. fi;
  128. else
  129. # No guessing required.....
  130. for x in $KERNEL_SOURCE/include/asm* ; do
  131. ln -fs ${x} include/
  132. done
  133. fi
  134. #
  135. # Annoyingly, 2.6.x kernel headers also need an include/asm-generic/ directory
  136. #
  137. if [ -e $KERNEL_SOURCE/include/asm-generic ]; then
  138. rm -f include/asm-generic
  139. ln -fs $KERNEL_SOURCE/include/asm-generic include/asm-generic
  140. fi
  141. #
  142. # Create the include/linux symlink.
  143. #
  144. rm -f include/linux
  145. ln -fs $KERNEL_SOURCE/include/linux include/linux