-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
47 lines (35 loc) · 996 Bytes
/
Copy pathmakefile
File metadata and controls
47 lines (35 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
TARGET ?= main
BUILD_DIR ?= build
SRC_DIRS ?= srcs
SRC_EXT := c
MKDIR_P ?= mkdir -p
# busca sources em srcs e subdiretorios
SRCS :=$(shell find $(SRC_DIRS) -type f -name *.$(SRC_EXT) )
# define objects
OBJS := $(patsubst $(SRC_DIRS)/%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.o))
# busca includes em srcs e subdiretorios
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
# prepara as include-flags
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# prepara as flags do compilador
CFLAGS ?= $(INC_FLAGS) -Wall
# Linking
$(BUILD_DIR)/$(TARGET):$(OBJS)
@echo "Linking ..."
@echo "gcc $^ -o $@";gcc $^ -o $@
# Compiling
$(BUILD_DIR)/%.o:$(SRC_DIRS)/%.c
@mkdir -p $(dir $@)
@echo "compiling ... $@"
@echo "gcc $(CFLAGS) -c -o $@ $< ";gcc $(CFLAGS) -c -o $@ $<
.PHONY: clean vars run
clean:
-rm -r $(BUILD_DIR)
run:
./$(BUILD_DIR)/$(TARGET)
vars:
@echo "SRCS...: $(SRCS)"
@echo "OBJS...: $(OBJS)"
@echo "INC_DIRS...: $(INC_DIRS)"
@echo "INC_FLAGS...: $(INC_FLAGS)"
@echo "CFLAGS...: $(CFLAGS)"