forked from hbprosper/treestream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (116 loc) · 3.79 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
# Build libtreestream.so
# Created 27 Feb 2013 HBP & SS
# 30 May 2015 HBP - standardize structure (src, lib, include)
# 12 Sep 2022 HBP - use TREESTREAM_PREFIX as installation area and
# allow installation only if the variable is defined
# ----------------------------------------------------------------------------
ifndef ROOTSYS
$(error *** Please set up Root)
endif
ifndef TREESTREAM_PREFIX
ifdef CONDA_PREFIX
TREESTREAM_PREFIX := $(CONDA_PREFIX)
endif
endif
# ----------------------------------------------------------------------------
NAME := treestream
incdir := include
srcdir := src
libdir := lib
bindir := bin
testdir := test
SRCTESTS:= \
$(testdir)/testtreestream.cc \
$(testdir)/testdelphes.cc \
$(testdir)/testvector.cc
OBJTESTS:= $(SRCTESTS:.cc=.o)
TESTS := $(SRCTESTS:.cc=)
$(shell mkdir -p lib)
# get lists of sources
SRCS := $(srcdir)/treestream.cc \
$(srcdir)/pdg.cc \
$(srcdir)/testme.cc
CINTSRCS := $(wildcard $(srcdir)/*_dict.cc)
OTHERSRCS := $(filter-out $(CINTSRCS) $(SRCS),$(wildcard $(srcdir)/*.cc))
# list of dictionaries to be created
DICTIONARIES := $(SRCS:.cc=_dict.cc)
# get list of objects
OBJECTS := $(SRCS:.cc=.o) $(OTHERSRCS:.cc=.o) $(DICTIONARIES:.cc=.o)
PYTHONLIB := python$(shell python --version | cut -c 8-10)
#say := $(shell echo "DICTIONARIES: $(DICTIONARIES)" >& 2)
#say := $(shell echo "" >& 2)
#say := $(shell echo "SRCS: $(SRCS)" >& 2)
#say := $(shell echo "PYTHON_LIB: $(PYTHONLIB)" >& 2)
#$(error bye)
# ----------------------------------------------------------------------------
ROOTCINT := rootcint
# check for clang++, otherwise use g++
COMPILER := $(shell which clang++)
ifneq ($(COMPILER),)
CXX := /usr/bin/clang++
LD := /usr/bin/clang++
else
CXX := g++
LD := g++
endif
CPPFLAGS := -I. -I$(incdir)
CXXFLAGS := -O -Wall -fPIC -g -ansi -Wshadow -Wextra \
$(shell root-config --cflags)
LDFLAGS := -g
# ----------------------------------------------------------------------------
# which operating system?
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
LDFLAGS += -dynamiclib
LDEXT := .dylib
else
LDFLAGS += -shared
LDEXT := .so
endif
LDFLAGS += $(ROOTFLAGS) -Wl,-rpath,$(ROOTSYS)/lib
LIBS := $(shell root-config --libs)
LIBRARY := $(libdir)/lib$(NAME)$(LDEXT)
# ----------------------------------------------------------------------------
all: $(LIBRARY) $(TESTS)
ifdef TREESTREAM_PREFIX
install:
cp $(bindir)/mk*.py $(TREESTREAM_PREFIX)/bin
cp $(incdir)/treestream.h $(TREESTREAM_PREFIX)/include
cp $(incdir)/pdg.h $(TREESTREAM_PREFIX)/include
cp $(libdir)/lib$(NAME)$(LDEXT) $(TREESTREAM_PREFIX)/lib
find $(libdir) -name "*.pcm" -exec cp {} $(TREESTREAM_PREFIX)/lib \;
cp treestream.py $(TREESTREAM_PREFIX)/lib/$(PYTHONLIB)/site-packages
endif
$(LIBRARY) : $(OBJECTS)
@echo ""
@echo "=> Linking shared library $@"
$(LD) $(LDFLAGS) $^ $(LIBS) -o $@
$(OBJECTS) : %.o : %.cc
@echo ""
@echo "=> Compiling $<"
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
$(DICTIONARIES) : $(srcdir)/%_dict.cc : $(incdir)/%.h $(srcdir)/%_linkdef.h
@echo ""
@echo "=> Building dictionary $@"
$(ROOTCINT) -f $@ -c $(CPPFLAGS) $^
find $(srcdir) -name "*.pcm" -exec mv {} $(libdir) \;
$(OBJTESTS) : %.o : %.cc
@echo ""
@echo "=> Compiling $<"
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
$(TESTS) : % : %.o $(LIBRARY)
@echo ""
@echo "=> Linking test program $@"
$(LD) $(ROOTFLAGS) $^ -L$(libdir) -l$(NAME) $(LIBS) -o $@
tidy:
rm -rf $(srcdir)/*_dict*.* $(srcdir)/*.o $(testdir)/*.o
ifdef TREESTREAM_PREFIX
clean:
rm -rf $(libdir)/* $(srcdir)/*_dict*.* $(srcdir)/*.o
rm -rf $(TESTS) $(OBJTESTS)
rm -rf $(TREESTREAM_PREFIX)/lib/*$(NAME)*
rm -rf $(TREESTREAM_PREFIX)/lib/pdg_*.pcm
rm -rf $(TREESTREAM_PREFIX)/include/*$(NAME)*
rm -rf $(TREESTREAM_PREFIX)/include/pdg.h
rm -rf $(TREESTREAM_PREFIX)/lib/$(PYTHONLIB)/site-packages/$(NAME).py
endif