-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
125 lines (109 loc) · 3.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
topdir := $(dir $(lastword $(MAKEFILE_LIST)))
###############################################################################
#
# Simple Makefile wrapper over cmake
#
# Author: Andrea Valassi, 31 Aug 2016 (COOL)
# Modified: Andrea Valassi, 18 Jun 2018 (BLUEFIN)
#
# Targets:
# cmake -> create cmake config ("cmake")
# all -> create cmake config and build code ("cmake; make")
#
# Additional targets (show build variables):
# setup_sh -> show the commands needed to set up the (bash) environment
# print-<v> -> show the value of variable/macro <v>
# print -> show a selection of relevant variables/macros
#
# Mandatory prerequisites:
# - the cmake executable
#
# Recommended prerequisites:
# - the CMAKEFLAGS variable
# (this contains the command line options used in the cmake step)
# - the CMAKE_PREFIX_PATH env variable
# (this is used by CMake to resolve package dependencies of BLUEFIN)
#
###############################################################################
#------------------------------------------------------------------------------
# Architecture (e.g. x86_64)
LCG_arch := $(shell uname -m)
# Determine the O/S
ifneq ($(wildcard /etc/os-release),)
# 1. Determine the O/S from /etc/os-release
LCG_os := $(shell cat /etc/os-release | grep ^ID= | sed 's/^ID="//' | sed 's/"$$//')
LCG_os := $(LCG_os)$(shell cat /etc/os-release | grep ^VERSION_ID= | sed 's/^VERSION_ID="//' | sed 's/"$$//' | cut -d. -f1)
else
ifneq ($(wildcard /etc/redhat-release),)
# 2. Determine the O/S from /etc/redhat-release
RH := $(shell more /etc/redhat-release)
ifeq ($(RH),)
LCG_os := unknown
endif
ifeq ($(wordlist 1,5,$(RH)),Scientific Linux CERN SLC release)
LCG_os := slc$(firstword $(subst ., ,$(word 6,$(RH))))
else
ifeq ($(wordlist 1,4,$(RH)),Scientific Linux SL release)
LCG_os := sl$(firstword $(subst ., ,$(word 5,$(RH))))
else
ifeq ($(wordlist 1,6,$(RH)),Red Hat Enterprise Linux Server release)
LCG_os := rhel$(firstword $(subst ., ,$(word 7,$(RH))))
else
ifeq ($(wordlist 1,3,$(RH)),CentOS Linux release)
LCG_os := centos$(firstword $(subst ., ,$(word 4,$(RH))))
else
LCG_os := unknown
endif
endif
endif
endif
else
# 3. Could not determine the O/S
LCG_os := unknown
endif
endif
# Compiler version
LCG_compiler := gcc$(shell gcc -dumpversion | sed 's/\.//g')
# Build mode (opt or dbg)
ifeq ($(LCG_mode),)
LCG_mode := opt
endif
# Determine the BINARY_TAG for the build
BINARY_TAG := $(LCG_arch)-$(LCG_os)-$(LCG_compiler)-$(LCG_mode)
# Define the default build directory as build.${BINARY_TAG}
BUILDDIR := $(CURDIR)/build.$(BINARY_TAG)
#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------
# Phony targets
.PHONY: cmake setup_sh print
# Execute the make step (default target)
all: cmake
cmake --build $(BUILDDIR) --config .
# Execute the cmake step
cmake:
ifeq ($(wildcard $(BUILDDIR)/Makefile),)
ifeq ($(wildcard $(BUILDDIR)/build.ninja),)
cmake $(CMAKEFLAGS) -H. -B$(BUILDDIR)
endif
endif
# Execute the install step
install: cmake
@: # noop
# [Presently a noop]
# cmake --build $(BUILDDIR) --config . --target install | grep -v "^-- Up-to-date:"
# Minimal setup: add the build directory to PATH and LD_LIBRARY_PATH
setup_sh :
@echo "export PATH=$(realpath $(BUILDDIR)):\$${PATH}; export LD_LIBRARY_PATH=$(realpath $(BUILDDIR)):\$${LD_LIBRARY_PATH}"
# Print all Makefile variables/macros
# See https://stackoverflow.com/questions/22925380
print:
$(info cmake is $(shell which cmake))
$(info )
$(foreach var,BINARY_TAG BUILDDIR CMAKEFLAGS LCG_arch LCG_compiler LCG_mode LCG_os,$(info $(var)=$($(var))))
$(info )
@: # noop
# Print individual Makefile variables/macros
# See https://stackoverflow.com/a/25817631
print-%:
@echo $($*) # or @echo $*=$($*)