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.

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