OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.3 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-package/patch-copyright.sh
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2005 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. # must match [^-]*-COPYRIGHT-NOTE
  18. NOTEMARKER=SDE-COPYRIGHT-NOTE
  19. PROJECTNAME="The OpenSDE Project"
  20. copynote=`mktemp`
  21. copynotepatch=`mktemp`
  22. rocknote=`mktemp`
  23. oldfile=`mktemp`
  24. newfile=`mktemp`
  25. tmpfile=`mktemp`
  26. thisyear=`date +%Y`
  27. cat << EOT > $copynote
  28. This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  29. Filename: @@FILENAME@@
  30. @@COPYRIGHT@@
  31. More information can be found in the files COPYING and README.
  32. EOT
  33. cp $copynote $copynotepatch
  34. cat << EOT >> $copynote
  35. This program is free software; you can redistribute it and/or modify
  36. it under the terms of the GNU General Public License as published by
  37. the Free Software Foundation; version 2 of the License. A copy of the
  38. GNU General Public License can be found in the file COPYING.
  39. EOT
  40. cat << EOT >> $copynotepatch
  41. This patch file is dual-licensed. It is available under the license the
  42. patched project is licensed under, as long as it is an OpenSource license
  43. as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  44. of the GNU General Public License as published by the Free Software
  45. Foundation; either version 2 of the License, or (at your option) any later
  46. version.
  47. EOT
  48. if [ $# = 0 ]; then
  49. set lib/. architecture/. misc/. package/. scripts/. target/.
  50. else
  51. # check if file or package name was given
  52. files=""
  53. for i; do
  54. if [ -f $i -o -d $i ]; then
  55. files="$files ${i#./}"
  56. elif [ -d package/*/$i ]; then
  57. for each in `echo package/*/$i`; do
  58. [[ $each = *~ ]] && continue
  59. files="$files $each/."
  60. done
  61. else
  62. echo Cannot find \'$i\', ignoring. 1>&2
  63. fi
  64. done
  65. set -- $files
  66. [ $# = 0 ] && exit
  67. fi
  68. bash scripts/xfind.sh $* -type f ! -name "*~" \
  69. | sed 's,/\./,/,g' |
  70. while read filename ; do
  71. grep -q -e '--- NO-[^-]*-COPYRIGHT-NOTE ---' "$filename" &&
  72. continue
  73. # detect current copyright note tag
  74. tag=$( sed -n -e "/^\(.*\)--- \([^-]*\)-COPYRIGHT-NOTE-BEGIN ---.*/{s//\1/;p;q;}" "$filename" )
  75. pretag= posttag=
  76. has_copyright_note=1
  77. if [ "$tag" = "# " ]; then
  78. mode=sh
  79. elif [ "$tag" = "[COPY] " ]; then
  80. mode=asci
  81. elif [ "$tag" = " * " ]; then
  82. pretag='/*' posttag=' */'
  83. mode=c
  84. elif [ "$tag" = "dnl " ]; then
  85. mode=m4
  86. elif [ "$tag" = "-- " ]; then
  87. mode=lua
  88. elif [ -z "$tag" ]; then
  89. has_copyright_note=0
  90. # determine the comment mode by extension
  91. mode=none
  92. case "$filename" in
  93. *.cache) continue ;;
  94. */Makefile|*.sh|*.pl|*.in|*.hlp|*.conf) mode=sh ;;
  95. *.cron|*.postinstall|*.init) mode=sh ;;
  96. *.h|*.c|*.lex|*.y|*.spec|*.tcx|*.tmpl|*.tcc) mode=c ;;
  97. *.lua) mode=lua ;;
  98. *.desc) mode=asci ;;
  99. *scripts/[A-Z][a-z-]*|*/parse-config*) mode=sh ;;
  100. *.patch|*.diff|*.patch.*|*.patch-*) mode=sh ;;
  101. *m4) mode=m4 ;;
  102. *.awk) mode=sh ;;
  103. esac
  104. #echo "Mode type: $mode"
  105. case "$mode" in
  106. none) if head -n 1 "$filename" | grep -q '^#!'; then
  107. mode=sh
  108. tag="# "
  109. else
  110. echo "Unknown type of $filename"
  111. continue
  112. fi
  113. ;;
  114. sh) tag="# "
  115. ;;
  116. asci) tag="[COPY] "
  117. ;;
  118. m4) tag="dnl "
  119. ;;
  120. lua) tag="-- "
  121. ;;
  122. c) pretag='/*' posttag=' */'
  123. tag=' * '
  124. ;;
  125. *) echo "Unknown mode '$mode' of $filename"
  126. continue
  127. ;;
  128. esac
  129. else
  130. echo "Unknown tag '$tag' on $filename"
  131. continue
  132. fi
  133. # make a copy in the case we have no matching conditional below
  134. sed -e "s,--- \([^-]*\)-COPYRIGHT-NOTE-\(BEGIN\|END\) ---,--- $NOTEMARKER-\2 ---,g" \
  135. "$filename" > $oldfile
  136. if [ $has_copyright_note -eq 1 ]; then
  137. # has a note, catch copyrights
  138. oldcopyright=`sed -e "/--- $NOTEMARKER-BEGIN ---/,/--- $NOTEMARKER-END ---/!d" \
  139. -e '/.*\(Copyright (C) .*\)/!d;s//\1/;' \
  140. $oldfile`
  141. else
  142. oldcopyright=
  143. fi
  144. if echo "$oldcopyright" | grep -q "$PROJECTNAME"; then
  145. # A copyright note from our project was found, renew if necesary
  146. since=$( echo "$oldcopyright" | sed -n -e "s,.* (C) \([^ ]*\) .*$PROJECTNAME.*,\1,p" )
  147. if [ $since -lt $thisyear ]; then
  148. copyright=`echo "$oldcopyright" | sed -e \
  149. "s,.*$PROJECTNAME.*,Copyright (C) $since - $thisyear $PROJECTNAME,"`
  150. else
  151. copyright=`echo "$oldcopyright" | sed -e \
  152. "s,.*$PROJECTNAME.*,Copyright (C) $thisyear $PROJECTNAME,"`
  153. fi
  154. else
  155. # else, add one...
  156. copyright="Copyright (C) $thisyear $PROJECTNAME"
  157. copyright="$copyright${oldcopyright:+\\n$oldcopyright}"
  158. fi
  159. if [ $has_copyright_note -ne 1 ]; then
  160. # doesn't have a note
  161. if head -n 1 "$filename" | grep -q '^#!'; then
  162. action='a'
  163. else
  164. action='i'
  165. fi
  166. # insert one
  167. sed -i "1 $action\\
  168. ${pretag:+$pretag\\
  169. }$tag--- $NOTEMARKER-BEGIN ---\\
  170. $tag--- $NOTEMARKER-END ---\\
  171. ${posttag:+$posttag\\
  172. }" $oldfile
  173. fi
  174. mangled_filename=`echo "$filename" | \
  175. sed 's,package/\([^/]*\)/\(.*\),package/.../\2,'`
  176. #echo BEFORE
  177. #cat $oldfile
  178. if [ "$tag" ] ; then
  179. # implant our copy note
  180. {
  181. grep -B 100000 -- "--- $NOTEMARKER-BEGIN ---" $oldfile
  182. {
  183. if [ "$filename" != "${filename%/*.diff}" -o \
  184. "$filename" != "${filename%/*.patch}" -o \
  185. "$filename" != "${filename%/*.patch.*}" -o \
  186. "$filename" != "${filename%/*.patch-*}" ] ; then
  187. sed -e "s,@@FILENAME@@,$mangled_filename,; \
  188. s,@@COPYRIGHT@@,${copyright//
  189. /\n},;" $copynotepatch
  190. else
  191. sed -e "s,@@FILENAME@@,$mangled_filename,; \
  192. s,@@COPYRIGHT@@,${copyright//
  193. /\n},;" $copynote
  194. fi
  195. # we need a separated sed call because $rockcopyright adds a new line
  196. } | sed -e "s,^,$tag,"
  197. grep -A 100000 -- "--- $NOTEMARKER-END ---" $oldfile
  198. } > $newfile
  199. # create the difference
  200. if ! cmp -s $oldfile $newfile ; then
  201. echo "Creating patch for $filename." >&2
  202. diff -u "./$filename" $newfile |
  203. sed -e "2 s,$newfile,./$filename,"
  204. fi
  205. else
  206. echo "WARNING: No Copyright tags in $filename found!" >&2
  207. fi
  208. done
  209. rm -f $copynote $copynotepatch $newfile