-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
44 lines (34 loc) · 1003 Bytes
/
Makefile
File metadata and controls
44 lines (34 loc) · 1003 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
# Compiler
CC := gcc
# Executable name
TARGET := bmm350_example.bin
# Source files
SRC_DIR1 := .
SRC_DIR2 := BMM350-SensorAPI/
# Compiler flags
CFLAGS := -Wall -Wextra -Iinclude -I${SRC_DIR2} -Wno-unused-parameter
SRCS1 := $(wildcard $(SRC_DIR1)/*.c)
SRCS2 := $(wildcard $(SRC_DIR2)/*.c)
# Object files
OBJ_DIR := build
OBJS1 := $(patsubst $(SRC_DIR1)/%.c, $(OBJ_DIR)/%.o, $(SRCS1))
OBJS2 := $(patsubst $(SRC_DIR2)/%.c, $(OBJ_DIR)/%.o, $(SRCS2))
# Default target
all: $(TARGET)
# Rule to build the executable
$(TARGET): $(OBJS1) $(OBJS2)
$(CC) $(CFLAGS) $^ -o $@ -lm
# Rule to build object files for source folder 1
$(OBJ_DIR)/%.o: $(SRC_DIR1)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Rule to build object files for source folder 2
$(OBJ_DIR)/%.o: $(SRC_DIR2)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create the object directory
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
# Clean rule
clean:
rm -rf $(OBJ_DIR) $(TARGET)
# Phony target to avoid conflicts with file names
.PHONY: all clean