Nat! bio photo

Nat!

Senior Mull

Twitter Github Twitch

Parallelize SublimeText project builds created by cmake

A convenient shell script to massage the output of cmake -G "Sublime Text 2 - Unix Makefiles" so that make runs with the -j <n> option. Where n will be the result of nprocs

cat <<EOF > mulle-parallelize-sublime-project.sh
#! /bin/sh


PROJECT="$1"

if [ "${PROJECT}" = "" ]
then
   echo "usage: mulle-parallelize-sublime-project.sh  <sublime-project>" >&2
   exit 1
fi

if [ ! -f "${PROJECT}" ]
then
   echo "\"${PROJECT}\" not found" >&2
   exit 1
fi

egrep -q "cmd\"\: \[\".*bin/make\"" "${PROJECT}"
if [ $? -ne 0 ]
then
   echo "not a make based sublime project" >&2
   exit 1
fi

egrep -q "cmd\"\: \[\".*bin/make\".*\"-j\"" "${PROJECT}"
if [ $? -eq 0 ]
then
   echo "is already parallelized" >&2
   exit 0
fi

cp "${PROJECT}" "${PROJECT}".tmp
if [ $? -ne 0 ]
then
   echo "failed to backup to \"${PROJECT}.tmp\"" >&2
   exit 1
fi

sed "/\"cmd\"\:/s/make\"\, /make\", \"-j\", \"`nproc`\", /" < "${PROJECT}".tmp > "${PROJECT}"

if [ $? -eq 0 ]
then
   rm  "${PROJECT}".tmp
fi
EOF
chmod 755 mulle-parallelize-sublime-project.sh

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

Name:
E-mail: (not published)
Website: