Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- # attempts to cd to the root dir of the project
- function go_to_project_root {
- while : ; do
- if [ ! -e "CMakeLists.txt" ]; then
- cd ..
- if [ "$(pwd)" == "/" ]; then
- echoerr "No CMakeLists.txt found! Are you in one of the project's directories?"
- exit 1
- fi
- else
- break;
- fi
- done
- }
- function echoerr {
- echo -e "\e[00;31m[Error] $@\e[00m" 1>&2
- }
- function echostat {
- echo -e "\e[00;32m[Status] $@\e[00m"
- }
- function echoinfo {
- echo -e "\e[00;34m[Info] $@\e[00m"
- }
- function usage {
- echo -e "Usage: ebuild <command> [parameter]
- Commands:
- build - Builds the project belonging to the current diretory
- new - Launches the project creation wizard
- addpackage <package> - Adds a package to the project. Check CMakeLists.txt's top for a list of the ones currently used
- 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
- push [branch] - Pushes the bzr branch to branch and sets branch as default location. If no branch is specified, attempt to push to default
- addfile <file> - Adds file to the project
- removefile <file> - Removes file from the project
- clean - Removes build directory, sometimes required to have new packages used correctly
- If no command is given, 'build' will be used
- "
- exit 0
- }
- echostat "Welcome to ebuild!"
- case "$1" in
- "new")
- echo "Enter the project's name:"
- read FULLNAME
- echo "Enter its description:"
- read DESC
- echo "Enter the authors in the form 'Author Name <author@email>, Author2 Name2 <author2@email.com>' (without quotes):"
- read AUTH
- echo "Enter an icon name, if none is given application-default is used:"
- read ICON
- if [ "$ICON" == "" ]; then
- ICON="application-default"
- fi
- echo "Enter a generic name for the app (e.g. MusicPlayer for Noise):"
- read GENNAME
- # make it lowercase and put a dash where a whitespace was
- NAME=$(echo "$FULLNAME" | tr '[A-Z] ' '[a-z]-')
- NAMESPACE=$(echo "$FULLNAME" | tr -d ' ')
- YEAR=$(date +%Y)
- echoinfo "To edit these values later, see data/$NAME.desktop"
- mkdir $NAME
- cd $NAME
- # get the newest cmake modules
- echostat "Getting latest cmake modules ..."
- bzr branch lp:~elementary-apps/+junk/cmake-modules
- mv cmake-modules/cmake/ .
- rm -r cmake-modules
- # our main CMakeLists.txt
- echostat "Generating project files ..."
- echo "
- set (NAME $NAME)
- set (PACKAGES granite)
- set (FILES src/$NAMESPACE.vala)
- project (\${NAME})
- cmake_minimum_required (VERSION 2.8)
- cmake_policy (VERSION 2.6)
- list (APPEND CMAKE_MODULE_PATH \${CMAKE_SOURCE_DIR}/cmake/vala)
- set (CMAKE_INSTALL_PREFIX /usr)
- enable_testing ()
- set (DATADIR \"\${CMAKE_INSTALL_PREFIX}/share\")
- set (PKGDATADIR \"\${DATADIR}/${NAME}\")
- set (GETTEXT_PACKAGE \"\${NAME}\")
- set (VERSION \"0.1\")
- list (APPEND CMAKE_MODULE_PATH \${CMAKE_SOURCE_DIR}/cmake)
- configure_file (\${CMAKE_SOURCE_DIR}/src/Config.vala.cmake \${CMAKE_BINARY_DIR}/src/Config.vala)
- add_definitions(-DGETTEXT_PACKAGE=\\\"\${GETTEXT_PACKAGE}\\\")
- find_package(PkgConfig)
- pkg_check_modules(DEPS REQUIRED \${PACKAGES})
- add_definitions (\${DEPS_CFLAGS})
- link_libraries (\${DEPS_LIBRARIES})
- link_directories (\${DEPS_LIBRARY_DIRS})
- find_package (Vala REQUIRED)
- include (ValaVersion)
- ensure_vala_version ("0.16.0" MINIMUM)
- include (ValaPrecompile)
- vala_precompile (VALA_C \${NAME}
- \${FILES}
- \${CMAKE_BINARY_DIR}/src/Config.vala
- PACKAGES
- \${PACKAGES}
- OPTIONS
- \${VALAFLAGS}
- )
- add_subdirectory (po)
- include (GSettings)
- add_schema ("data/org.pantheon.$NAME.gschema.xml")
- add_executable (\${NAME} \${VALA_C})
- install (TARGETS \${NAME} RUNTIME DESTINATION bin)
- install (FILES \${CMAKE_CURRENT_SOURCE_DIR}/data/\${NAME}.desktop DESTINATION share/applications)
- " > CMakeLists.txt
- # the desktop and the gschema file
- mkdir data
- cd data
- echo "[Desktop Entry]
- Type=Application
- Name=$FULLNAME
- Comment=$DESC
- GenericName=$GENNAME
- Exec=$NAME
- Icon=$ICON
- Terminal=false
- Categories=Utility;
- " > $NAME.desktop
- echo "
- <?xml version=\"1.0\" encoding=\"UTF-8\"?>
- <schemalist>
- <schema path=\"/org/pantheon/$NAME/\" id=\"org.pantheon.$NAME\" gettext-domain=\"$NAME\">
- </schema>
- </schemalist>
- " > org.pantheon.$NAME.gschema.xml
- cd ..
- # l10n
- mkdir po
- cd po
- echo "include (Translations)
- add_translations_directory (\"$NAME\")
- add_translations_catalog (\"$NAME\"
- ../src
- ../src/Widgets
- )
- " > CMakeLists.txt
- cd ..
- # src
- mkdir src
- cd src
- echo "/***
- BEGIN LICENSE
- Copyright (C) $YEAR $AUTH
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License version 3, as
- published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranties of
- MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- PURPOSE. See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program. If not, see <http://www.gnu.org/licenses>
- END LICENSE
- ***/
- namespace $NAMESPACE
- {
- public class App : Granite.Application
- {
- construct
- {
- program_name = \"$FULLNAME\";
- exec_name = \"$NAME\";
- app_years = \"$YEAR\";
- application_id = \"net.launchpad.$NAME\";
- app_icon = \"$ICON\";
- app_launcher = \"$NAME.desktop\";
- main_url = \"https://code.launchpad.net/$NAME\";
- bug_url = \"https://bugs.launchpad.net/$NAME\";
- help_url = \"https://code.launchpad.net/$NAME\";
- translate_url = \"https://translations.launchpad.net/$NAME\";
- about_authors = {\"$AUTH\"};
- about_documenters = {\"$AUTH\"};
- about_artists = {\"$AUTH\"};
- about_comments = \"$DESC\";
- about_translators = \"\";
- about_license_type = Gtk.License.GPL_3_0;
- }
- public App ()
- {
- }
- public override void activate ()
- {
- var window = new Gtk.ApplicationWindow (this);
- window.window_position = Gtk.WindowPosition.CENTER;
- window.set_default_size (640, 480);
- window.show_all ();
- }
- }
- }
- public static int main (string [] args)
- {
- Gtk.init (ref args);
- return new $NAMESPACE.App ().run (args);
- }
- " > $NAMESPACE.vala
- echo "
- namespace Constants {
- public const string DATADIR = \"@DATADIR@\";
- public const string PKGDATADIR = \"@PKGDATADIR@\";
- public const string GETTEXT_PACKAGE = \"@GETTEXT_PACKAGE@\";
- public const string RELEASE_NAME = \"@RELEASE_NAME@\";
- public const string VERSION = \"@VERSION@\";
- public const string VERSION_INFO = \"@VERSION_INFO@\";
- public const string PLUGINDIR = \"@PLUGINDIR@\";
- }" > Config.vala.cmake
- cd ..
- echostat "Intializing bazaar"
- bzr init
- bzr add *
- echostat "Done!"
- ;;
- "build" | "")
- go_to_project_root
- if [ ! -d "build" ]; then
- echostat "Creating build directory"
- mkdir build
- fi
- cd build
- if [ ! -e "Makefile" ]; then
- echostat "Running CMake ..."
- cmake .. || (echoerr "CMake failed"; exit 1)
- fi
- echostat "Building ..."
- make || (echoerr "Build failed"; exit 1)
- echostat "Build finished successfully!"
- ;;
- "addpackage")
- go_to_project_root
- if [ "$#" -lt 2 ]; then
- echoerr "No package entered"
- exit 1
- fi
- sed -i "s/set (PACKAGES /set (PACKAGES $2 /" CMakeLists.txt || (echoerr "Failed to insert package"; exit 1)
- echostat "Added package $2"
- ;;
- "add")
- go_to_project_root
- if [ "$#" -lt 2 ]; then
- echoerr "No filename entered"
- exit 1
- fi
- # append .vala if necessary
- file=$(echo $2 | sed "/\.vala/! s/$/.vala/")
- sed -i "s/set (FILES /set (FILES src\/$file /" CMakeLists.txt || (echoerr "Failed to add file to cmake setup"; exit 1)
- touch "src/$file"
- bzr add "src/$file" || (echoerr "Failed to add file to bzr"; exit 1)
- echostat "src/$file added successfully"
- ;;
- "remove")
- go_to_project_root
- if [ "$#" -lt 2 ]; then
- echoerr "No filename entered"
- exit 1
- fi
- # append .vala if necessary
- file=$(echo $2 | sed "/\.vala/! s/$/.vala/")
- if [ ! -e "src/$file" ]; then
- echoerr "File src/$file does not exist"
- exit 1
- fi
- sed -i "s/ src\/$file//" CMakeLists.txt || (echoerr "Failed to remove file from cmake setup"; exit 1)
- bzr rm "src/$file" || (echoerr "Failed to remove file"; exit 1)
- echostat "src/$file removed successfully"
- ;;
- "clean")
- go_to_project_root
- if [ -d "build" ]; then
- rm -rf build
- echostat "Cleaned"
- else
- echoinfo "No build directory found to be cleaned"
- fi
- ;;
- "commit")
- if [ "$#" -lt 2 ]; then
- echoerr "No commit message entered"
- exit 1
- fi
- if [ "$#" -lt 3 ]; then
- bzr commit -m "$2" || (echoerr "Commit failed"; exit 1)
- else
- bzr commit --fixes lp:$3 -m "$2" || (echoerr "Commit failed"; exit 1)
- fi
- echostat "Successfully commited"
- ;;
- "push")
- echostat "Pushing ..."
- if [ "$#" -lt 2 ]; then
- bzr push || (echoerr "Pushing to default failed. Try specifying a branch"; exit 1)
- else
- bzr push --remember $2 || (echoerr "Pushing to $2 failed"; exit 1)
- fi
- echostat "Successfully pushed to $2"
- ;;
- "help" | "--help")
- usage
- ;;
- "-v")
- echo "Version: 0.1"
- ;;
- *)
- echoerr "Invalid command"
- usage
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement