-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
59 lines (58 loc) · 1.85 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
# Compiler and shell
CC = g++
SHELL = /bin/bash
RM = rm -f
# Default name of the program
MAIN = main
# ROOT flags
ROOTCFLAGS = $(shell root-config --cflags)
ROOTLIBS = $(shell root-config --libs)
ROOTLIBDIR = $(shell root-config --libdir)
EXTRA_ROOTLIBS = -lRooFit -lRooStats -lRooFitCore
ROOTLIBFLAGS = -L$(ROOTLIBDIR) -Wl,--as-needed $(ROOTLIBS) $(EXTRA_ROOTLIBS) -Wl,-rpath,$(ROOTLIBDIR)
# ExtraRooFit flags
ERFDIR = ExtraRooFit
ERFCXXFLAGS = $(shell make -sC $(ERFDIR) cflags)
ERFLIBS = $(shell make -sC $(ERFDIR) libs)
ERFLIBDIR = $(shell make -sC $(ERFDIR) libdir)
ERFLIBFLAGS = -L$(ERFLIBDIR) -Wl,--no-as-needed $(ERFLIBS) -Wl,-rpath,$(ERFLIBDIR)
# Extensions
SRCEXT = cpp
HDREXT = h
OBJEXT = o
# Directories
SRCDIR = src
HDRDIR = include
OBJDIR = build
BINDIR = bin
# Get files and make list of objects and libraries
SRCS := $(shell find $(SRCDIR) -name '*.$(SRCEXT)')
HDRS := $(shell find $(HDRDIR) -name '*.$(HDREXT)')
OBJS := $(patsubst $(SRCDIR)/%.$(SRCEXT), $(OBJDIR)/%.$(OBJEXT), $(SRCS))
# Where the output is
OUTPUT = $(OBJDIR)/*.$(OBJEXT) $(BINDIR)/*
# Compiler flags
CXXFLAGS = -Wall -fPIC -I$(HDRDIR) $(ROOTCFLAGS)
LIBFLAGS = -Wl,--no-undefined -Wl,--no-allow-shlib-undefined $(ROOTLIBFLAGS) $(ERFLIBFLAGS) -lboost_program_options
# Rules
.PHONY : all clean $(ERFDIR)
# Default
all : bin/$(MAIN)
# Compile ExtraRooFit
$(ERFDIR) :
make -C $@
# Build binary. In principle you can call `make bin/whatever` to rename the output binary
$(BINDIR)/% : $(OBJS) | $(BINDIR) $(ERFDIR)
@echo "Linking $@"
@$(CC) $^ -o $@ $(LIBFLAGS)
# Build objects
$(OBJDIR)/%.$(OBJEXT) : $(SRCDIR)/%.$(SRCEXT) | $(OBJDIR)
@echo "Compiling $@"
@$(CC) -c $< -o $@ $(CXXFLAGS)
# Make directories
$(BINDIR) $(OBJDIR) :
mkdir -p $@
# Remove all the output
clean :
$(RM) $(OUTPUT)
make -C $(ERFDIR) clean