Advertisement
Guest User

spec2bb for KDE

a guest
Apr 3rd, 2013
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # only handles program usage and parameter checking
  4. ##source `dirname $0`/spec2bb.inc
  5.  
  6.  ### @b this could be done by parsing the kde yaml files in the meego OBS, but not all rpm builders seem to use yaml files
  7. function packages()
  8. {
  9.     echo -e 'PACKAGES=+"\\' >> ${OUTFILE}
  10.  
  11.     grep "%package" ${SPECFILE}  |
  12.         sort |
  13.         sed 's/.*\ //' | #1. remove everything until after the first whitespace (crops %packages and -n or other options)
  14.         sed ':a;N;$!ba;s/\n/ \\\n/g' | #2. replace newlines with "\\\n" see http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n
  15.         sed 's/^/${PN}-/' | #3. add '${PN}-' before the package name
  16.         sed '$s/$/ \\\n"/' >> ${OUTFILE} #4.replaces the last newline with '"' see http://unix.stackexchange.com/questions/20573/sed-insert-something-to-the-last-line
  17. }
  18.  
  19. function packagefiles()
  20. {
  21.     cat ${SPECFILE} | # Caution: do not sort $SPECFILE!
  22.         sed -n -e '/%files/,$p' | #1. print everything after the first '%files'
  23.         sed 's/%\(files\|defattr\|doc\|config\|dir\ \|verify\).*//' | #2. replace '%files', '%defattr', '%doc', '%config', '%dir' and '%verify' + the rest of the line with ''
  24.         sed '/^$/d' | #3. remove multiple newlines after removing the precvious entries
  25.         sed 's/# >> files\ */FILES_$\{PN\}-/' | #4. replace '# >> files' with 'FILES_${PN}-' (truncates spaces until next character)
  26.         sed ':a;N;$!ba;s/\n%/ \\\n/g' | #5. add ' \' after line ends which are followed by '%' next line
  27.         sed ':a;N;$!ba;s/\n#/ \\\n#/g' | #6. add ' \' after line ends which are followed by '#' on the next line
  28.         sed 's/# << files.*/"/' | #7. replace '# << files' and the rest of the line with '"'
  29.         sed 's/\(FILES_.*\S\)\s/\1=" /' | #8. add '=" ' after FILES_.*
  30.         sed 's/^#.*//' | #9. replace leftover comment lines (starting with '#')
  31.         sed '/^$/d' | #10. remove multiple newlines created at comment removal
  32.         sed 's/\(FILES_.*\S\)\s/\n\1/' | #11. add newlines before 'FILES_.*'
  33.         sed 's/FILES_${PN}-="\\/FILES_${PN}+="\\/' >> ${OUTFILE} #12. replace 'FILES_${PN}-="\' with FILES_${PN}+="\'
  34. }
  35.  
  36. function kdepaths()
  37. {
  38.     # post process the outfile to replace kde paths with bitbake paths
  39.     touch ${OUTFILE}-tmp$$
  40.     cat ${OUTFILE} |
  41.         sed 's#{_datadir}#${datadir}#' | # not kde specific
  42.         sed 's#{_kde_applicationsdir}#${datadir}/applications/kde4#' |
  43.         sed 's#{_kde_appsdir}#${datadir}/apps#' |
  44.         sed 's#{_kde_bindir}#${bindir}#' |
  45.         sed 's#{_kde_configdir}#${datadir}/config#' |
  46.         sed 's#{_kde_configkcfgdir}#${datadir}/config.kcfg#' |
  47.         sed 's#{_kde_docdir}#${datadir}/doc/kde#' |
  48.         sed 's#{_kde_htmldir}#${datadir}/doc/kde/HTML#' |
  49.         sed 's#{_kde_iconsdir}#${datadir}/icons#' |
  50.         sed 's#{_kde_includedir}#${includedir}#' |
  51.         sed 's#{_kde_libdir}#${libdir}#' |
  52.         sed 's#{_kde_libexecdir}#${libdir}/kde4/libexec#' |
  53.         sed 's#{_kde_libkdeinitdir}#${libdir}/kde4/libkdeinit#' |
  54.         sed 's/{_kde_mandir}/# FIXME: /' | # man files go to the ${PN}-doc package, not to individual subpackages
  55.         sed 's#{_kde_modulesdir}#${libdir}/kde4#' |
  56.         sed 's#{_kde_prefix}#${prefix}#' |
  57.         sed 's#{_kde_sbindir}#${sbindir}#' |
  58.         sed 's#{_kde_servicesdir}#${datadir}/services#' |
  59.         sed 's#{_kde_servicetypesdir}#${datadir}/servicetypes#' |
  60.         sed 's#{_kde_sharedir}#${datadir}/kde4#' |
  61.         sed 's#{_kde_sysconfdir}#${sysconfdir}#' |
  62.         sed 's#{_kde_wallpapersdir}#${datadir}/wallpapers#' > ${OUTFILE}-tmp$$
  63.     rm ${OUTFILE}
  64.     mv ${OUTFILE}-tmp$$ ${OUTFILE}
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. if [ -s ${OUTFILE} ]
  72. then
  73.     echo "outfile already exists"
  74.     exit 1
  75. fi
  76.  
  77. touch ${OUTFILE}
  78.  
  79.  
  80. packages
  81. if [ -z ${PKGFILES} ]
  82. then
  83.     packagefiles
  84. fi
  85.  
  86. kdepaths
  87.  
  88. if [ ${OUTFILE}="$$tmpfile.~" ]
  89. then
  90.     cat "$$tmpfile.~"
  91.     rm "$$tmpfile.~"
  92. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement