fix_includes.sh 3.9 KB

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