/
build-cxx-root.go
149 lines (124 loc) · 2.94 KB
/
build-cxx-root.go
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
// Copyright ©2019 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
// Command to build a given ROOT version from sources.
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
)
func main() {
log.SetPrefix("")
log.SetFlags(0)
rvers := flag.String("root-version", "6.26.00", "ROOT version to build")
nproc := flag.Int("j", runtime.NumCPU(), "number of parallel build processes")
flag.Parse()
build(*rvers, *nproc)
}
func build(rvers string, nproc int) {
tmp, err := os.MkdirTemp("", "build-root-")
if err != nil {
log.Fatalf("could not create top-level tmp dir: %+v", err)
}
defer os.RemoveAll(tmp)
bdir := filepath.Join(tmp, "build")
err = os.MkdirAll(bdir, 0755)
if err != nil {
log.Fatalf("could not create build dir %q: %+v", bdir, err)
}
dst := filepath.Join(tmp, "root-"+rvers)
err = os.MkdirAll(dst, 0755)
if err != nil {
log.Fatalf("could not create dst dir %q: %+v", dst, err)
}
fname := filepath.Join(tmp, "build.sh")
err = os.WriteFile(fname, []byte(fmt.Sprintf(docker, rvers, nproc)), 0644)
if err != nil {
log.Fatalf("could not create build-script: %+v", err)
}
cmd := exec.Command("docker", "run", "--rm",
"--network=host",
"-v", fname+":/build.sh",
"-v", bdir+":/build/src",
"-v", dst+":/build/install",
"ubuntu:20.04", "/bin/sh", "/build.sh",
)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatalf("could not build ROOT-%s: %+v", rvers, err)
}
wd, err := os.Getwd()
if err != nil {
log.Fatalf("could not get pwd: %+v", err)
}
cmd = exec.Command("tar", "zcf", filepath.Join(wd, "root-"+rvers+"-linux_amd64.tar.gz"), "root-"+rvers)
cmd.Dir = tmp
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatalf("could not tar ROOT-%s: %+v", rvers, err)
}
}
const docker = `#!/bin/sh
set -e
set -x
export DEBIAN_FRONTEND=noninteractive
apt update -yq
apt install -yq \
cmake curl \
g++ git \
python \
;
export ROOT_VERSION="%[1]s"
cd /tmp
curl -O -L https://root.cern.ch/download/root_v${ROOT_VERSION}.source.tar.gz
tar zxf ./root_v${ROOT_VERSION}.source.tar.gz
cd /build/src
cmake /tmp/root-${ROOT_VERSION} \
-DCMAKE_INSTALL_PREFIX=/build/install -DCMAKE_BUILD_TYPE=Release \
-Dall=OFF -Dfail-on-missing=OFF \
-Dalien=OFF \
-Dastiff=OFF \
-Dbonjour=OFF \
-Dbuiltin_afterimage=OFF \
-Dbuiltin_ftgl=OFF \
-Dbuiltin_glez=OFF \
-Dcastor=OFF \
-Dclad=OFF \
-Dchirp=OFF \
-Ddcache=OFF \
-Dfftw3=OFF \
-Dfitsio=OFF \
-Dgenvector=OFF \
-Dgfal=OFF \
-Dglite=OFF \
-Dgnuinstall=OFF \
-Dgraphics=OFF \
-Dgviz=OFF \
-Dhdfs=OFF \
-Dkrb5=OFF \
-Dldap=OFF \
-Dmathmore=OFF \
-Dmonalisa=OFF \
-Dmysql=OFF \
-Dodbc=OFF \
-Dpython=OFF \
-Dshared=OFF \
-Dtmva=OFF \
-Dvdt=OFF \
-Dx11=OFF \
-Dxrootd=OFF \
;
make -j%[2]d
make -j%[2]d install
`