Advertisement
Guest User

ebuild

a guest
Feb 7th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.15 KB | None | 0 0
  1. #!/bin/bash -e
  2.  
  3. # attempts to cd to the root dir of the project
  4. function go_to_project_root {
  5.     while : ; do
  6.         if [ ! -e "CMakeLists.txt" ]; then
  7.             cd ..
  8.             if [ "$(pwd)" == "/" ]; then
  9.                 echoerr "No CMakeLists.txt found! Are you in one of the project's directories?"
  10.                 exit 1
  11.             fi
  12.         else
  13.             break;
  14.         fi
  15.     done
  16. }
  17.  
  18. function echoerr {
  19.     echo -e "\e[00;31m[Error] $@\e[00m" 1>&2
  20. }
  21. function echostat {
  22.     echo -e "\e[00;32m[Status] $@\e[00m"
  23. }
  24. function echoinfo {
  25.     echo -e "\e[00;34m[Info] $@\e[00m"
  26. }
  27.  
  28. function usage {
  29.     echo -e "Usage: ebuild <command> [parameter]
  30.  
  31. Commands:
  32.  build - Builds the project belonging to the current diretory
  33.  new - Launches the project creation wizard
  34.  addpackage <package> - Adds a package to the project. Check CMakeLists.txt's top for a list of the ones currently used
  35.  commit <message> [fixes] - Commits a revision with message to the bzr branch. If fixes is specified, the commit is marked to fix the bug with this number
  36.  push [branch] - Pushes the bzr branch to branch and sets branch as default location. If no branch is specified, attempt to push to default
  37.  addfile <file> - Adds file to the project
  38.  removefile <file> - Removes file from the project
  39.  clean - Removes build directory, sometimes required to have new packages used correctly
  40.  
  41. If no command is given, 'build' will be used
  42. "
  43.     exit 0
  44. }
  45.  
  46. echostat "Welcome to ebuild!"
  47.  
  48. case "$1" in
  49. "new")
  50.     echo "Enter the project's name:"
  51.     read FULLNAME
  52.  
  53.     echo "Enter its description:"
  54.     read DESC
  55.  
  56.     echo "Enter the authors in the form 'Author Name <author@email>, Author2 Name2 <author2@email.com>' (without quotes):"
  57.     read AUTH
  58.  
  59.     echo "Enter an icon name, if none is given application-default is used:"
  60.     read ICON
  61.     if [ "$ICON" == "" ]; then
  62.         ICON="application-default"
  63.     fi
  64.  
  65.     echo "Enter a generic name for the app (e.g. MusicPlayer for Noise):"
  66.     read GENNAME
  67.     # make it lowercase and put a dash where a whitespace was
  68.     NAME=$(echo "$FULLNAME" | tr '[A-Z] ' '[a-z]-')
  69.     NAMESPACE=$(echo "$FULLNAME" | tr -d ' ')
  70.     YEAR=$(date +%Y)
  71.  
  72.     echoinfo "To edit these values later, see data/$NAME.desktop"
  73.  
  74.     mkdir $NAME
  75.     cd $NAME
  76.  
  77.     # get the newest cmake modules
  78.     echostat "Getting latest cmake modules ..."
  79.     bzr branch lp:~elementary-apps/+junk/cmake-modules
  80.     mv cmake-modules/cmake/ .
  81.     rm -r cmake-modules
  82.  
  83.     # our main CMakeLists.txt
  84.     echostat "Generating project files ..."
  85.     echo "
  86. set (NAME $NAME)
  87. set (PACKAGES granite)
  88. set (FILES src/$NAMESPACE.vala)
  89.  
  90.  
  91. project (\${NAME})
  92. cmake_minimum_required (VERSION 2.8)
  93. cmake_policy (VERSION 2.6)
  94.  
  95. list (APPEND CMAKE_MODULE_PATH \${CMAKE_SOURCE_DIR}/cmake/vala)
  96.  
  97. set (CMAKE_INSTALL_PREFIX /usr)
  98.  
  99. enable_testing ()
  100.  
  101. set (DATADIR \"\${CMAKE_INSTALL_PREFIX}/share\")
  102. set (PKGDATADIR \"\${DATADIR}/${NAME}\")
  103. set (GETTEXT_PACKAGE \"\${NAME}\")
  104. set (VERSION \"0.1\")
  105.  
  106. list (APPEND CMAKE_MODULE_PATH \${CMAKE_SOURCE_DIR}/cmake)
  107.  
  108. configure_file (\${CMAKE_SOURCE_DIR}/src/Config.vala.cmake \${CMAKE_BINARY_DIR}/src/Config.vala)
  109. add_definitions(-DGETTEXT_PACKAGE=\\\"\${GETTEXT_PACKAGE}\\\")
  110.  
  111. find_package(PkgConfig)
  112. pkg_check_modules(DEPS REQUIRED \${PACKAGES})
  113.  
  114. add_definitions (\${DEPS_CFLAGS})
  115. link_libraries (\${DEPS_LIBRARIES})
  116. link_directories (\${DEPS_LIBRARY_DIRS})
  117.  
  118. find_package (Vala REQUIRED)
  119. include (ValaVersion)
  120. ensure_vala_version ("0.16.0" MINIMUM)
  121.  
  122. include (ValaPrecompile)
  123. vala_precompile (VALA_C \${NAME}
  124.     \${FILES}
  125.     \${CMAKE_BINARY_DIR}/src/Config.vala
  126. PACKAGES
  127.     \${PACKAGES}
  128. OPTIONS
  129.     \${VALAFLAGS}
  130. )
  131.  
  132. add_subdirectory (po)
  133.  
  134. include (GSettings)
  135. add_schema ("data/org.pantheon.$NAME.gschema.xml")
  136.  
  137. add_executable (\${NAME} \${VALA_C})
  138.  
  139. install (TARGETS \${NAME} RUNTIME DESTINATION bin)
  140. install (FILES \${CMAKE_CURRENT_SOURCE_DIR}/data/\${NAME}.desktop DESTINATION share/applications)
  141. " > CMakeLists.txt
  142.  
  143.     # the desktop and the gschema file
  144.     mkdir data
  145.     cd data
  146.     echo "[Desktop Entry]
  147. Type=Application
  148. Name=$FULLNAME
  149. Comment=$DESC
  150. GenericName=$GENNAME
  151. Exec=$NAME
  152. Icon=$ICON
  153. Terminal=false
  154. Categories=Utility;
  155. " > $NAME.desktop
  156.  
  157.     echo "
  158. <?xml version=\"1.0\" encoding=\"UTF-8\"?>
  159. <schemalist>
  160.     <schema path=\"/org/pantheon/$NAME/\" id=\"org.pantheon.$NAME\" gettext-domain=\"$NAME\">
  161.     </schema>
  162. </schemalist>
  163. " > org.pantheon.$NAME.gschema.xml
  164.     cd ..
  165.  
  166.     # l10n
  167.     mkdir po
  168.     cd po
  169.     echo "include (Translations)
  170. add_translations_directory (\"$NAME\")
  171. add_translations_catalog (\"$NAME\"
  172.     ../src
  173.     ../src/Widgets
  174. )
  175. " > CMakeLists.txt
  176.     cd ..
  177.  
  178.     # src
  179.     mkdir src
  180.     cd src
  181.     echo "/***
  182.  BEGIN LICENSE
  183.  
  184.  Copyright (C) $YEAR $AUTH
  185.  This program is free software: you can redistribute it and/or modify it
  186.  under the terms of the GNU Lesser General Public License version 3, as
  187.  published    by the Free Software Foundation.
  188.  
  189.  This program is distributed in the hope that it will be useful, but
  190.  WITHOUT ANY WARRANTY; without even the implied warranties of
  191.  MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
  192.  PURPOSE.  See the GNU General Public License for more details.
  193.  
  194.  You should have received a copy of the GNU General Public License along
  195.  with this program.  If not, see <http://www.gnu.org/licenses>
  196.  
  197.  END LICENSE
  198. ***/
  199.  
  200. namespace $NAMESPACE
  201. {
  202.     public class App : Granite.Application
  203.     {
  204.         construct
  205.         {
  206.             program_name = \"$FULLNAME\";
  207.             exec_name = \"$NAME\";
  208.  
  209.             app_years = \"$YEAR\";
  210.             application_id = \"net.launchpad.$NAME\";
  211.             app_icon = \"$ICON\";
  212.             app_launcher = \"$NAME.desktop\";
  213.  
  214.             main_url = \"https://code.launchpad.net/$NAME\";
  215.             bug_url = \"https://bugs.launchpad.net/$NAME\";
  216.             help_url = \"https://code.launchpad.net/$NAME\";
  217.             translate_url = \"https://translations.launchpad.net/$NAME\";
  218.  
  219.             about_authors = {\"$AUTH\"};
  220.             about_documenters = {\"$AUTH\"};
  221.             about_artists = {\"$AUTH\"};
  222.             about_comments = \"$DESC\";
  223.             about_translators = \"\";
  224.             about_license_type = Gtk.License.GPL_3_0;
  225.         }
  226.  
  227.         public App ()
  228.         {
  229.         }
  230.  
  231.         public override void activate ()
  232.         {
  233.             var window = new Gtk.ApplicationWindow (this);
  234.             window.window_position = Gtk.WindowPosition.CENTER;
  235.             window.set_default_size (640, 480);
  236.             window.show_all ();
  237.         }
  238.     }
  239. }
  240.  
  241. public static int main (string [] args)
  242. {
  243.     Gtk.init (ref args);
  244.  
  245.     return new $NAMESPACE.App ().run (args);
  246. }
  247.     " > $NAMESPACE.vala
  248.     echo "
  249. namespace Constants {
  250.     public const string DATADIR = \"@DATADIR@\";
  251.     public const string PKGDATADIR = \"@PKGDATADIR@\";
  252.     public const string GETTEXT_PACKAGE = \"@GETTEXT_PACKAGE@\";
  253.     public const string RELEASE_NAME = \"@RELEASE_NAME@\";
  254.     public const string VERSION = \"@VERSION@\";
  255.     public const string VERSION_INFO = \"@VERSION_INFO@\";
  256.     public const string PLUGINDIR = \"@PLUGINDIR@\";
  257. }" > Config.vala.cmake
  258.  
  259.     cd ..
  260.  
  261.     echostat "Intializing bazaar"
  262.     bzr init
  263.     bzr add *
  264.  
  265.     echostat "Done!"
  266.     ;;
  267. "build" | "")
  268.     go_to_project_root
  269.  
  270.     if [ ! -d "build" ]; then
  271.         echostat "Creating build directory"
  272.         mkdir build
  273.     fi
  274.  
  275.     cd build
  276.     if [ ! -e "Makefile" ]; then
  277.         echostat "Running CMake ..."
  278.         cmake .. || (echoerr "CMake failed"; exit 1)
  279.     fi
  280.  
  281.     echostat "Building ..."
  282.  
  283.     make || (echoerr "Build failed"; exit 1)
  284.  
  285.     echostat "Build finished successfully!"
  286.     ;;
  287. "addpackage")
  288.     go_to_project_root
  289.  
  290.     if [ "$#" -lt 2 ]; then
  291.         echoerr "No package entered"
  292.         exit 1
  293.     fi
  294.  
  295.     sed -i "s/set (PACKAGES /set (PACKAGES $2 /" CMakeLists.txt || (echoerr "Failed to insert package"; exit 1)
  296.     echostat "Added package $2"
  297.     ;;
  298. "add")
  299.     go_to_project_root
  300.  
  301.     if [ "$#" -lt 2 ]; then
  302.         echoerr "No filename entered"
  303.         exit 1
  304.     fi
  305.  
  306.     # append .vala if necessary
  307.     file=$(echo $2 | sed "/\.vala/! s/$/.vala/")
  308.  
  309.     sed -i "s/set (FILES /set (FILES src\/$file /" CMakeLists.txt || (echoerr "Failed to add file to cmake setup"; exit 1)
  310.     touch "src/$file"
  311.     bzr add "src/$file" || (echoerr "Failed to add file to bzr"; exit 1)
  312.     echostat "src/$file added successfully"
  313.     ;;
  314. "remove")
  315.     go_to_project_root
  316.  
  317.     if [ "$#" -lt 2 ]; then
  318.         echoerr "No filename entered"
  319.         exit 1
  320.     fi
  321.  
  322.     # append .vala if necessary
  323.     file=$(echo $2 | sed "/\.vala/! s/$/.vala/")
  324.  
  325.     if [ ! -e "src/$file" ]; then
  326.         echoerr "File src/$file does not exist"
  327.         exit 1
  328.     fi
  329.  
  330.     sed -i "s/ src\/$file//" CMakeLists.txt || (echoerr "Failed to remove file from cmake setup"; exit 1)
  331.     bzr rm "src/$file" || (echoerr "Failed to remove file"; exit 1)
  332.     echostat "src/$file removed successfully"
  333.     ;;
  334. "clean")
  335.     go_to_project_root
  336.  
  337.     if [ -d "build" ]; then
  338.         rm -rf build
  339.         echostat "Cleaned"
  340.     else
  341.         echoinfo "No build directory found to be cleaned"
  342.     fi
  343.  
  344.     ;;
  345. "commit")
  346.     if [ "$#" -lt 2 ]; then
  347.         echoerr "No commit message entered"
  348.         exit 1
  349.     fi
  350.     if [ "$#" -lt 3 ]; then
  351.         bzr commit -m "$2" || (echoerr "Commit failed"; exit 1)
  352.     else
  353.         bzr commit --fixes lp:$3 -m "$2" || (echoerr "Commit failed"; exit 1)
  354.     fi
  355.     echostat "Successfully commited"
  356.     ;;
  357. "push")
  358.     echostat "Pushing ..."
  359.     if [ "$#" -lt 2 ]; then
  360.         bzr push || (echoerr "Pushing to default failed. Try specifying a branch"; exit 1)
  361.     else
  362.         bzr push --remember $2 || (echoerr "Pushing to $2 failed"; exit 1)
  363.     fi
  364.     echostat "Successfully pushed to $2"
  365.     ;;
  366. "help" | "--help")
  367.     usage
  368.     ;;
  369. "-v")
  370.     echo "Version: 0.1"
  371.     ;;
  372. *)
  373.     echoerr "Invalid command"
  374.     usage
  375. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement