-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (43 loc) · 1.42 KB
/
Makefile
File metadata and controls
64 lines (43 loc) · 1.42 KB
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
# Copyright © 2019 Giacomo Rosin
# The binary file generated by this Makefile is named vm.out
# All the file (.o / .d) generated by the compilation process are put into the build dir
CC = gcc
# CC = clang
# CFLAGS = -std=gnu89 -g3 -pedantic-errors -Wall -Wextra
CFLAGS = -std=gnu89 -g3 -pedantic-errors -Wall -Wextra -fsanitize=address -fsanitize=undefined
# Include path
INCLUDES = -I "./include"
# Final binary
BIN = vm.out
# Put all auto generated stuff to this build dir
BUILD_DIR = ./build
# Source code path
SOURCE_DIR = ./src
# List of all .c source files
SOURCES = $(wildcard $(SOURCE_DIR)/*.c)
# All the .o files go to build dir
OBJECTS = $(patsubst $(SOURCE_DIR)/%.c,$(BUILD_DIR)/%.o, $(SOURCES))
# Gcc/Clang will create this .d files containing dependencies
DEP = $(OBJECTS:%.o=%.d)
# Final binary - depends on all .o files
$(BIN) : $(OBJECTS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $^ -o $@
# Include all .d files
-include $(DEP)
# Build all the object files from .c files
# The potential dependency on header files is covered
# by calling '-include $(DEP)'
# The -MMD flags additionaly creates a .d files
$(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDES) -MMD -c $< -o $@
.PHONY : clean check
clean :
rm -rf $(BUILD_DIR)
rm -rf $(BIN)
# Automated tests (probably not the best way do them)
check : $(BIN)
$(CC) $(CFLAGS) test/automated-test/auto-test.c -o test.out
./test.out
rm -rf test.out