6.3.6.3.1 User Makefile Project – Create Code from a Batch File
To compile the code, the simple batch file
makeme.bat takes as arguments production
,
debug
or clean
. If production
is
passed then t_production.hex is built. If debug
is
passed then t_debug.elf is built. If clean
is
passed, then the .elf and .hex files are
erased.
Example: makeme.bat Code
::assumes xc32-gcc and xc32-bin2hex are on the path
rem @echo off
set COMPILER=xc32-gcc
set BIN2HEX=xc32-bin2hex
set PROCESSOR=32MX360F512L
if "%1" == "production" goto production
if "%1" == "clean" goto clean
:debug
%COMPILER% -mprocessor=%PROCESSOR% -g -D_DEBUG -o t_debug.elf t.c
goto end
:production
%COMPILER% -mprocessor=%PROCESSOR% -o t_production.elf t.c
%BIN2HEX% t_production.elf
goto end
:clean
del /F *.elf
del /F *.hex
goto end
:end
To create a new user makefile project in MPLAB X IDE, follow the steps in 6.3.6.1 New Project - User Makefile:
- Choose Project: Select Microchip Embedded, User Makefile Project.
- Select Device (and Tool): Select PIC32MX360F512L as the device. No tool is available for selection in this type of project.
- Select Header: None available for this device.
- Select Plugin Board: None used for this example.
- Select Project Name and Folder: For this example, the Project Folder will be a sibling to myOwnCodeWithItsOwnMakefile. Therefore the Project Location will be: C:\Users\User\MPLABXProjects\makestuff. The Project Name is MPLABXProjectT.
- Create User Makefile Project:
Enter information to set up your makefile project.
The Working Directory is where the batch file build, debug build and clean commands will be run. This directory could be set as the absolute path:
C:\Users\User\MPLABXProjects\makestuff\myOwnCodeWithItsOwnMakefile.
Doing this, however, makes the MPLAB X IDE project less portable. Therefore the Working Directory, Image name and the Debug image name will be entered as relative paths with respect to the MPLAB X IDE project directory.
Click Finish to create the project.