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.

245 lines
6.2 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 - 2008 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/. package/. scripts/. bin/. 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. bin/find $* -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. *.txt) mode=sh ;;
  102. *m4) mode=m4 ;;
  103. *.awk) mode=sh ;;
  104. *.all|*.ask|*.choice) mode=sh ;;
  105. esac
  106. #echo "Mode type: $mode"
  107. case "$mode" in
  108. none) if head -n 1 "$filename" | grep -q '^#!'; then
  109. mode=sh
  110. tag="# "
  111. else
  112. echo "Unknown type of $filename" >&2
  113. continue
  114. fi
  115. ;;
  116. sh) tag="# "
  117. ;;
  118. asci) tag="[COPY] "
  119. ;;
  120. m4) tag="dnl "
  121. ;;
  122. lua) tag="-- "
  123. ;;
  124. c) pretag='/*' posttag=' */'
  125. tag=' * '
  126. ;;
  127. *) echo "Unknown mode '$mode' of $filename" >&2
  128. continue
  129. ;;
  130. esac
  131. else
  132. echo "Unknown tag '$tag' on $filename" >&2
  133. continue
  134. fi
  135. # make a copy in the case we have no matching conditional below
  136. sed -e "s,--- \([^-]*\)-COPYRIGHT-NOTE-\(BEGIN\|END\) ---,--- $NOTEMARKER-\2 ---,g" \
  137. "$filename" > $oldfile
  138. if [ $has_copyright_note -eq 1 ]; then
  139. # has a note, catch copyrights
  140. oldcopyright=`sed -e "/--- $NOTEMARKER-BEGIN ---/,/--- $NOTEMARKER-END ---/!d" \
  141. -e '/.*\(Copyright (C) .*\)/!d;s//\1/;' \
  142. $oldfile`
  143. else
  144. oldcopyright=
  145. fi
  146. if echo "$oldcopyright" | grep -q "$PROJECTNAME"; then
  147. # A copyright note from our project was found, renew if necesary
  148. since=$( echo "$oldcopyright" | sed -n -e "s,.* (C) \([^ ]*\) .*$PROJECTNAME.*,\1,p" )
  149. if [ $since -lt $thisyear ]; then
  150. copyright=`echo "$oldcopyright" | sed -e \
  151. "s,.*$PROJECTNAME.*,Copyright (C) $since - $thisyear $PROJECTNAME,"`
  152. else
  153. copyright=`echo "$oldcopyright" | sed -e \
  154. "s,.*$PROJECTNAME.*,Copyright (C) $thisyear $PROJECTNAME,"`
  155. fi
  156. else
  157. # else, add one...
  158. copyright="Copyright (C) $thisyear $PROJECTNAME"
  159. copyright="$copyright${oldcopyright:+\\n$oldcopyright}"
  160. fi
  161. if [ $has_copyright_note -ne 1 ]; then
  162. # doesn't have a note
  163. if head -n 1 "$filename" | grep -q '^#!'; then
  164. action='a'
  165. else
  166. action='i'
  167. fi
  168. # insert one
  169. sed -i "1 $action\\
  170. ${pretag:+$pretag\\
  171. }$tag--- $NOTEMARKER-BEGIN ---\\
  172. $tag--- $NOTEMARKER-END ---\\
  173. ${posttag:+$posttag\\
  174. }" $oldfile
  175. fi
  176. mangled_filename=`echo "$filename" | \
  177. sed 's,package/\([^/]*\)/\(.*\),package/.../\2,'`
  178. #echo BEFORE
  179. #cat $oldfile
  180. if [ "$tag" ] ; then
  181. # implant our copy note
  182. {
  183. grep -B 100000 -- "--- $NOTEMARKER-BEGIN ---" $oldfile
  184. {
  185. # what template to use
  186. case "$filename" in
  187. *.diff|*.patch|*.patch.*|*.patch-*)
  188. copyright_template="$copynotepatch"
  189. ;;
  190. *)
  191. copyright_template="$copynote"
  192. ;;
  193. esac
  194. copyright_n="$( echo "$copyright" | tr '\n' '|' | sed -e 's/|$//' | sed -e 's/|/\\n/g' )"
  195. sed -e "s|@@FILENAME@@|$mangled_filename|" \
  196. -e "s|@@COPYRIGHT@@|$copyright_n|" \
  197. "$copyright_template"
  198. } | sed -e "s,^,$tag," -e 's,[ \t]\+$,,'
  199. grep -A 100000 -- "--- $NOTEMARKER-END ---" $oldfile
  200. } > $newfile
  201. # create the difference
  202. if ! cmp -s $oldfile $newfile ; then
  203. echo "Creating patch for $filename." >&2
  204. diff -u "./$filename" $newfile |
  205. sed -e "2 s,$newfile,./$filename,"
  206. fi
  207. else
  208. echo "WARNING: No Copyright tags in $filename found!" >&2
  209. fi
  210. done
  211. rm -f $copynote $copynotepatch $newfile