forked from lnls-fac/trackcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
215 lines (170 loc) · 6.78 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
## TRACKCPP
## ========
## Author: Accelerator Physics Group - LNLS
## contact: xresende@gmail.com
## affiliation: Laboratorio Nacional de Luz Sincrotron
##
## The MIT License (MIT)
##
## Copyright (c) <year> <copyright holders>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
## THE SOFTWARE.
#### READS LIB VERSION ####
FILE=VERSION
VERSION=$(shell cat ${FILE})
#### COMPILATION OPTIONS ####
CC = gcc
CXX = g++
AR = ar
MACHINE = -m64
OPT_FLAG = -O3 -std=c++11 -fPIC
DBG_FLAG = -O0 -g3 -std=c++11 -fPIC
ARFLAGS = rcs
DFLAGS = -DVERSION=$(VERSION)
LIBSOURCES_CPP = lattice.cpp \
elements.cpp \
passmethods.cpp \
tracking.cpp \
trackcpp.cpp \
flat_file.cpp \
optics.cpp \
diffusion_matrix.cpp \
dynap.cpp \
output.cpp \
kicktable.cpp \
multithreads.cpp \
accelerator.cpp \
naff.cpp \
linalg.cpp \
auxiliary.cpp
BINSOURCES_CPP = exec.cpp \
tests.cpp \
commands.cpp \
AUXFILES = VERSION
LIBS = $(shell gsl-config --libs)
LIBS += -lpthread
INC = -I./include
INC += $(shell gsl-config --cflags)
ifeq ($(CONDA_PREFIX),)
PREFIX = /usr/local
else
PREFIX = $(CONDA_PREFIX)
endif
BINDEST_DIR = $(PREFIX)/bin
LIBDEST_DIR = $(PREFIX)/lib
INCDEST_DIR = $(PREFIX)/include
OBJDIR = build
SRCDIR = src
INCDIR = include
PYTHON_PACKAGE_DIR = python_package
$(shell touch $(SRCDIR)/output.cpp) # this is so that last compilation time always goes into executable
WARNINGS_CFLAGS += -Wall
WARNINGS_CFLAGS += -Wextra # reasonable and standard
WARNINGS_CFLAGS += -Wshadow # warn the user if a variable declaration shadows one from a parent context
WARNINGS_CFLAGS += -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor.
# This helps catch hard to track down memory errors
# WARNINGS_CFLAGS += -Wdouble-promotion # warn if float is implicit promoted to double
# WARNINGS_CFLAGS += -Wformat=2 # warn on security issues around functions that format output (ie printf)
# WARNINGS_CFLAGS += -Wold-style-cast # warn for c-style casts
# WARNINGS_CFLAGS += -Wsign-conversion # warn on sign conversions
WARNINGS_CFLAGS += -Wcast-align # warn for potential performance problem casts
WARNINGS_CFLAGS += -Wconversion # warn on type conversions that may lose data
# WARNINGS_CFLAGS += -Wduplicated-branches # warn if if / else branches have duplicated code // not available in g++ 6.3.0
WARNINGS_CFLAGS += -Wduplicated-cond # warn if if / else chain has duplicated conditions
# WARNINGS_CFLAGS += -Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation // not available in g++ 6.3.0
WARNINGS_CFLAGS += -Wlogical-op # warn about logical operations being used where bitwise were probably wanted
WARNINGS_CFLAGS += -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
WARNINGS_CFLAGS += -Wnull-dereference # warn if a null dereference is detected
WARNINGS_CFLAGS += -Woverloaded-virtual # warn if you overload (not override) a virtual function
WARNINGS_CFLAGS += -Wpedantic # warn if non-standard C++ is used
WARNINGS_CFLAGS += -Wunused # warn on anything being unused
WARNINGS_CFLAGS += -Wuseless-cast # warn if you perform a cast to the same type
ifeq ($(MAKECMDGOALS),trackcpp-debug)
CFLAGS = $(MACHINE) $(DBG_FLAG) $(DFLAGS) -pthread
else
CFLAGS = $(MACHINE) $(OPT_FLAG) $(DFLAGS) -pthread
endif
CFLAGS += $(WARNINGS_CFLAGS)
LIBOBJECTS = $(addprefix $(OBJDIR)/, $(LIBSOURCES_CPP:.cpp=.o))
BINOBJECTS = $(addprefix $(OBJDIR)/, $(BINSOURCES_CPP:.cpp=.o))
LDFLAGS = $(MACHINE)
#### DERIVED CONDITIONALS AND VARIABLES ####
ifeq ($(shell hostname), uv100)
CC = /progs/users/gcc-4.7.3/bin/gcc
CXX = /progs/users/gcc-4.7.3/bin/g++
LIBS = -Wl,-rpath,/progs/users/gcc-4.7.3/lib64 ~/bin/GSL/lib/libgsl.a ~/bin/GSL/lib/libgslcblas.a -lpthread
INC = -I../bin/GSL/include/
endif
.PHONY: all alllibs trackcpp clean cleanall
#### TARGETS ####
all: libtrackcpp trackcpp python_package
#### GENERATES DEPENDENCY FILE ####
$(shell $(CXX) -MM $(CFLAGS) $(addprefix $(SRCDIR)/, $(LIBSOURCES_CPP)) $(addprefix $(SRCDIR)/, $(BINSOURCES_CPP)) | sed 's/.*\.o/$(OBJDIR)\/&/' > .depend)
-include .depend
libtrackcpp: $(OBJDIR)/libtrackcpp.a
trackcpp: $(OBJDIR)/trackcpp
python_package: $(PYTHON_PACKAGE_DIR)/trackcpp/_trackcpp.so
$(PYTHON_PACKAGE_DIR)/trackcpp/_trackcpp.so: libtrackcpp
$(MAKE) -C $(PYTHON_PACKAGE_DIR)
$(OBJDIR)/libtrackcpp.a: $(LIBOBJECTS)
$(AR) $(ARFLAGS) $@ $^
$(OBJDIR)/trackcpp: libtrackcpp $(BINOBJECTS)
$(CXX) $(LDFLAGS) $(BINOBJECTS) $(OBJDIR)/libtrackcpp.a $(LIBS) -o $@
$(LIBOBJECTS): | $(OBJDIR)
$(BINOBJECTS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)
install-cpp: uninstall-cpp all
cp $(OBJDIR)/trackcpp $(BINDEST_DIR)
cp $(OBJDIR)/libtrackcpp.a $(LIBDEST_DIR)
cp -r $(INCDIR)/trackcpp $(INCDEST_DIR)
uninstall-cpp:
-rm -rf $(BINDEST_DIR)/trackcpp
-rm -rf $(LIBDEST_DIR)/libtrackcpp.a
-rm -rf $(INCDEST_DIR)/trackcpp
install-py: uninstall-py
$(MAKE) install -C $(PYTHON_PACKAGE_DIR)
uninstall-py:
$(MAKE) uninstall -C $(PYTHON_PACKAGE_DIR)
install: clean install-cpp install-py
uninstall: uninstall-cpp uninstall-py
develop-install-py: develop-uninstall-py all
$(MAKE) develop-install -C $(PYTHON_PACKAGE_DIR)
develop-uninstall-py:
$(MAKE) develop-uninstall -C $(PYTHON_PACKAGE_DIR)
$(BINDEST_DIR):
mkdir $(BINDEST_DIR)
$(LIBDEST_DIR):
mkdir $(LIBDEST_DIR)
$(INCDEST_DIR):
mkdir $(INCDEST_DIR)
clean:
-rm -rf $(OBJDIR) trackcpp trackcpp-debug .depend *.out *.dat *~ *.o *.a
$(MAKE) clean -C $(PYTHON_PACKAGE_DIR)
cleanall: clean
cd tracking_mp; make clean;
#### RULES ####
*.cpp: VERSION
touch $(SRCDIR)/*.cpp
*.cc: VERSION
touch $(SRCDIR)/*.cc
*.c: VERSION
touch $(SRCDIR)/*.c
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) -c $(CFLAGS) $(INC) -I./$(SRCDIR) $< -o $@;