This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
91 lines (74 loc) · 1.73 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
87
88
89
90
91
# Copyright (C) 2023 Ethan Uppal. All rights reserved.
#
# Purpose: builds and installs the config library.
SRCDIR := .
INCLUDEDIR := .
CC := $(shell which gcc || which clang)
CFLAGS := -std=c99 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
CDEBUG := -g
CRELEASE := -O2
TARGET := config
CFLAGS += $(CRELEASE)
SRC := config.c
OBJ := $(SRC:.c=.o)
PUBHEA := config.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)
mv $(STATICLIB) $(INSTLIB)
mv $(DYNLIB) $(INSTLIB)
mkdir -p $(INSTHEA)
cp $(PUBHEA) $(INSTHEA)
uninstall:
rm -rf $(INSTLIB)/$(STATICLIB) \
$(INSTLIB)/$(DYNLIB) \
$(INSTHEA)
# check:
# if [ ! -f "$(INSTLIB)/$(TARGET).a" ]
# then
# echo "Static library not installed." >&2
# fi
# if [ ! -f "$(INSTLIB)/$(TARGET).so" ]
# then
# echo "Dynamic library not installed." >&2
# fi
# if [ ! -f "$(INSTHEA)" ]
# then
# echo "Library headers not installed." >&2
# fi
# Requires doxygen to be installed.
# Link: https://www.doxygen.nl
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