This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (54 loc) · 1.78 KB
/
Makefile
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -Wpedantic -std=c99 -D_POSIX_C_SOURCE=200112L
# Directories
BUILD_DIR = build
COMMANDS_DIR = commands
CLI_DIR = CLI
INCLUDE_DIR = $(CLI_DIR)/include
SRC_DIR = $(CLI_DIR)/src
# Program name
PROGRAM_NAME = interpretador
# Find all source files in commands/
COMMAND_SOURCES := $(wildcard $(COMMANDS_DIR)/*.c)
# Object files for commands
COMMAND_OBJECTS := $(patsubst $(COMMANDS_DIR)/%.c,$(BUILD_DIR)/commands/%.o,$(COMMAND_SOURCES))
# Find all source files in CLI/src/
CLI_SOURCES := $(wildcard $(SRC_DIR)/*.c)
# Header files for the main program in CLI/
CLI_HEADERS := $(wildcard $(INCLUDE_DIR)/*.h)
# Object files for the main program
CLI_OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(CLI_SOURCES))
# Default rule to build the executable
$(PROGRAM_NAME): cli commands
# Rule to compile the CLI
.PHONY: cli
cli: $(CLI_OBJECTS)
$(CC) $(CFLAGS) $(CLI_OBJECTS) -o $(BUILD_DIR)/$(PROGRAM_NAME)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(CLI_HEADERS) | $(BUILD_DIR)
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -c -o $@
# Rule to compile each .c file in commands folder into separate executables
.PHONY: commands
commands: $(COMMAND_OBJECTS)
@for obj in $(COMMAND_OBJECTS); do \
exe=$$(basename $$obj .o); \
echo "Linking $$exe from $$obj"; \
$(CC) $(CFLAGS) $$obj -o $(BUILD_DIR)/commands/$$exe; \
done
# Pattern rule to compile .c files in commands directory into .o files
$(BUILD_DIR)/commands/%.o: $(COMMANDS_DIR)/%.c | $(BUILD_DIR)/commands
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -c -o $@
# Create build directories if they don't exist
$(BUILD_DIR)/commands:
mkdir -p $@
$(BUILD_DIR):
mkdir -p $@
# Rule to clean the project
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
# Delete build directory
.PHONY: cleanall
cleanall:
rm -rf $(BUILD_DIR)