-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (49 loc) · 1.37 KB
/
Makefile
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
CC=gcc
CFLAGS=-Wall -Wextra -pedantic -I./include
DEFINES=
LIBS=-lm
SRCDIR=src
EXAMPLESDIR=examples
BUILDDIR=build
SRC=$(SRCDIR)/mgl.c
ifeq ($(PLATFORM),RPI_PICO)
$(error Unimplemented)
else ifeq ($(PLATFORM),WIRINGPI)
$(error Unimplemented)
else
$(warning Platform not specified, \
building for generic platform \
without an actual implementation)
SRC += $(SRCDIR)/mgl_platform_generic.c
endif
ifeq ($(PREFIX),)
PREFIX := /usr
endif
OBJ=$(patsubst $(SRCDIR)/%.c, $(BUILDDIR)/%.o, $(SRC))
EXAMPLES=$(wildcard $(EXAMPLESDIR)/*.c)
EXAMPLESOBJ=$(patsubst $(EXAMPLESDIR)/%.c, $(BUILDDIR)/%, $(EXAMPLES))
HEADERNAME=mgl.h
HEADER=include/$(HEADERNAME)
BINARYNAME=libmgl.so
BINARY=$(BUILDDIR)/$(BINARYNAME)
all: always $(BINARY)
$(BINARY): $(BUILDDIR)/$(OBJ)
$(CC) $(CFLAGS) -shared $(OBJ) -o $(BINARY) $(LIBS)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(DEFINES) -c -fpic $< -o $@
examples: always $(EXAMPLES:.c=)
%: %.c
$(CC) $(CFLAGS) $(DEFINES) -o $(BUILDDIR)/$@ $< -lmgl
always:
mkdir -p $(BUILDDIR)
mkdir -p $(BUILDDIR)/examples
install: $(BINARY)
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 $(BINARY) $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/
install -m 644 $(HEADER) $(DESTDIR)$(PREFIX)/include/
uninstall: $(BINARY)
rm $(DESTDIR)$(PREFIX)/lib/$(BINARYNAME)
rm $(DESTDIR)$(PREFIX)/include/$(HEADERNAME)
clean:
rm -rf $(BUILDDIR)