This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How can I perform a pre-link custom build operation in CCSv6?

Other Parts Discussed in Thread: TMS320C6657

We have a project that is targeting the TMS320C6657 DSP. I need advice on how to create a custom build step that only gets executed if the final linking is about to take place.

The reason for this is that I have a tool that will generate a source file with some extern constants in it (for version numbering, as well as some other miscellaneous build machine info), that I would like to compile and link into the final executable.

This generated source file should not really appear as part of the project, and should not be placed in version control for obvious reasons.

I've solved this problem in Visual Studio and QtCreater, because both VS and qmake offer "pre-link" commands that allow me to run a batch file/shell script to generate the source file and compile the source file into an object file. I then specify this object file to be included in the link operation. This only happens if the executable needs to be relinked because some other source file changed.

How can I accomplish this in CCSv6?

  • Hmm.. we have a options for a pre-build step that always runs before the build starts and a post build-stop that only runs after the link is done. Neither help you obviously. We don't have that option for custom intermediate step after the compilation is done and before the link.

    There are some potential hacks you can do but they are indeed hacks and not very pretty. One is to actually modify the generated makefile itself and add whatever custom step before the linker is called. The problem with that is that CCS auto-generates that makefile so you would need to disable the auto-generation and maintain the makefile yourself directly. Another option is use the file specific options to specify a custom command for that file to build it and also add any additional custom steps afterwards. This would require to manually specify the build command for the file and maintain it. Neither are pretty options.

    ki
  • CCS also has support for running pre and post build steps - please see this wiki article for more information:
    http://processors.wiki.ti.com/index.php/Projects_and_Build_Handbook_for_CCS#Pre_and_Post_Build_Steps

    In your case, you could perhaps run your batch file/script to generate the source file and compile it into an object file as a pre-build step in the project. Then you can add the .obj file to the linker command file (.cmd) that is part of the project. This will allow that object file to be pulled into the final link when the linker command file is passed to the linker.

    The .obj can simply be specified at the top of the linker command file (may need to include the whole path depending on the location of the file), for example:

    filename.obj
    MEMORY
    {....
    }
    SECTIONS
    {...
    }

    Does this address your situation? 

  • Actually I got a great suggestion from one of our senior engineers here. You can add any pre-link step to the command field in the Linker options. Basically prepend the custom step before the exisiting command and separate with an ampersand.

    Below is an example of adding a pre-link step to call a batch file:

    Thanks

    ki

  • Ki,

    Pre-pending the pre-link command like you mentioned worked beautifully. Also, thank you to AartiG on how to include the object in the link process, as that would have been the next question, I suspect.

    Might I suggest adding this tidbit of information to the Projects and Build Handbook, and/or possibly adding a new option to CCS specifically to address this need.

    Thanks!