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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:33:50+00:00 2026-05-20T09:33:50+00:00

I’ve got several directories with subdirectories containing c or asm files and I want

  • 0

I’ve got several directories with subdirectories containing c or asm files and I want them all compiled/assembled and then linked. I’m not especially picky where the object files go (e.g. a special bin folder or in the src folder) as long as a make clean removes them all.

The structure would look something like this:

/src
    /dir1
        /dir1_1
            +file1_1.s
            +file1_2.s
        +file1.s
    /dir2
        +file2.c

I’m sure there’s some easy way to create a makefile that compiles all files without me having to specify where it should look (compiling all files in one directory is doable with wildcards, but what then?).

  • 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-20T09:33:51+00:00Added an answer on May 20, 2026 at 9:33 am

    If your project is small enough, you might get away with using a single hand-crafted makefile instead of a more sophisticated build system: check out the manual page on transformation functions to see what’s possible.

    Your example project could be compiled with the following non-recursive makefile:

    targets = $(patsubst %$(1),%$(2),$(foreach dir,$(3),$(wildcard $(dir)/*$(1))))
    
    asmdirs := src/dir1 src/dir1/dir1_1
    cdirs := src/dir2
    
    asmobjects := $(call targets,.s,.o,$(asmdirs))
    cobjects := $(call targets,.c,.o,$(cdirs))
    
    .PHONY : all clean
    
    all : $(asmobjects) $(cobjects)
    
    clean :
        rm -f $(asmobjects) $(cobjects)
    
    $(cobjects) : %.o : %.c
        gcc -o $@ -c $<
    
    $(asmobjects) : %.o : %.s
        gcc -o $@ -c $<
    

    However, because make can access the shell, you could also use standard unix tools like find instead of the somewhat limited builtin functions, eg

    asmsources := $(shell find src -name '*.s')
    csources := $(shell find src -name '*.c')
    
    asmobjects := $(asmsources:.s=.o)
    cobjects := $(csources:.c=.o)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.