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.

CCS pre/post build step with OS detection

I have a pre-build step that would be nice to automate for windows vs linux. 

  • script.sh works in linux/mac 
  • script.bat works in windows

How can I detect the OS pre/post build and fire off the right script? 
Not certain of a universal way to handle this. 


For now we have to edit the project settings depending on the platform to launch the shell script or batch file.

  • Hello Mike,

    How can I detect the OS pre/post build and fire off the right script? 
    Not certain of a universal way to handle this. 

    I'm not sure either. Note that the pre/post build step option simply passes the specified text to the system console for processing. 

    AartiG's post in the thread you referenced may be the best option. Have both sh and bat file in the same directory and have your pre/post build step invoke "script" without the extension. The correct one should get called depending on the system console used.

    Thanks

    ki

  • Thanks Ki. 

    I have 2 scripts, gitsha.sh for mac/linux, gitsha.bat for windows. 

    Executing in the Debug/ folder, I needed to add ../. 

    In my pre-build on OSX, I have ../gitsha.sh > gitsha.h, and that works. 
    Removing the extension breaks this. Do you have an example of this? 
    It sounds so simple!

  • It looks like the pre-build step, and therefore probably also the post build script, can take Eclipse variables such as ProjDirPath which is the absolute path of the project.

    With CCS 11.2 under Windows 10 created a simple project in which the pre-build step was:

    Fullscreen
    1
    echo #define PROJECT_DIR "${ProjDirPath}" > ${ProjDirPath}/test.h
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Which created a test.h file in the root of the project containing the absolute path of the project:

    Fullscreen
    1
    #define PROJECT_DIR "C:/Users/mr_halfword/workspace_v11/ccs_pre_build"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I.e. you might be able to pass ${ProjDirPath} as an argument to your script to get the file created in the correct directory on all operating systems.

  • Removing the extension breaks this. Do you have an example of this? 

    Try removing the *.sh file extension from the shell script. That worked for me. 

  • Thanks Chester. That'll be great once I can run the scripts! 
    The relative path would be nice to cleanup, but I'd like the same pre-build step on both OS's. 
    Ki thinks its possible tho! 

  • Thanks again Ki. Did you try on Mac or Windows? I'm currently on the Mac. 

    When I change the pre-build TO "../gitsha > gitsha.h" FROM "../gitsha.sh > gitsha.h"

    I get this on the build console - 

    inject git sha
    ../gitsha > gitsha.h
    makefile:185: recipe for target 'pre-build' failed
    /bin/sh: ../git: No such file or directory
    gmake[1]: [pre-build] Error 127 (ignored)

    I wouldn't expect this to work in any Mac or linux shell without an extension. 

  • I wouldn't expect this to work in any Mac or linux shell without an extension. 

    I think Ki meant to rename the script in the file system to remove the .sh extension, as well as removing the extension in the pre-build step.

    I.e. under Mac or Linux the shell script is named gitsha

    Whereas under Windows the batch file is named gitsha.bat

  • Thanks Chester. I must have mis interpreted that as I just woke up :) 

    That works on BOTH machines.