-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
78 lines (63 loc) · 2.97 KB
/
Makefile
File metadata and controls
78 lines (63 loc) · 2.97 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# =============================================================================
# SCRAP Makefile
# =============================================================================
CC = gcc
CFLAGS_C89 = -std=c89 -Wall -Wextra -Werror -pedantic
CFLAGS_C99 = -std=c99 -Wall -Wextra -Werror -Wno-unused-function
SRC_DIR = src
TESTS_DIR = tests
DIST_DIR = dist
BUILD_DIR = build
EXAMPLES_DIR = examples
COMMON_DIR = $(EXAMPLES_DIR)/common
FILE_TRANSFER_DIR = $(EXAMPLES_DIR)/file_transfer
INCLUDE_PATHS = -I$(SRC_DIR) -I$(COMMON_DIR)
# Test configuration
TEST_DEFINES = -DSCRAP_MAX_PACKET_PAYLOAD=64 -DSCRAP_MAX_CHANNELS=4 -DSCRAP_MAX_WINDOW_SIZE=4
# =============================================================================
# Default target
# =============================================================================
all: check test dist
# =============================================================================
# Syntax check (C89 strict)
# =============================================================================
check:
@echo "=== C89 syntax check (P2P) ==="
$(CC) $(CFLAGS_C89) -fsyntax-only $(SRC_DIR)/scrap.c
@echo "=== C89 syntax check (BUS) ==="
$(CC) $(CFLAGS_C89) -DSCRAP_ENABLE_ADDRESSING -fsyntax-only $(SRC_DIR)/scrap.c
@echo "All checks passed."
# =============================================================================
# Unit tests
# =============================================================================
test: $(BUILD_DIR)/test_scrap
@echo "=== Running C tests ==="
./$(BUILD_DIR)/test_scrap
@echo ""
@echo "=== Running Python tests ==="
python3 $(EXAMPLES_DIR)/python/loopback_test.py
$(BUILD_DIR)/test_scrap: $(TESTS_DIR)/test_scrap.c $(SRC_DIR)/scrap.c $(SRC_DIR)/scrap.h
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS_C99) $(TEST_DEFINES) -I$(SRC_DIR) -o $@ $(TESTS_DIR)/test_scrap.c $(SRC_DIR)/scrap.c
# =============================================================================
# Amalgamated single-header (dist/scrap.h)
# =============================================================================
dist: $(DIST_DIR)/scrap.h
$(DIST_DIR)/scrap.h: $(SRC_DIR)/scrap.h $(SRC_DIR)/scrap.c tools/amalgamate.py
python3 tools/amalgamate.py
# =============================================================================
# Examples
# =============================================================================
examples: $(BUILD_DIR)/host_uploader $(BUILD_DIR)/device_downloader
$(BUILD_DIR)/host_uploader: $(FILE_TRANSFER_DIR)/host_uploader.c $(SRC_DIR)/scrap.c $(COMMON_DIR)/common.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS_C99) $(INCLUDE_PATHS) -o $@ $^
$(BUILD_DIR)/device_downloader: $(FILE_TRANSFER_DIR)/device_downloader.c $(SRC_DIR)/scrap.c $(COMMON_DIR)/common.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS_C99) $(INCLUDE_PATHS) -o $@ $^
# =============================================================================
# Clean
# =============================================================================
clean:
rm -rf $(BUILD_DIR)
.PHONY: all check test dist examples clean