-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
86 lines (68 loc) · 1.63 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright (C) 2024 Ethan Uppal. All rights reserved.
#
# Purpose: builds and installs the libcmdapp library.
SRCDIR := src
INCLUDEDIR := src
CC := $(shell which gcc || which clang)
CFLAGS := -std=c99 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
CDEBUG := -g
CRELEASE := -O2
TARGET := cmdapp
CFLAGS += $(CRELEASE)
SRC := $(shell find $(SRCDIR) -type f -name "*.c")
OBJ := $(SRC:.c=.o)
PUBHEA := src/cmdapp.h src/proj.h
STATICLIB := lib$(TARGET).a
DYNLIB := lib$(TARGET).so
LCLLIBS := $(STATICLIB) $(DYNLIB)
INSTLIB := /usr/local/lib
INSTHEA := /usr/local/include/$(TARGET)
# NOT MY CODE
# Customizes ar for macOS
ifeq ($(shell uname), Darwin)
AR := /usr/bin/libtool
AR_OPT := -static
else
AR := ar
AR_OPT := rcs $@ $^
endif
all: static dynamic
static: $(STATICLIB)
dynamic: $(DYNLIB)
%.o: %.c
@echo 'Compiling $@'
$(CC) $(CFLAGS) $^ -c -o $@
clean:
rm -rf $(LCLLIBS) $(OBJ) test/main docs
$(STATICLIB): $(OBJ)
@echo 'Creating static $@'
$(AR) $(AR_OPT) $^ -o $@
$(DYNLIB): $(OBJ)
@echo 'Creating dynamic $@'
$(CC) $(CFLAGS) -shared $^ -o $@
install: $(LCLLIBS)
mkdir -p $(INSTLIB)
mkdir -p $(INSTHEA)
mv $(STATICLIB) $(INSTLIB)
mv $(DYNLIB) $(INSTLIB)
cp $(PUBHEA) $(INSTHEA)
uninstall:
rm -rf $(INSTLIB)/$(STATICLIB) \
$(INSTLIB)/$(DYNLIB) \
$(INSTHEA)
reinstall:
sudo make uninstall
sudo make install
# Requires doxygen to be installed.
# Link: https://www.doxygen.nl
.PHONY: docs
docs:
if ! command -v doxygen &> /dev/null; then \
echo "'doxygen' could not be found"; \
echo "You can install it from https://www.doxygen.nl"; \
exit; \
fi; \
doxygen
.PHONY: test
test:
@cd test; make test