forked from petervaro/cutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
151 lines (122 loc) · 5.22 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
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
## INFO ########################################################################
## ##
## cutils ##
## ====== ##
## ##
## Modern and Lightweight C Utilities ##
## Version: 0.8.96.177 (20140907) ##
## ##
## File: makefile ##
## ##
## For more information about the project, visit <http://www.cutils.org>. ##
## Copyright (C) 2014 Peter Varo ##
## ##
## This program is free software: you can redistribute it and/or modify it ##
## under the terms of the GNU General Public License as published by the ##
## Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, but ##
## WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
## See the GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program, most likely a file in the root directory, ##
## called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. ##
## ##
######################################################################## INFO ##
#------------------------------------------------------------------------------#
# User flags
IS_OPTIMISED=
USE_JEMALLOC=true
EXCEPTION_LOG=true
DYNAMIC_LIB=
# Location 'prefix'
LOCATION=/usr/local
# Locations
INCLUDE_FOLDER=$(LOCATION)/include
LIBRARY_FOLDER=$(LOCATION)/lib
BINARY_FOLDER=$(LOCATION)/bin
PYTHON=$(LOCATION)/bin/python3
# Compiler
CC=clang
#------------------------------------------------------------------------------#
cutils_DEVELOPER_CHECK=
# Filename of library
cutils_NAME=libcutils
# Output dirs
cutils_BUILD_OUT_DIR=build
cutils_BUILD_TMP_DIR=$(cutils_BUILD_OUT_DIR)/tmp
# Resources in current library
cutils_C_SOURCES=$(wildcard *.c) internal/xxhash.c
cutils_C_OBJECTS=$(addprefix $(cutils_BUILD_TMP_DIR)/, $(notdir $(cutils_C_SOURCES:.c=.o)))
cutils_H_SOURCES=$(wildcard *.h)
cutils_INTERNALS=$(addprefix internal/, defs.h fcmp.h fmtc.h xxhash.h)
# Includes, libs and frameworks
cutils_INCLUDE_DIRS=/usr/local/include .
cutils_LIBRARY_DIRS=/usr/local/lib
cutils_LIBRARIES=
cutils_FRAMEWORKS=
# Operating system
UNAME=$(shell uname)
# If use the jemalloc library
ifdef USE_JEMALLOC
cutils_LIBRARIES+=jemalloc
CFLAGS+=$(addprefix -D, CDAR_JEM CSLL_JEM)
endif
# Flags
ifdef IS_OPTIMISED
CFLAGS+=-O3 $(addprefix -D, CDAR_OPT CSLL_OPT)
else
CFLAGS+=-Wall -v -g
endif
ifdef cutils_DEVELOPER_CHECK
CFLAGS+=-Wextra
endif
# If compiler is clang
ifeq ($(CC), clang)
CFLAGS+=-fmacro-backtrace-limit=0
endif
ifdef EXCEPTION_LOG
CFLAGS+=-D CEXC_LOG
endif
CFLAGS+=-std=c11 $(addprefix -I, $(cutils_INCLUDE_DIRS))
CFLAGS+=$(foreach framework, $(cutils_FRAMEWORKS), -framework $(framework))
LDFLAGS=$(addprefix -L, $(cutils_LIBRARY_DIRS))
LDFLAGS+=$(addprefix -l, $(cutils_LIBRARIES))
# Rules
.PHONY: all clean install
.PHONY: make_build_dirs make_install_dirs
.PHONY: build_generic build_static
all: make_build_dirs build_generic build_static
# Build rule for sources in the root-dir
$(cutils_BUILD_TMP_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
# Build rule for sources in the internal-dir
$(cutils_BUILD_TMP_DIR)/%.o: internal/%.c
$(CC) $(CFLAGS) -c -o $@ $<
build_generic:
# HACK:
cp -f internal/static_hash_map.h cshm.h
cp -f internal/static_hash_map.c cshm.c
$(PYTHON) dev/proj.py
build_static: $(cutils_C_OBJECTS)
ar -c -r -s -v $(cutils_BUILD_OUT_DIR)/$(cutils_NAME).a $(cutils_C_OBJECTS)
# $(cutils_BUILD_TMP_DIR)/%.o: %.c
# $(CC) $(CFLAGS) -fPIC -c -o $@ $<
# build_shared: $(cutils_NAME)
# $(CC) -shared -Wl -soname -o $(cutils_BUILD_OUT_DIR)/$(cutils_NAME).so
install: all make_install_dirs
$(PYTHON) setup.py install $(INCLUDE_FOLDER) $(LIBRARY_FOLDER) $(BINARY_FOLDER)
cp -Rf $(cutils_BUILD_OUT_DIR)/$(cutils_NAME).a $(LIBRARY_FOLDER)/$(cutils_NAME).a
cp -Rf $(cutils_H_SOURCES) $(INCLUDE_FOLDER)/cutils
cp -Rf $(cutils_INTERNALS) $(INCLUDE_FOLDER)/cutils/internal
# Create build dir and tmp dir inside it
make_build_dirs:
mkdir -p $(cutils_BUILD_TMP_DIR)
make_install_dirs:
mkdir -p $(INCLUDE_FOLDER)/cutils/internal
# Remove build dir and all dirs and files inside
clean:
rm -f -r $(cutils_BUILD_OUT_DIR)