Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate directories using make file
    text
    copied!<p>I'm a very new to makefiles and i want to create directories using makefile. My project directory is like this</p> <pre><code>+--Project +--output +--source +Testfile.cpp +Makefile </code></pre> <p>I want to put all the objects and output into the respective output folder. I want to create folder structure which would be like this after compiling.</p> <pre><code>+--Project +--output +--debug (or release) +--objs +Testfile.o +Testfile (my executable file) +--source +Testfile.cpp +Makefile </code></pre> <p>I tried with several options, but could not succeed. Please help me to make directories using make file. I'm posting my Makefile for your consideration.</p> <pre><code>#--------------------------------------------------------------------- # Input dirs, names, files #--------------------------------------------------------------------- OUTPUT_ROOT := output/ TITLE_NAME := TestProj ifdef DEBUG TITLE_NAME += _DEBUG else ifdef RELEASE TITLE_NAME += _RELEASE endif endif # Include all the source files here with the directory tree SOURCES := \ source/TestFile.cpp \ #--------------------------------------------------------------------- # configs #--------------------------------------------------------------------- ifdef DEBUG OUT_DIR := $(OUTPUT_ROOT)debug CC_FLAGS := -c -Wall else ifdef RELEASE OUT_DIR := $(OUTPUT_ROOT)release CC_FLAGS := -c -Wall else $(error no build type defined) endif endif # Put objects in the output directory. OUT_O_DIR := $(OUT_DIR)/objs #--------------------------------------------------------------------- # settings #--------------------------------------------------------------------- OBJS = $(SOURCES:.cpp=.o) DIRS = $(subst /,/,$(sort $(dir $(OBJS)))) DIR_TARGET = $(OUT_DIR) OUTPUT_TARGET = $(OUT_DIR)/$(TITLE_NAME) CC_FLAGS += LCF_FLAGS := LD_FLAGS := #--------------------------------------------------------------------- # executables #--------------------------------------------------------------------- MD := mkdir RM := rm CC := g++ #--------------------------------------------------------------------- # rules #--------------------------------------------------------------------- .PHONY: all clean title all: title clean: $(RM) -rf $(OUT_DIR) $(DIR_TARGET): $(MD) -p $(DIRS) .cpp.o: @$(CC) -c $&lt; -o $@ $(OBJS): $(OUT_O_DIR)/%.o: %.cpp @$(CC) -c $&lt; -o $@ title: $(DIR_TARGET) $(OBJS) </code></pre> <p>Thanks in advance. Please guide me if i made any mistakes also. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload