HOW TO BUILD MPLAB X PROJECTS FROM THE COMMAND LINE?

A Quick Introduction

MPLAB X IDE is a software program that is used to develop applications for Microchip microcontrollers and digital signal controllers. This development tool is called an Integrated Development Environment, or IDE, because it provides a single integrated “environment” to develop code for embedded microcontrollers.

Why build from Command line, when I can do with one click

                              We can build the project in MPLAB X IDE with one click on any of the following icons

Capture
In this way the IDE works great and makes it easy to develop and build projects. however, building releases locally on developer machines is not the ideal way to be releasing software. Usually we want to automate the build and test software continuously using a platform like Jenkins. Jenkins is cross-platform, continuous integration and continuous delivery application that increases your productivity. Using Jenkins to build and test your software projects continuously makes it easier for developers to integrate changes to the project and makes it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by providing powerful ways to define your build pipelines and integrating with a large number of testing and deployment technologies. Continuous Integration (CI) and automated build servers solve this problem and are in widespread use by the software industry.

To automate build, we need to set up Embedded toolchains which can be complicated and time-consuming. IDEs do a good job of making this easy, but build servers usually require building the projects through scripts and the command line. I’ve seen a lot of people asking questions about how to build their MPLABX projects through the command line, presumably so that they can set up automated build servers for their projects.

The process is really quite simple once you understand how MPLABX builds a release.,

  • Firstly it generates a Makefile based on the build configuration and settings of your project.
  • Secondly it runs the build using the generated Makefile.

Following steps show how to set up and build from command line:

Environment Setup 

  1. Make sure you have the latest version of MPLABX. Look inside your MPLABX installation folder and browse to batch file which creates makefile C:\Program Files(x86)\Microchip\MPLABX\v3.05\mplab_ide\bin\ . If you see a file called prjMakefilesGenerator.bat then move on to the next step. Otherwise, update your copy of MPLABX.
  2. Add the folder containing prjMakefilesGenerator.bat to PATH. This will allow you to run the Makefile generator simply by typing its name on the command line. On Windows, the directory you will need to add to PATH will most likely be C:\Program Files(x86)\Microchip\MPLABX\v3.05\mplab_ide\bin\.
  3. Add the MPLABX utilities required to run a Makefile to PATH. The utilities are located inside the MPLABX installation folder inside of \gnuBins\GnuWin32\bin\ . This will allow you to run the Makefile simply by using the command make . On Windows the directory you will need to add to PATH will most likely be C:\Program Files (x86)\Microchip\MPLABX\v3.05\gnuBins\GnuWin32\bin\ . Make sure that you don’t have any other make commands on your path else this might cause some issues.

What Next

Building the Project

  1. Open up a command line and browse to the project’s root folder.
  2. Run the prjMakefilesGenerator.bat to generate the Makefile.

    The Makefile should now appear in the project’s root directory. If you are going to be building on a build server, you won’t always know what the full path is. On a Windows build machine, you could use the following command instead:

    This will automatically insert the path of the current directory when you run the command.

  3. Find out what the build command is by running the GUI version of MPLABX. Open the project you are trying to build and run the “Clean and Build” command. Then look in the Output window (If you don’t see it, try Windows > Output > Output) to see the command that was run. Look for the first command starting with make . The command should look something like this:

     

commandline capture

  1. You can replace buildconfigname from the line above with whatever build configuration you want to build.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s