3

I'm writing firmware using an older C compiler called HC12. Currently I use GNU Make for the build system. I'm hoping to start using CMake, but ran into an issue: The compiler does not support some standard C compiler syntax, namely the "-o" flag.

I've made a custom toolchain file and added all my c flags, but CMake seems to implicitly add the "-o" to compile source files, in the generated GNU Makefiles.

The HC12 compiler allows me to use -objn="name_of_file" to specify the output filename.

My question: Is there a way to get CMake to stop putting the implicit "-o" so that I can use this compiler?

I know there is a GCC port for this processor, but changing compilers at this point isn't an option.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • 4
    Make a script that parses the command line a little and replaces `-o filename` with `-objn=filename` and tell CMake to call that script instead of the compiler. Or give that script the same name as the compiler and put it in your executable search path (and be sure it executes the compiler using an absolute path). – Eric Postpischil Jan 07 '22 at 00:15
  • Use the workaround Eric suggested. But, then, as a service to the rest of the world, please file a bug report with the compiler company/author :-) – Craig Estey Jan 07 '22 at 00:58
  • @CraigEstey - your suggestion is a good one, but I suspect OP will come back and say that the compiler vendor is either no longer in business, or not supporting/updating the compiler anymore. (The HC12 is an ancient microcontroller) – Dan Jan 07 '22 at 01:30
  • @Dan Yes, I agree. That's why I used ":-)" in my comment. I just wanted to "annoy" the [ancient] vendor ;-) I could have been "more annoying" if I suggested that OP talk to his local H/W engineer to respin the board to use a more modern/faster processor. I do a lot of device driver/embedded work and I get frustrated by H/W engineer(s) designing a _modern_ board with under powered CPUs (e.g.) They design the system so that, in order for the system to meet its realtime latency/throughput requirements, it runs at 90% utilization. I've [actually] heard: _Well, you have a 10% margin_ – Craig Estey Jan 07 '22 at 03:26
  • @EricPostpischil - That's a great idea and I'll probably go with that. – Bruce Haines Jan 08 '22 at 03:22
  • @CraigEstey - I think I might email them just to see what they say. They'll probably have a good laugh! – Bruce Haines Jan 08 '22 at 03:28
  • Are you sure the compiler is called that? I've worked extensively with HC12 and thought I knew all compilers. What is it actually named? Is it Cosmic, Codewarrior, IAR...? Also compilers tend to use `-O` upper case. The gcc port for HC12 is likely hopelessly outdated. – Lundin Jan 08 '22 at 10:13
  • @CraigEstey -- sorry, I didn't put 2 & 2 together. I read the smiley as "pay it forward / do something nice for the next person" -- I often use the wink ;-) to indicate sarcasm so I didn't pick up on it. I agree about underpowered / outdated CPUs. Cheers! – Dan Jan 09 '22 at 16:45
  • @Dan Ironically, I _usually_ use ";-)" for humor/sarcasm, but I used ":-)" for LOL [thinking it would be clearer]. I looked up the HC12. It is _horrible_. It's a descendant of the HC08 which comes from the Motorola 6800 which predates the mc68000. The 6800 was first created in 1974 and the instruction set is anemic/unbalanced to say the least. It's time to design this _out_. – Craig Estey Jan 09 '22 at 16:58
  • @Lundin - Yes, I am sure the compiler is called HC12. Here is the manual: https://www.nxp.com/docs/en/reference-manual/HC12COMPILERRM.pdf The project originally used the CodeWarrior IDE (not a compiler!), which in turn uses the HC12 compiler. The -O flag for this compiler is for setting the main optimization target (speed vs size). The GCC port may be outdated, but I wouldn't be surprised if it is more modern than the original. This compiler does not support the C99 standard. – Bruce Haines Jan 09 '22 at 18:50
  • @BruceHaines Everyone calls the compiler Codewarrior and that's the one referred to in the document. It had shaky C99 support indeed. – Lundin Jan 10 '22 at 07:20
  • @CraigEstey Not quite, HCS12 (16 bit) replaced 68HC12 (16 bit) which replaced 68HC11 (8 bit). 68HC08 (8 bit) was based on 6800 and HCS08 (8 bit) replaced it. They are all quite similar on the assembler level though. The HCS12 doesn't have much in the way of registers but it's still way more code efficient than much older cores like AVR and PIC. Naturally all of the old 8 and 16 bitters should be avoided, but end products tend to live much longer than MCUs these days. – Lundin Jan 10 '22 at 07:26

1 Answers1

5

You could take a file like the Modules/Compiler/ti.cmake as a reference and create one for your HC12 compiler, and also change these macros defined there:


# the input file options from TI, change to what your compiler needs
# They are used below in the command where ${lang} is either C, CXX or ASM
set(__COMPILER_HC12C_SOURCE_FLAG_C   "--c_file")
set(__COMPILER_HC12C_SOURCE_FLAG_CXX "--cpp_file")
set(__COMPILER_HC12C_SOURCE_FLAG_ASM "--asm_file")
# add output file option
set(__COMPILER_HC12C_OUTPUT_FLAG_C   "--objn")

macro(__compiler_HC12C lang)

  # ...

  set(CMAKE_${lang}_COMPILE_OBJECT  "<CMAKE_${lang}_COMPILER> --compile_only ${__COMPILER_HC12C_SOURCE_FLAG_${lang}}=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> ${__COMPILER_HC12C_OUTPUT_FLAG_${lang}}=<OBJECT>")
  #                                                                          ---------------------------------------                                       ---------------------------------------

  # ...

endmacro()

Hope, this will help.

kesselhaus
  • 1,241
  • 8
  • 9
  • Thank you, this looks very promising. I will try it tomorrow before I try wrapping the compiler in a script as Ericpostpischil commented above. Will accept your answer when I get it working. – Bruce Haines Jan 09 '22 at 18:57