Drupal, Makefiles: save time, make awesome

| development, drupal, geek

One day I’ll post a generalized version of the Makefile that makes my Drupal life so much easier, but in the meantime, here’s the general structure I use:

  1. Lots of configuration settings:
    Database name for Drupal site
    Database user for Drupal site
    Database user password for Drupal site
    Root MySQL password, used to drop and recreate the database, and grant permissions
    Subversion branch for source code control
    Subversion user name
    Subversion password
    Particularly useful when working with sites that use Domain Access, but handy even with other sites because of BASE_PATH
    Location of source code, needed for Drush
    Drush command line, just in case I want to fiddle with it
    Database prefix, for make clearcache

    Base URL

    Regular expression to match against simpletests using my modified Drush_simpletest that lets me run all groups of tests matching a regular expression
  2. An include statement
    -include *.mk
    This is really useful. This lets you override the variables using a file like local.mk, dropped into your current directory and kept out of your source code control system. I use this to make my Makefile just Do The Right Thing when it’s in different directories or on different servers. Do not forget to tweak your included file (or make sure there is one) if you need different configuration settings.
  3. Lots of targets:
    Uses mysqldump to back up the database.
    Drops the database and restores it from the backup.
    Drops the database
    Calls the site’s install.php with the appropriate profile.
    Calls the site’s cron.php
    Starts a MySQL connection to the Drupal database. I don’t have to remember what the database name is or what the connection details are, hooray!
    Clears the {cache}, {cache_menu}, {cache_views}, {cache_content}, {cache_filter}, and {cache_page} tables
    Hits the panic button and reverts my tree. (because svn revert . -R is too long)

    Regenerate the TAGS file that lets me find function definitions really quickly
    Use Drush to run all of my simpletest functional tests for this project

Sometimes I’ll have an “rsync” target to deploy files to a server and a “doc” target to regenerate my low-level documentation using doxygen, too.

This Makefile is seriously cool and seriously time-saving because it means that no matter which project, branch, directory, or server I’m working on, I have a consistent set of commands for the most common things I need to do. The less time I spend thinking about fiddly administrative tasks, the more time I can enjoy in the coding zone.

This is also one of the reasons why Drupal development is _so_ much easier on Linux or other Unix-ish systems, or even Microsoft Windows with the Cygwin environment. If you see yourself doing a fair bit of Drupal work, it’s well worth investing the time in setting up a virtual machine or a second partition, learning a new operating system, and re-setting-up your development environment.

make awesome. =)

What’s in your Makefile, or what other tricks do you use to increase your developer happiness?

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.