Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:06:38+00:00 2026-06-12T20:06:38+00:00

Have problem in dynamically create target name with .SECONDEXPANSION: Small Makefile to reproduce problem:

  • 0

Have problem in dynamically “create” target name with .SECONDEXPANSION:

Small Makefile to reproduce problem:

CONFIGS = test1 test2 test3

.SECONDEXPANSION:

all: $(CONFIGS)

OBJECTS=$$(CFG_NAME)_OBJECTS


$(CONFIGS) : CFG_NAME=$@
$(CONFIGS) : $(OBJECTS) 
    @echo $(CFG_NAME) $@ from $^

$(OBJECTS):
    @echo OBJECTS $@ from $^
    @echo DO IT

It says: “No rule to make target ‘test1_OBJECTS’.
How can I solve this problem?

EDIT: CHANGE OF THE ANSWER

Thank you much for the answer. It was the simple variant for my task.

So I try to answer in another way.

CONFIGS = test1 test2 test3
PLATFORMS = x86 ppc arm
#will be test1x86 test2x86 ... test1ppc ... test3arm,
#so it is long way to enumarate all variants
VARIANTS = $(foreach c, $(CONFIGS), $(foreach p, $(PLATFORMS), $(c)$(p)))
#C FILE LIST
CFILES:=$(shell /bin/find -name "*.c")


.SECONDEXPANSION:

all: $(VARIANTS)

#More Comlex Rule
#Want to corresponding objects be in bins/test1x86/
OBJECTS:=$(CFILES:%.c=bins/$$(CFGNAME)%.o)


$(CONFIGS) : CFG_NAME=$@
$(CONFIGS) : $(OBJECTS) 
    @echo $(CFG_NAME) $@ from $^

#More complex prerequisites
#I understand that $$(CFGNAME) will be resolve incorrect.
#For each *.c file in subdir I would have object in corresponding path.
#For example, '1/2/3/test.c' will use for generate 
#object file 'bins/test1x86/1/2/3/test.o',
#when I call 'make testx86' or 'make all' (it will build all VARIANTS),
#in 'bins/test1x86/1/2/3/'.
#So what have I do?
$(OBJECTS): bins/$$(CFGNAME)_OBJECTS/%o : %.c
    @echo OBJECTS $@ from $^
    @echo DO IT

So, I would like to avoid recursive make calls. Can you help me?
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:06:40+00:00Added an answer on June 12, 2026 at 8:06 pm

    I’ve gotcha it.

    CONFIGS = test1 test2 test3
    PLATFORMS = p1 p2
    #Will be testp1 test1p2 .. test3p2
    VARIANTS = $(foreach c, $(CONFIGS), $(foreach p, $(PLATFORMS), $(c)$(p)))
    
    .SECONDEXPANSION:
    #.c files list in all subfolders
    cfiles = $(shell /bin/find -name "*.c")
    #objects for these .c files for custom VARIANT
    objects = $(patsubst %.c,%.o,$(addprefix bins/$1/,$(cfiles)))
    #Get .c source for object (e.g. bins/test1p1/tests/main_test.o => tests/main_test.c)
    get_src=$(shell echo $1 | sed 's/[^\/]*\/[^\/]*\/\(.*\)/\1.c/')
    
    #Build All Variants
    all: $(VARIANTS)
    
    #Build objects. Target list contains all objects for all variants.
    #Prerequisites get .c sources from the pattern rule for targets
    $(foreach v, $(VARIANTS), $(call objects,$(v))) : %.o : $$(call get_src,$$*)
        @echo OBJECTS $@ FROM $^
    
    #Variants rule, depends on objects 
    $(VARIANTS): $(call objects,$$@)
        @echo $@ from $^
    

    Thank you, Beta. You only have tried. 🙂
    Maybe anyone have style or efficiency suggestions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem. I have a function where I dynamically create <input />
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
I have a button which needs to get created dynamically but the problem is
so I have a problem with dynamically adding items to menuStrip. I mean I
I have a problem with adding OPTIONS to SELECT tag dynamically. Here is my
I am loading some text dynamically into a div, but have the problem that
Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
I have run into a strange problem, i am creating a lot of dynamically
Newbie here! My problem is as follows: I have a dynamically populating ul where
I have a weird problem and I find no answer on google... I dynamically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.