Home > OS >  How to loop trough counter in GNU makefile?
How to loop trough counter in GNU makefile?

Time:09-13

What would be a proper way of defining a number macro in Config.in and looping through it in makefile?

Config.in

config BR2_PACKAGE_CNT
    string "counter"
    default "1" if BR2_PLATFORM_XX
    default "2" if BR2_PLATFORM_YY

package.mk

$(foreach i, $(shell seq $(BR2_PACKAGE_CNT)), \
    $(info $i))

CodePudding user response:

With some examples I manage to construct a number list from Boolean variable, which then could be iterated. Maybe not the cleanest approach, but the best I could come up with.

Defined in Config.in

config CONFIG_VAR_1
  bool "var 1"
  default y

config CONFIG_VAR_2
  bool "var 2"
  default y

Makefile

VAR = \
    $(if $(CONFIG_VAR_1), 0) \
    $(if $(CONFIG_VAR_2), 1)

$(foreach i, $(VAR), $(info VAR=$i))

CodePudding user response:

There is a function interval in gmtt which creates a list of numbers.

include gmtt.mk

$(foreach i, $(call interval,1,$(BR2_PACKAGE_CNT)), \
    $(info $i))
  • Related