jahan-addison revisou este gist . Ir para a revisão
Sem alterações
jahan-addison revisou este gist . Ir para a revisão
1 file changed, 75 insertions
Makefile(arquivo criado)
| @@ -0,0 +1,75 @@ | |||
| 1 | + | ############################## | |
| 2 | + | # Generic C++ Makefile for small to medium projects | |
| 3 | + | # Your should have a "build", a "test", folder, and your code inside a folder of the same name. | |
| 4 | + | # | |
| 5 | + | # Production-ready executables can go in "apps" folder. | |
| 6 | + | ############################## | |
| 7 | + | ||
| 8 | + | CXX := -g++ | |
| 9 | + | CXXFLAGS := -pedantic-errors -std=c++20 -Wall -Wextra -Werror | |
| 10 | + | LDFLAGS := -L/usr/lib -lstdc++ -lm | |
| 11 | + | BUILD := ./build | |
| 12 | + | NAME := Foobar # replace | |
| 13 | + | APP_DIR := $(BUILD)/apps | |
| 14 | + | TEST_DIR := ./test | |
| 15 | + | OBJ_DIR := $(BUILD)/objects | |
| 16 | + | TARGET := program | |
| 17 | + | INCLUDE := -I. | |
| 18 | + | SRC := \ | |
| 19 | + | $(wildcard $(NAME)/*.cc) \ | |
| 20 | + | ||
| 21 | + | TEST := \ | |
| 22 | + | $(wildcard test/*.cc) \ | |
| 23 | + | ||
| 24 | + | OBJECTS := $(SRC:%.cc=$(OBJ_DIR)/%.o) | |
| 25 | + | DEPENDENCIES \ | |
| 26 | + | := $(OBJECTS:.o=.d) | |
| 27 | + | ||
| 28 | + | TESTS := $(TEST:%.cc=$(OBJ_DIR)/%.o) | |
| 29 | + | DEPENDENCIES \ | |
| 30 | + | := $(TESTS:.o=.d) | |
| 31 | + | ||
| 32 | + | ||
| 33 | + | all: build $(APP_DIR)/$(TARGET) | |
| 34 | + | ||
| 35 | + | test: build $(TEST_DIR)/$(TARGET) | |
| 36 | + | ./test/test_runner | |
| 37 | + | @rm -f ./test/test_runner | |
| 38 | + | ||
| 39 | + | $(OBJ_DIR)/%.o: %.cc | |
| 40 | + | @mkdir -p $(@D) | |
| 41 | + | $(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@ | |
| 42 | + | ||
| 43 | + | $(APP_DIR)/$(TARGET): $(OBJECTS) | |
| 44 | + | @mkdir -p $(@D) | |
| 45 | + | $(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS) | |
| 46 | + | ||
| 47 | + | $(TEST_DIR)/$(TARGET): $(OBJECTS) $(TESTS) | |
| 48 | + | @mkdir -p $(@D) | |
| 49 | + | $(CXX) $(CXXFLAGS) -o $(TEST_DIR)/test_runner $^ $(LDFLAGS) | |
| 50 | + | ||
| 51 | + | ||
| 52 | + | -include $(DEPENDENCIES) | |
| 53 | + | ||
| 54 | + | .PHONY: all build clean debug release info test | |
| 55 | + | ||
| 56 | + | build: | |
| 57 | + | @mkdir -p $(APP_DIR) | |
| 58 | + | @mkdir -p $(OBJ_DIR) | |
| 59 | + | ||
| 60 | + | debug: CXXFLAGS += -DDEBUG -g | |
| 61 | + | debug: all | |
| 62 | + | ||
| 63 | + | release: CXXFLAGS += -O2 | |
| 64 | + | release: all | |
| 65 | + | ||
| 66 | + | clean: | |
| 67 | + | -@rm -rvf $(OBJ_DIR)/* | |
| 68 | + | -@rm -rvf $(APP_DIR)/* | |
| 69 | + | ||
| 70 | + | info: | |
| 71 | + | @echo "[*] Application dir: ${APP_DIR} " | |
| 72 | + | @echo "[*] Object dir: ${OBJ_DIR} " | |
| 73 | + | @echo "[*] Sources: ${SRC} " | |
| 74 | + | @echo "[*] Objects: ${OBJECTS} " | |
| 75 | + | @echo "[*] Dependencies: ${DEPENDENCIES}" | |
Próximo
Anterior