-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
38 lines (29 loc) · 773 Bytes
/
Makefile
File metadata and controls
38 lines (29 loc) · 773 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
# Compiler and flags
CC = gcc
CFLAGS = -Wall -I./include
# Directories
SRCDIR = src
INCLUDEDIR = include
EXAMPLESDIR = examples
BINDIR = bin
# Source files
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(patsubst $(SRCDIR)/%.c, $(BINDIR)/%.o, $(SRC))
# Example source files
EXAMPLES_SRC = $(wildcard $(EXAMPLESDIR)/*.c)
EXAMPLES_BIN = $(patsubst $(EXAMPLESDIR)/%.c, $(BINDIR)/%, $(EXAMPLES_SRC))
# Targets
all: $(OBJ) $(EXAMPLES_BIN)
# Build object files
$(BINDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Build example binaries
$(BINDIR)/%: $(EXAMPLESDIR)/%.c $(OBJ)
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $^ -o $@ -lm # Add -lm flag to link with the math library
.PHONY: clean
clean:
rm -rf $(BINDIR)
# Default target
.DEFAULT_GOAL := all