Soy un nuevo miembro de makefiles y quiero crear directorios usando makefile. Mi directorio de proyecto es asíCrear directorios usando make file
+--Project
+--output
+--source
+Testfile.cpp
+Makefile
Quiero poner todos los objetos y la salida en la carpeta de salida respectiva. Quiero crear una estructura de carpetas que sería así después de compilar.
+--Project
+--output
+--debug (or release)
+--objs
+Testfile.o
+Testfile (my executable file)
+--source
+Testfile.cpp
+Makefile
he intentado con varias opciones, pero no podía tener éxito. Por favor, ayúdame a hacer directorios usando make file. Estoy publicando mi Makefile para su consideración.
#---------------------------------------------------------------------
# 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 $< -o [email protected]
$(OBJS): $(OUT_O_DIR)/%.o: %.cpp
@$(CC) -c $< -o [email protected]
title: $(DIR_TARGET) $(OBJS)
Gracias de antemano. Por favor guíame si cometí algún error también.
Gracias Jonathan. cuando probé recibí un error "make: *** No rule to make target 'output/debug', necesario para' directories '. Stop. " Pero no voy a preocuparme por eso ahora. se quedará con las reglas básicas. :). Gracias por guiarY estoy ejecutando "make" desde el directorio toplevel solamente. – Jabez
Simplemente elimine los $ {OUT_DIR} detrás de los directorios :, entonces debería funcionar. –
Funcionó. Gracias Doc. – Jabez