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.

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