-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (48 loc) · 1.17 KB
/
Copy pathMakefile
File metadata and controls
62 lines (48 loc) · 1.17 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
# Makefile for SPI communication library
# Enables compilation and installation of the static library
# Compiler and parameters
CC = clang
CFLAGS = -Wall -O2
AR = ar
ARFLAGS = rcs
# Installation paths - local user directories
PREFIX = $(HOME)
LIBDIR = $(PREFIX)/lib
INCLUDEDIR = $(PREFIX)/include
# Library files
LIB_NAME = spi
LIB_STATIC = lib$(LIB_NAME).a
SRC = spi_base.c
OBJ = $(SRC:.c=.o)
HDR = spi_base.h
# Default target - only static library
all: $(LIB_STATIC)
# Compile .c to .o
%.o: %.c $(HDR)
$(CC) $(CFLAGS) -c $< -o $@
# Create static library
$(LIB_STATIC): $(OBJ)
$(AR) $(ARFLAGS) $@ $^
# Install the library to local directories
install: all
mkdir -p $(LIBDIR)
mkdir -p $(INCLUDEDIR)
cp $(LIB_STATIC) $(LIBDIR)/
cp $(HDR) $(INCLUDEDIR)/
# Uninstall the library
uninstall:
rm -f $(LIBDIR)/$(LIB_STATIC)
rm -f $(INCLUDEDIR)/$(HDR)
# Clean
clean:
rm -f $(OBJ) $(LIB_STATIC)
# Example usage
EXAMPLE = spi_example
EXAMPLE_SRC = example.c
example: $(EXAMPLE)
$(EXAMPLE): $(EXAMPLE_SRC) $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< -L. -l$(LIB_NAME)
clean-example:
rm -f $(EXAMPLE)
# Targets that are not files
.PHONY: all clean install uninstall example clean-example