1

I want to generate a random value within a given range and use the result to update a Makevariable as well as modify a file.

I tried using the below code, I do see the random value generated. But I am unable to use it in the sed/Make variable.

Makefile ::

ALL_CPU_IRQ = 1

all:
ifeq ($(ALL_CPU_IRQ),1)
        RANDINT=$(shell python -c 'from random import randint; print(randint(1,3));')
        @echo $(RANDINT)
override BLOCK_RUN_OPT  +=  +init_cpu=$(RANDINT)
        sed -i 's|asm_comp_opt_tl=|\0INIT_CPU=$(RANDINT),|' $(CURDIR)/asm_opt.txt
        @echo $(BLOCK_RUN_OPT)
endif


Output I observe is :

RANDINT=2
+init_cpu=

And asm_opt.txt : asm_comp_opt=INIT_CPU=,


Expected output :

RANDINT=2
+init_cpu=2

And asm_opt.txt : asm_comp_opt=INIT_CPU=2,


I am fairly new to Makefile. Any suggestions would be helpful. Apologies if it's a redundant question.

  • What is the expected output? And what output do you expect in the Makefile finally? Can you help us in that? – hacker315 Feb 22 '23 at 08:35
  • Sorry I missed it in main thread. Expected output : BLOCK_RUN_OPT = +init_cpu=2 and asm_opt.txt :: asm_comp_opt=INIT_CPU=2, – g8grundeller Feb 22 '23 at 08:37
  • Hang on, is that code in a script? I don't see how it could function as well as it does in a makefile, whether it's in a rule or not. – Beta Feb 22 '23 at 12:02
  • @Beta : It is part of rule of Makefile. I have updated the main thread, with full Makefile sample – g8grundeller Feb 22 '23 at 16:56
  • If that is your full makefile, what is `BLOCK_RUN_OPT` for? – Beta Feb 22 '23 at 17:54
  • This is an excerpt for total makefile. I would want to use BLOCK_RUN_OPT further as arg to simv command – g8grundeller Feb 22 '23 at 19:02

1 Answers1

0

Try following:

RANDINT=$(shell python -c 'from random import randint; print(randint(1,3));')
@echo $(RANDINT)
    override BLOCK_RUN_OPT  +=  +init_cpu=$(RANDINT)
@echo $(BLOCK_RUN_OPT)
sed -i 's|asm_comp_opt_=|\0INIT_CPU="$RANDINT",|' $(CURDIR)/asm_opt.txt
hacker315
  • 1,996
  • 2
  • 13
  • 23
  • I tried below change, but issue remains the same. sed -i 's|asm_comp_opt_tl=|\0INIT_CPU="$(RANDINT)",|' $(CURDIR)/asm_opt.txt – g8grundeller Feb 22 '23 at 09:21