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

  • Home
  • SEARCH
  • 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 326275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:17:39+00:00 2026-05-12T09:17:39+00:00

all. Let’s say I have a program that contains a long list of C

  • 0

all. Let’s say I have a program that contains a long list of C source files, A.c, B.c, …., Z.c, now I want to compile A.c, B.c with certain CFLAGS, and compile the rest part of source files with a different CFLAGS value.

How to write a Makefile to do the above described job? currently what I am doing in my Makefile is:

OBJ=[all other .o files here, e.g. D.o, D.o, E.o .... Z.o]
SPECIAL_OBJS=A.o B.o

all: $(OBJ) $(SPECIAL_OBJS)

$(SPECIAL_OBJS): 
     @echo [Compiling]: $(@:.o=.c)
     $(CC) [SOME OTHER GCC OPTIONS HERE] $(CFLAGS) -c $(@:.o=.c) -o $@

%.o: %.c
     @echo [Compiling]: $<
     $(CC) $(CFLAGS) -o $@ -c $<

It works, but looks just stupid/complicated. Can anyone help to point out what is the recommended way of doing this in Makefile? thanks!

  • 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-05-12T09:17:39+00:00Added an answer on May 12, 2026 at 9:17 am

    Try using target-specific variables. A target-specific variable is declared like this:

    TARGET: VAR := foo  # Any valid form of assignment may be used ( =, :=, +=, ?=)
    

    Now when the target named TARGET is being made, the variable named VAR will have the value “foo”.

    Using target-specific variables, you could do this, for example:

    OBJ=[all other .o files here, e.g. D.o, D.o, E.o .... Z.o]
    SPECIAL_OBJS=A.o B.o
    
    all: $(OBJ) $(SPECIAL_OBJS)
    
    $(SPECIAL_OBJS): EXTRA_FLAGS := -std=c99   # Whatever extra flags you need
    
    %.o: %.c
         @echo [Compiling]: $<
         $(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $@ -c $<
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have multiple directories that all exist on the same partition. Let's
First of all let me say thank you to everyone that offered answers...I have
First of all let me tell you that i have read the following questions
Let's say i need to find all .bar elements inside an element that's assigned
Let's say I started a thread and I have something like this: ...//initiate all
first of all please let me say that I am quite new to objective
first of all let me say that I know about dynamic, no PIA, named
First of all let me explain that I have searched for at least an
I have quick question for you all :) Let's say we have an eshop
Hi there First of all just let me say that I'm new in Python

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.