Configuring an Asterisk build from the command line

Configuring an Asterisk build from the command line

If you’re an Asterisk package maintainer, you already know this.  If not, did you know you can run menuselect/menuselect from the command line to enable/disable modules, set compile flags, choose sound files, etc.?

$ menuselect/menuselect --help
Usage: menuselect/menuselect [--enable] [--disable]
[--enable-category ] [--enable-all]
[--disable-category ] [--disable-all] [...]
[ [...]]
Usage: menuselect/menuselect { --check-deps | --list-options
| --list-category  | --category-list | --help }
[ [...]]

If you hack on Asterisk regularly, this can be a great time saver over having to run make menuselect.  For instance, if you want to create a build with only the chan_pjsip channel driver, you could run menuselect/menuselect --disable-category MENUSELECT_CHANNELS --enable chan_pjsip  to enable only chan_pjsip.  Now running menuselect by hand from the command line isn’t all that helpful but running it from a script or a Makefile opens up some interesting possibilities…

Being an Asterisk core developer, I spend a good deal of my day re-configuring and re-building Asterisk with various combinations of ./configure arguments and menuselect options.  One of the things I did to ease the pain was to create a wrapper Makefile that contains the common configurations that I use.  Here’s how you can do the same:

Create a file called “.Makefile.local” in the top source tree directory with the following contents:

# Include the 'real' Makefile
include Makefile
# Add your own targets
configprod:
    ./configure --prefix=/usr
    ./menuselect/menuselect --disable-category MENUSELECT_CHANNELS 
        --enable chan_pjsip
configdev:
    ./configure --prefix=/usr --enable-dev-mode
    ./menuselect/menuselect --enable DONT_OPTIMIZE 
        --enable TEST_FRAMEWORK --disable COMPILE_DOUBLE

Once you’ve saved that file, add the name to the end of .git/info/excludes file.  This is a local “.gitignore” file that’s specific to your copy of the repository.  This prevents .Makefile.local from showing up as an untracked file.

Now create a bash alias for make:

$ alias make='_ml=$([ -f .Makefile.local ] && echo "-f .Makefile.local") make -j$(nproc) $_ml'

The alias does a few things…

  • Checks for the existence of a file named “.Makefile.local”
  • If it exists, sets the variable “_ml” to “-f .Makefile.local”
  • Runs the real “make” with arguments that set the number of parallel builds to the number of processors available and, if .Makefile.local exists,  uses the .Makefile.local file instead of the default Makefile.

Nifty huh?   Now you can just run make configdev to run ./configure and set up the build options the way you want.  Any make target other than the ones in your .Makefile.local will be searched for in the normal Makefile.   There are lots of things you can do in your .Makefile.local.   Here’s an example of a quick re-install target…

reinstall:
    sudo rm -rf /usr/lib64/asterisk/modules 
    sudo $(MAKE) install install-headers

That’s all for now!  Leave a comment if you have other tips on how to make configuring an Asterisk build easier.

 

About the Author

What can we help you find?