-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (116 loc) · 3.02 KB
/
Copy pathMakefile
File metadata and controls
159 lines (116 loc) · 3.02 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
# Adjacency Makefile, Guy Nankivell, 2017
#
# Library specific options
CC ?= gcc
NAME = adjacency
LIBNAME=libadjacency.so
VERSION = devel
PREFIX?=~
MAKE += --no-print-directory
# Avoid inheritance of shell from environment
SHELL = /bin/sh
# Clear implicit suffixes
.SUFFIXES:
.SUFFIXES: .c .o
LIBPREFIX = $(PREFIX)/lib
INCLPREFIX = $(PREFIX)/include
LIBINSTALL = $(PREFIX)/lib
INCLINSTALL = $(PREFIX)/include
# Prefixes for commonly used directories.
SRCDIR = src
TESTDIR = test
BUILDDIR = build
#
# Compilation Options
#
CFLAGS = -Wall -Wextra --std=c99
DEBUG_FLAGS = -Werror -Wstrict-prototypes -Wpointer-arith -Wshadow \
-pg -g
LFLAGS=
# Flags for enabling or disabling compiler options for either strict debugging
# or allowing the debugging options to be disabled and produce faster code with
# no debugging symbols. Note: DIST overrides DEBUG
DEBUG=1
DIST=0
ifeq ($(DEBUG), 0)
DEBUG_FLAGS =
endif
ifeq ($(DIST), 1)
DEBUG_FLAGS = -O2
endif
# Crude compiler detection
#CLANG := $(shell command -v clang --version 2> /dev/null)
#ifdef CLANG
# CC = clang
#endif
.PHONY: clean clean-test cp-lib set-ld
PROG = create-build-dir so-gen cp-lib cp-headers
# Dumb way of passing the correct compiler options
ifeq ($(CC),clang)
PROG = create-build-dir so-gen-clang cp-lib cp-headers
endif
all: $(PROG) tests
create-build-dir:
mkdir -p $(BUILDDIR)
#
# Object files for dependency checks at compile time
#
memutils.o:
$(CC) $(CFLAGS) -fPIC -c src/memutils.c $(DEBUG_FLAGS) $(LFLAGS)
vertex.o:
$(CC) $(CFLAGS) -fPIC -c src/vertex.c $(DEBUG_FLAGS) $(LFLAGS)
meta.o:
$(CC) $(CFLAGS) -fPIC -c src/meta.c $(DEBUG_FLAGS) $(LFLAGS)
graph.o:
$(CC) $(CFLAGS) -fPIC -c src/graph.c $(DEBUG_FLAGS) $(LFLAGS)
fileutils.o:
$(CC) $(CFLAGS) -fPIC -c src/fileutils.c $(DEBUG_FLAGS) $(LFLAGS)
adjlist.o:
$(CC) $(CFLAGS) -fPIC -c src/adjlist.c $(DEBUG_FLAGS) $(LFLAGS)
build-objs: vertex.o fileutils.o graph.o meta.o adjlist.o memutils.o
#
# Build the Library
#
so-gen: build-objs
$(CC) -dynamiclib -shared -Wl,-soname,$(LIBNAME) -o \
$(LIBNAME).$(VERSION) *.o
mv *.o $(BUILDDIR)
ln -sf $(LIBNAME).$(VERSION) $(LIBNAME)
mv $(LIBNAME)* $(BUILDDIR)
so-gen-clang: build-objs
$(CC) -dynamiclib -shared -Wl,-install_name,$(LIBNAME) -o \
$(LIBNAME).$(VERSION) *.o
mv *.o $(BUILDDIR)
ln -sf $(LIBNAME).$(VERSION) $(LIBNAME)
mv $(LIBNAME)* $(BUILDDIR)
cp-lib:
mkdir -p $(LIBPREFIX)
cp $(BUILDDIR)/$(LIBNAME).$(VERSION) $(LIBPREFIX)
ln -sf $(LIBPREFIX)/$(LIBNAME).$(VERSION) $(LIBPREFIX)/$(LIBNAME)
cp-headers:
mkdir -p $(INCLPREFIX)
cp $(SRCDIR)/*.h $(INCLPREFIX)
#
# Install
#
install: create-build-dir so-gen
mkdir -p $(LIBINSTALL)
mkdir -p $(INCLINSTALL)/$(NAME)/
cp $(BUILDDIR)/$(LIBNAME).$(VERSION) $(LIBINSTALL)
ln -sf $(LIBINSTALL)/$(LIBNAME).$(VERSION) $(LIBINSTALL)/$(LIBNAME)
cp $(SRCDIR)/*.h $(INCLINSTALL)/$(NAME)/
uninstall:
rm -rf $(LIBINSTALL)/$(LIBNAME)*
rm -rf $(INCLINSTALL)/$(NAME)/
#
# Test Targets
#
tests:
$(MAKE) -C test
#
# Clean Targets
#
clean: clean-test
rm -rf $(BUILDDIR) *.o
$(MAKE) -C test clean