-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (39 loc) · 1.21 KB
/
Copy pathMakefile
File metadata and controls
55 lines (39 loc) · 1.21 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
# Ring Buffer Library Makefile
# Author: subrata05
CC = gcc
CFLAGS = -Wall -Wextra -Werror -std=c11 -O2 -Iinclude
DEBUG_CFLAGS = -g -O0 -DDEBUG
SRC_DIR = src
INC_DIR = include
TEST_DIR = tests
EXAMPLE_DIR = examples
BUILD_DIR = build
SOURCES = $(SRC_DIR)/ring_buffer.c
OBJECTS = $(BUILD_DIR)/ring_buffer.o
TEST_SOURCES = $(TEST_DIR)/test_ring_buffer.c
EXAMPLE_SOURCES = $(EXAMPLE_DIR)/example_usage.c
# targets
.PHONY: all clean test example debug static
all: $(BUILD_DIR) $(BUILD_DIR)/test_ring_buffer $(BUILD_DIR)/example_usage
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/ring_buffer.o: $(SRC_DIR)/ring_buffer.c $(INC_DIR)/ring_buffer.h
$(CC) $(CFLAGS) -c $< -o $@
# test executable
$(BUILD_DIR)/test_ring_buffer: $(TEST_SOURCES) $(OBJECTS)
$(CC) $(CFLAGS) $^ -o $@
# example executable
$(BUILD_DIR)/example_usage: $(EXAMPLE_SOURCES) $(OBJECTS)
$(CC) $(CFLAGS) $^ -o $@
debug: CFLAGS += $(DEBUG_CFLAGS)
debug: all
test: $(BUILD_DIR)/test_ring_buffer
./$(BUILD_DIR)/test_ring_buffer
example: $(BUILD_DIR)/example_usage
./$(BUILD_DIR)/example_usage
clean:
rm -rf $(BUILD_DIR) .gdb_history
# static library
$(BUILD_DIR)/libringbuffer.a: $(OBJECTS)
ar rcs $@ $^
static: $(BUILD_DIR) $(BUILD_DIR)/libringbuffer.a