-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
78 lines (63 loc) · 1.81 KB
/
Makefile
File metadata and controls
78 lines (63 loc) · 1.81 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
# Makefile for c-argparse library
# Portable build system for Linux/macOS/Windows (MinGW)
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -pedantic -I./include
LDFLAGS =
# Directories
SRC_DIR = src
INCLUDE_DIR = include
EXAMPLES_DIR = examples
TESTS_DIR = tests
BUILD_DIR = build
# Library source files
LIB_SRCS = $(SRC_DIR)/argparse.c
LIB_OBJS = $(BUILD_DIR)/argparse.o
# Example source files
EXAMPLE_SRCS = $(wildcard $(EXAMPLES_DIR)/*.c)
EXAMPLE_BINS = $(patsubst $(EXAMPLES_DIR)/%.c,$(BUILD_DIR)/%,$(EXAMPLE_SRCS))
# Test source files
TEST_SRCS = $(wildcard $(TESTS_DIR)/*.c)
TEST_BINS = $(patsubst $(TESTS_DIR)/%.c,$(BUILD_DIR)/%,$(TEST_SRCS))
# Default target
.PHONY: all
all: $(BUILD_DIR) $(LIB_OBJS) examples tests
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Build library object file
$(BUILD_DIR)/argparse.o: $(SRC_DIR)/argparse.c $(INCLUDE_DIR)/argparse.h
$(CC) $(CFLAGS) -c $< -o $@
# Build examples
.PHONY: examples
examples: $(EXAMPLE_BINS)
$(BUILD_DIR)/%: $(EXAMPLES_DIR)/%.c $(LIB_OBJS)
$(CC) $(CFLAGS) $< $(LIB_OBJS) $(LDFLAGS) -o $@
# Build tests
.PHONY: tests
tests: $(TEST_BINS)
$(BUILD_DIR)/%: $(TESTS_DIR)/%.c $(LIB_OBJS)
$(CC) $(CFLAGS) $< $(LIB_OBJS) $(LDFLAGS) -o $@
# Run tests
.PHONY: test
test: tests
@echo "Running tests..."
@for test in $(TEST_BINS); do \
echo "Running $$test..."; \
$$test || exit 1; \
done
@echo "All tests passed!"
# Clean build artifacts
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
# Help target
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Build library, examples, and tests (default)"
@echo " examples - Build example programs"
@echo " tests - Build test programs"
@echo " test - Build and run all tests"
@echo " clean - Remove all build artifacts"
@echo " help - Show this help message"