-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (50 loc) · 1.51 KB
/
Copy pathMakefile
File metadata and controls
63 lines (50 loc) · 1.51 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
# liblinht-ctrl Makefile
# Overrideable variables for Yocto compatibility
CC ?= gcc
CFLAGS ?= -Wall -Wextra -O2 -fPIC -Iinclude
LDFLAGS ?= -lgpiod
PREFIX ?= /usr
# Library files
LIB_NAME = liblinht-ctrl
STATIC_LIB = $(LIB_NAME).a
SHARED_LIB = $(LIB_NAME).so
# Source files
SOURCES = src/gpio.c src/pwm.c src/backlight.c src/attenuator.c
OBJECTS = $(SOURCES:.c=.o)
HEADERS = include/liblinht-ctrl.h
# Default target
all: $(STATIC_LIB) $(SHARED_LIB)
# Static library
$(STATIC_LIB): $(OBJECTS)
ar rcs $@ $^
# Shared library
$(SHARED_LIB): $(OBJECTS)
$(CC) -shared -o $@ $^ $(LDFLAGS)
# Object files
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
# Clean build artifacts
clean:
rm -f $(OBJECTS) $(STATIC_LIB) $(SHARED_LIB) example example_atten
# Install headers and libraries (optimized for Yocto and standalone)
install: $(STATIC_LIB) $(SHARED_LIB)
mkdir -p $(DESTDIR)$(PREFIX)/include/
mkdir -p $(DESTDIR)$(PREFIX)/lib/
cp $(HEADERS) $(DESTDIR)$(PREFIX)/include/
cp $(STATIC_LIB) $(SHARED_LIB) $(DESTDIR)$(PREFIX)/lib/
ifndef DESTDIR
ldconfig
endif
# Uninstall (adjusted for prefix)
uninstall:
rm -f $(DESTDIR)$(PREFIX)/include/liblinht-ctrl.h
rm -f $(DESTDIR)$(PREFIX)/lib/$(STATIC_LIB) $(DESTDIR)$(PREFIX)/lib/$(SHARED_LIB)
ifndef DESTDIR
ldconfig
endif
# Example programs
example: example.c $(STATIC_LIB)
$(CC) $(CFLAGS) -o $@ $< -L. -llinht-ctrl $(LDFLAGS)
example_atten: example_atten.c $(STATIC_LIB)
$(CC) $(CFLAGS) -o $@ $< -L. -llinht-ctrl $(LDFLAGS)
.PHONY: all clean install uninstall example example_atten