-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
46 lines (35 loc) · 1.1 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
CC = gcc
CFLAGS = -Wall -Wextra -g
# -fsanitize=address
SRCDIR = .
TARGETDIR = target
# Source files
EXAMPLE_SRC = $(SRCDIR)/example.c
NN_SRC = $(SRCDIR)/train_nn.c
COMMON_SRCS = $(wildcard $(SRCDIR)/*.c) # All other .c files as common sources
# Filter out specific main source files from COMMON_SRCS
COMMON_SRCS := $(filter-out $(EXAMPLE_SRC) $(NN_SRC), $(COMMON_SRCS))
# Object files
ENGINE_OBJS = $(EXAMPLE_SRC:.c=.o) $(COMMON_SRCS:.c=.o)
MODEL_OBJS = $(NN_SRC:.c=.o) $(COMMON_SRCS:.c=.o)
# Executable names
TARGET1 = $(TARGETDIR)/example
TARGET2 = $(TARGETDIR)/train_nn
.PHONY: all clean
# Build both executables
all: $(TARGET1) $(TARGET2)
# Rule for the first executable (runEngine.c)
$(TARGET1): $(ENGINE_OBJS) | $(TARGETDIR)
$(CC) $(CFLAGS) $(ENGINE_OBJS) -o $@ -lm
# Rule for the second executable (runModel.c)
$(TARGET2): $(MODEL_OBJS) | $(TARGETDIR)
$(CC) $(CFLAGS) $(MODEL_OBJS) -o $@ -lm
# Ensure the target directory exists
$(TARGETDIR):
mkdir -p $(TARGETDIR)
# Rule to compile object files
%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up generated files
clean:
rm -rf $(TARGETDIR) *.o