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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:52:23+00:00 2026-05-15T19:52:23+00:00

From the command line you can make multiple directories like so: mkdir -p build/linux/{src,test,debug}

  • 0

From the command line you can make multiple directories like so:

mkdir -p build/linux/{src,test,debug}

How can the same thing be achieved from a Makefile? I’ve come up with this:

# The architecture/OS to compile for
ARCH        := linux

# Object files go here, under the architecture/OS directory
BUILD_DIR   := build/$(ARCH)

# List of source code directories
SOURCES     := src test debug

# e.g. The object files for 
# src/foo.c  test/bar.c  debug/bort.c
# will be in
# build/$(ARCH)/src/foo.o
# build/$(ARCH)/test/bar.o
# build/$(ARCH)/debug/bort.o

# Make a comma separated list of the source directories
# Is there a more concise way of doing this?
comma       :=,
empty       :=
space       := $(empty) $(empty)
DIRECTORIES := $(subst $(space),$(comma),$(SOURCES))

default:
    mkdir -p $(BUILD_DIR)/{$(DIRECTORIES)}

clean:
    rm -fr $(BUILD_DIR)

Which just makes one directory called ‘{src,test,debug}’ instead of three distinct directories.

$ make
mkdir -p build/linux/{src,test,debug}
$ ls build/linux/
{src,test,debug}
$ make clean
rm -fr build/linux
$ mkdir -p build/linux/{src,test,debug}
$ ls build/linux/
debug  src  test

I suspect the problem might be with/around the curly brackets… What am I doing wrong?

Edit: It does seem to be the shell make uses. The example at the top was in bash, but sh fails:

$ sh
$ mkdir -p build/linux/{src,test,debug}
$ ls build/linux
{src,test,debug}
  • 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-15T19:52:23+00:00Added an answer on May 15, 2026 at 7:52 pm

    I believe the problem is that make is invoking a shell that does not support the {} syntax. You can replace your rule with a simpler, more portable rule:

            for p in $(SOURCES); do mkdir -p $(BUILD_DIR)/$$p; done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I run from command line program created by Eclipse? I am
Is there anyway we can take input from command line in Objective-C, the way
How can I delete the hidden cropped elements from a pdf from command line?
As I know, when I run cs myConsoleApp.cs from windows command line, I can
How can I execute a command line from within a WiX script? I want
I can import MySQLdb from the interactive python command line but Zope gives me
I want to run coverage from the command line, but can't seem to get
How can I make xargs execute the command exactly once for each line of
From the command line, I can run rake db:migrate:up VERSION=20120123160700 This will migrate up
From command line I can't import appengine, this might be something with my 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.