2

I have a build environment variable available, let's say for differentiating 2 hardware variants: HW_VER1

We are using linker script in build.

So, we want something like this. But, of course below gives error "invalid syntax in flags"

MEMORY
{

   ifeq ($(HW_VER1),YES)
      iram0_0_seg :                         org = 0x00080400, len = 0x21C00  
   else
      iram0_0_seg :                         org = 0x00080400, len = 0xf1C00
   endif
}

The requirement is not to use 2 linker scripts with the same exact contents, except the len value above, and let build system decide which one based on the env variable (the one with bigger len or smaller len based on the hw ver)

electro
  • 911
  • 4
  • 12
  • 28
  • 1
    Make *two* linker scripts and let the Makefile to handle the environment binding. – Eugene Sh. Aug 02 '17 at 17:14
  • 1
    You could use GCC preprocessor to add _C_ style preprocessor directives to your linker script. You can manually pre-process a file without GCC trying to compile it using the `-E` option. You can also call the preprocessor directly through `cpp`. An example of this can be found in this SO Answer: https://stackoverflow.com/a/28837410/3857942 . Alternatives are to use a macro processor like [_M4_](https://www.gnu.org/software/m4/manual/m4.html) – Michael Petch Aug 02 '17 at 17:20
  • you can define a symbol in ld args at link time and use it in the conditional: ` --defsym symbol=expression` – Serge Aug 02 '17 at 18:21
  • @Serge : I believe this person is looking to create link time conditionals. Although --defsym symbol will define a global symbol I know of no way of doing a conditional link time comparison of that value to alter the linker scripts effects. You could use that symbol programmaticly at run time but that doesn't seem to be the question. – Michael Petch Aug 02 '17 at 18:35
  • I think that in this case (did not test) the OP could define a symbol and do `len = mysym` eliminating a need for the conditional. Yes, it will put a global symbol in the symbol table as well. it worked for me in different situations though. – Serge Aug 02 '17 at 20:11
  • @Serge I believe LD will consider `len = mysym` as a non constant expression.Don't believe you can use symbols for a `len` expression. – Michael Petch Aug 02 '17 at 21:05

0 Answers0