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 7790965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:44:47+00:00 2026-06-01T21:44:47+00:00

Suppose we have client-server application, compiling by one makefile. Server uses libtask for parallel

  • 0

Suppose we have client-server application, compiling by one makefile. Server uses libtask for parallel clients serving. Client uses ncurses for some graphic.
directory tree looks like this:

./
--bin/
--obj/
--src/
----client/*.c
----server/*.c
--makefile

So, here is makefile. Can we simplify it? I read some related questions on stackoverflow and I think it almost ideal, except of linking binaries, when we can see repeated commands. Some suggestions for style/cross-platform working will be useful. Thank you!

.PHONY: all clean

TASKLIB = -ltask
CURSESLIB = -lncurses
CFLAGS = -Wall -Werror -pedantic

bin = server client
obj_dir = obj
bin_dir = bin
ssource := src/server
csource := src/client
search_wildcard s := $(addsuffix /*.c, $(ssource))
search_wildcard c := $(addsuffix /*.c, $(csource))
sobjs = $(addprefix $(obj_dir)/, $(patsubst %.c, %.o, $(notdir $(wildcard $(search_wildcard s)))))
cobjs = $(addprefix $(obj_dir)/, $(patsubst %.c, %.o, $(notdir $(wildcard $(search_wildcard c)))))

all: $(bin)
    @echo "done!"

server: CFLAGS+=$(TASKLIB)
client: CFLAGS+=$(CURSESLIB)

clean:
    rm $(sobjs) $(cobjs) $(obj_dir)/*.d $(bin_dir)/client $(bin_dir)/server

VPATH := $(ssource) $(csource)

server: $(sobjs)
    @test -d $(bin_dir) || mkdir $(bin_dir)
    @echo "Linking $(@F)..."
    @$(CC) $< $(CFLAGS) -o $(bin_dir)/$@

client: $(cobjs)
    @test -d $(bin_dir) || mkdir $(bin_dir)
    @echo "Linking $(@F)..."
    @$(CC) $< $(CFLAGS) -o $(bin_dir)/$@

$(obj_dir)/%.o: %.c
    @test -d $(obj_dir) || mkdir $(obj_dir)
    @echo "Compiling $(@F)..."
    @$(CC) $< $(CFLAGS) -c -MD -o $@

include $(wildcard $(obj_dir)/*.d)
  • 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-01T21:44:48+00:00Added an answer on June 1, 2026 at 9:44 pm

    You’re probably more general than you need to be: For example, I wouldn’t make the directories configurable – that only makes sense for destinations of an install target.

    Anyway, this is how I would write your makefile (untested):

    CFLAGS := -Wall -Werror -pedantic
    RM := rm -f
    MKDIR := mkdir -p
    
    BINARIES := bin/server bin/client
    SERVER_OBJECTS := $(patsubst src/%.c, obj/%.o, $(wildcard src/server/*.c))
    CLIENT_OBJECTS := $(patsubst src/%.c, obj/%.o, $(wildcard src/client/*.c))
    OBJECTS := $(SERVER_OBJECTS) $(CLIENT_OBJECTS)
    
    .PHONY : build clean realclean
    
    build : $(BINARIES)
    
    clean :
        $(RM) $(OBJECTS) $(OBJECTS:%.o=%.d)
    
    realclean : clean
        $(RM) $(BINARIES)
    
    bin/server : LDLIBS := -ltask
    bin/client : LDLIBS := -lncurses
    
    bin/server : $(SERVER_OBJECTS)
    bin/client : $(CLIENT_OBJECTS)
    
    $(BINARIES) :
        @$(MKDIR) $(dir $@)
        $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
    
    include $(wildcard obj/*.d)
    
    $(OBJECTS) : obj/%.o : src/%.c
        @$(MKDIR) $(dir $@)
        $(CC) $(CFLAGS) -c -MD -o $@ $<
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have a client/server application, say a webserver component and a qt gui.
I am wondering how this is done.Suppose i have a client application and it
Ok, I have developed this WinForms client, which interacts with a server (ASPX Application)
Suppose I have an application that access data resident in a central DB server
I have a client server application in which the communication between the client and
Suppose we have an application (on a server) that has a set of resources:
One of my client has backend server without any webservices but my iOS application
Lets suppose I have an .NET client application that connects to a WCF service,
I have Chat Client Server Application, which we are scaling up. so I need
In our application we have a server which will connect to multiple clients. For

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.