CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

[Semi-SOLVED] Building IDE-created project via Command Line
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

[Semi-SOLVED] Building IDE-created project via Command Line
PostPosted: Tue Sep 03, 2019 8:25 am     Reply with quote

I want to start automating our builds. I am looking for references on using the command line compiler.

I tried changing into the directory of one of our projects and doing:

Quote:
ccsc OurProject.ccspjt


But that reported it was unable to find a file.

Also, it seemed to just pop up the GUI component. Ideally, I'd like to see text output so we could capture that and know where a build failed. Ultimately, I'd want to move us to using something like Jenkins to perform automatic builds on check ins.

The reason I'd like to use the project file is so we don't end up getting out-of-sync. Developers would be working from the IDE, and if they make a change or add a file there, I don't want to have to be manually editing build scripts to keep them updated.

Can someone point me to some tips? Thanks!
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.


Last edited by allenhuffman on Wed Sep 04, 2019 8:45 am; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 03, 2019 8:30 am     Reply with quote

See this previous thread on Jenkins:

Building with Jenkins -
http://www.ccsinfo.com/forum/viewtopic.php?t=57596
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 9:20 am     Reply with quote

Is it even possible to do a multi-unit compile from the command line?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 9:38 am     Reply with quote

"Multiple Compilation Units" shows the option I was looking for:

Quote:
ccsc BUILD=Project.ccspjt


But it doesn't seem to actually build an IDE-created project file. They list how to make .c file which includes other files, and a linker batch file, and a build batch file. I see how it should work manually, but I'd like to keep things in sync with the IDE project to make sure what developers are building and self-testing matches what a build server can build for testing.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 03, 2019 10:57 am     Reply with quote

Go to the CCS examples folder. There is a file there called mcu.zip.
Unzip it into a "mcu" folder.
It contains a pdf file called "Using Multiple Compilation Units Guide".
It talks about using batch files. This may help you.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 11:32 am     Reply with quote

I'll take a look. So far, the documentation has been a bit lacking. The help file shows examples of this and says:

Quote:
Use the EXPORT option to include the necessary *.c files.


+EXPORT, as mentioned there and shown in the screen shots, is not listed in the Command Line Options page.

Whac-A-Mole continues Smile

Being able to just "build and run this .pjt file" would suffice, but that doesn't seem to work for me.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 12:42 pm     Reply with quote

I have a nice batch file that automates this (I'll share it once I get linking working). The final link step doesn't work for me, even if I do it manually.

Code:
ccsc out="Debug" +EXPORT File1.c
ccsc out="Debug" +EXPORT File2.c
ccsc out="Debug" +EXPORT File3.c
cd Debug
ccsc LINK="MyProject.hex=File1.o,File2.o,File3.o"


We put our output files in a subdirectory, and I've tried relative (Debug\File1.o) as well as changing into the directory where all the .o files are (verified they are there). No hex file is produced and no error is shown.

This matches the example in the help file except for an option that errors out if I use it (for the compile steps, but it makes the .o without it).

What is missing from the examples that I need to add?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 03, 2019 12:52 pm     Reply with quote

How about sending an email to CCS support and point them to this thread ?
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 12:58 pm     Reply with quote

PCM programmer wrote:
How about sending an email to CCS support and point them to this thread ?


Yes indeed. I have an e-mail thread with them. I'm about to send them the follow-up with a few more things I've noticed. For example:

LINK="output.hex=File1.o,File2.o,File3.o,"

Above will silently fail -- it can't find the final file (see the extra comma?). Likewise is a bad filename is on the list.

The good news is that the .hex file I have manually produced now matches the one from the IDE. I'll share my batch script in a moment.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Sep 03, 2019 1:07 pm     Reply with quote

Here is a windows Batch file that will compile a list of .c files and link them into a .hex file. You edit:

1) The list of .c files to compile.
2) The root name of the output .hex file ("foo" would generate "foo.hex")
3) An output directory (such as "Debug" or whatever). It probably needs to exist before you run this.

I have a bit more cleanup to do, but this work-in-progress version works, at least for me.

Code:
@ECHO OFF

REM
REM .c files used in the project.
REM
SET FILES=File1.c File2.c File3.c File4.c

REM
REM Root name of final output hex file.
REM
SET ONAME=MyProject

REM
REM Output directory for temporary and final .hex file.
REM
SET ODIR=Debug

REM
REM Nothing else should need to be modified...
REM
SETLOCAL EnableDelayedExpansion

SET OFILES=

REM
REM Compile/export each .c file into a .o
REM Build an OFILES variable with all the "file.o" listed together (for linking).
REM
FOR %%F IN (%FILES%) DO (
   ECHO Building %%F... ^(%%~nF.o^)
   SET OFILES=!OFILES!%%~nF.o,
   ccsc out="%ODIR%" +EXPORT %%F
)

REM
REM Remove trailing comma in the .o list ("File1.o,File2.o,").
REM
SET OFILES=%OFILES:~0,-1%

REM
REM Link the .o together.
REM
echo Linking...
PUSHD %ODIR%
ccsc LINK="%ONAME%.hex=%OFILES%"
POPD

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

Updates: the "out" option has the issue
PostPosted: Fri Oct 11, 2019 7:39 am     Reply with quote

It seems that using...
Code:
ccsc BUILD=project.ccspjt

...works just find if you run it in the directory with the sources. It generates all the intermediate files and output file(s) there, making quite the mess.

There is an example in the help file that lists...
Code:
out="path"

...and that option is recognized, but it fails to build.

My temporary workaround was to do something like...
Code:

MKDIR TEMP

DEL TEMP\*.*
COPY *.* TEMP

PUSHD TEMP
CCSC BUILD=project.ccspjt
POPD


That batch script would make a temporary location for the files, copy them all there, temporarily move into that directory (push directory) and do the build, then return (pop directory) to where it started.

That works great, and is significantly faster doing the build than my file-by-file batch file.

We found an issue where the command line version would work, but would generate a different version of the file (based on linker order, maybe?) than the IDE was, and decided we wanted the automated build to be 100% matching the IDE developer versions, to ensure we were getting the same results.

More to come...
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.


Last edited by allenhuffman on Fri Oct 11, 2019 9:39 am; edited 1 time in total
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 11, 2019 9:32 am     Reply with quote

Another note … passing in defines using #LABEL=value does not seem to work when calling the project from the command line.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Fri Oct 11, 2019 12:05 pm     Reply with quote

I think you could do that by injecting a line. So:

SOURCELINE="#DEFINE VAL=xxxx"

Honestly, if you have a .def file created used by the IDE, just #include
this
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 11, 2019 12:58 pm     Reply with quote

Ttelmah wrote:
I think you could do that by injecting a line. So:

SOURCELINE="#DEFINE VAL=xxxx"

Honestly, if you have a .def file created used by the IDE, just #include
this


There is a hard-coded define in the source that builds to a specific origin address. We do two builds and alternate when updating flash, for disaster recovery.

I have just done a test and I can confirm that #VAL=label does appear to be honored when running a project file. Which means there is a different problem to track down.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
allenhuffman



Joined: 17 Jun 2019
Posts: 580
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Oct 14, 2019 11:01 am     Reply with quote

As a work-around for the "out=" not working, we just made a tempory subfolder, copied files into it, then did the build there and copied the resulting .hex file we needed to our distribution directory.

I will include SNIPPETS of what I did, for reference. We do many other things (parsing a file to get an internal hard-coded version date and build letter, for example).

Code:
@ECHO OFF
SETLOCAL
REM
REM Build CCS project.
REM
REM 2019-09-10 1.00 ach - Created.
REM

rem SET PROJECT=ControlInterface_main

SETLOCAL EnableDelayedExpansion

REM - set to the base name of the project file.

set PROJECT=ProjectName

if "%PROJECT%"=="" (
   echo PROJECT must be set.
   GOTO :EOF
)

REM
REM To workaround a CCSC.EXE bug, we want to copy all the source files into a
REM temporary sub-directory and then build from there.
REM
MKDIR TEMP
DEL TEMP\*.*
COPY *.c TEMP
copy *.h TEMP
copy *.ccspjt TEMP
PUSHD TEMP

REM
REM Build the project.
REM
ECHO Building %PROJECT%...
DEL *.o
DEL *.osym
CCSC BUILD=%PROJECT%.ccspjt

REM -- then we copy the .hex file to where we want it.

POPD


We have one master "build" batch file than produces A and B versions (different ORG memory address) of six different projects. Each is named with an internal version and build letter, then they are copied to a distribution folder that uses the build letter in a directory name. So there's a ton more of this batch file not included here, since it's specific to our use.

But with this, running on batch file performs steps that would have tied up the human for 15-30 minutes doing manually each time.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group