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
|
# file : bootstrap.gmake -*- Makefile -*-
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
# This makefile requires GNU make 3.81 or later and can be used to bootstrap
# the build system similar to the bootstrap.sh script. Its main advantages over
# the script are support for parallel compilation and an out of tree build.
#
# Similar to the script, the makefile expects to find the libbutl/ or
# libbutl-*/ directory either in the current directory (build2 root) or one
# level up. Both in-tree and out-of-tree builds as well as the 'clean' target
# are supported. The result is saved as build2/b-boot.
#
# Typical in-tree build:
#
# cd build2-X.Y.Z
# make -f bootstrap.gmake -j 8 CXX=g++-7
#
# Typical out-of-tree build:
#
# mkdir build2-boot
# cd build2-boot
# make -f ../build2-X.Y.Z/bootstrap.gmake -j 8 CXX=g++-7
#
# If used on Windows, then this makefile assumes you are building in the
# MinGW environment and sets things up similar to bootstrap-mingw.bat.
#
# The following standard make variables can be used to customize the build:
#
# CXX
# CPPFLAGS
# CXXFLAGS
# LDFLAGS
# LIBS
exe :=
host :=
chost :=
ifeq ($(OS),Windows_NT)
exe := .exe
host := x86_64-w64-mingw32
chost := x86_64-w64-mingw32
override LIBS += -limagehlp
else
override LIBS += -lpthread
endif
# Remove all the built-in rules, enable second expansion, etc.
#
.SUFFIXES:
ifeq ($(filter -r,$(MAKEFLAGS)),)
MAKEFLAGS += -r
endif
.DELETE_ON_ERROR:
.SECONDEXPANSION:
# We build in CWD and figure out the source directory based on the makefile
# path.
#
out_root := .
src_root := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
ifeq ($(realpath $(out_root)),$(realpath $(src_root)))
in_tree := true
else
in_tree := false
endif
# See if there is libbutl or libbutl-* in src_root or one directory up.
#
libbutl :=
ifeq ($(libbutl),)
libbutl := $(filter %/,$(wildcard $(src_root)/libbutl/))
ifeq ($(libbutl),)
libbutl := $(filter %/,$(wildcard $(src_root)/libbutl-*/))
endif
endif
ifeq ($(libbutl),)
libbutl := $(filter %/,$(wildcard $(src_root)/../libbutl/))
ifeq ($(libbutl),)
libbutl := $(filter %/,$(wildcard $(src_root)/../libbutl-*/))
endif
endif
ifeq ($(libbutl),)
$(error unable to find libbutl, use libbutl=<dir> to specify its location)
endif
ifneq ($(words $(libbutl)),1)
$(error found multiple libbutl, use libbutl=<dir> to specify its location)
endif
libbutl := $(patsubst %/,%,$(libbutl))
# Figure out libbutl output directory. If we are building in-tree, then build
# libbutl in-tree as well, whether inside or level up. Otherwise -- in the
# libbutl subdirectory.
#
ifeq ($(in_tree),true)
libbutl_out := $(libbutl)/libbutl
else
libbutl_out := $(out_root)/libbutl
endif
# Obtain the host triplet.
#
ifeq ($(host),)
host := $(shell $(src_root)/config.guess)
ifeq ($(host),)
$(error unable to guess host triplet, use host=<triplet> to specify)
endif
chost := $(host)
else
ifeq ($(chost),)
chost := $(shell $(src_root)/config.sub $(host))
ifeq ($(chost),)
$(error unable to canonicalize host triplet, use chost=<triplet> to specify)
endif
endif
endif
# Figure out the list of source/object files.
#
# Note: list nested subdirectories first (used in clean).
#
build2_sub := \
c \
cc \
cxx
libbuild2_sub := \
config \
dist \
test/script \
test \
install \
bin \
version \
in
build2_src := $(wildcard $(src_root)/build2/*.cxx)
build2_src += $(foreach d,$(build2_sub),$(wildcard $(src_root)/build2/$d/*.cxx))
libbuild2_src := $(wildcard $(src_root)/libbuild2/*.cxx)
libbuild2_src += $(foreach d,$(libbuild2_sub),$(wildcard $(src_root)/libbuild2/$d/*.cxx))
libbutl_src := $(wildcard $(libbutl)/libbutl/*.cxx)
# Filter out *.test.cxx sources.
#
build2_src := $(filter-out %.test.cxx,$(build2_src))
libbuild2_src := $(filter-out %.test.cxx,$(libbuild2_src))
libbutl_src := $(filter-out %.test.cxx,$(libbutl_src))
# Note that we use the .b.o object file extension to avoid clashing with the
# build2 builds.
#
build2_obj := $(patsubst $(src_root)/%.cxx,$(out_root)/%.b.o,$(build2_src))
libbuild2_obj := $(patsubst $(src_root)/%.cxx,$(out_root)/%.b.o,$(libbuild2_src))
libbutl_obj := $(patsubst $(libbutl)/libbutl/%.cxx,$(libbutl_out)/%.b.o,$(libbutl_src))
# Build.
#
$(out_root)/build2/b-boot$(exe): $(build2_obj) $(libbuild2_obj) $(libbutl_obj)
$(CXX) -std=c++1y $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(out_root)/build2/%.b.o: $(src_root)/build2/%.cxx | $$(dir $$@).
$(CXX) -I$(libbutl) -I$(src_root) -DBUILD2_BOOTSTRAP -DBUILD2_HOST_TRIPLET=\"$(chost)\" $(CPPFLAGS) -std=c++1y $(CXXFLAGS) -o $@ -c $<
$(out_root)/libbuild2/%.b.o: $(src_root)/libbuild2/%.cxx | $$(dir $$@).
$(CXX) -I$(libbutl) -I$(src_root) -DBUILD2_BOOTSTRAP -DBUILD2_HOST_TRIPLET=\"$(chost)\" $(CPPFLAGS) -std=c++1y $(CXXFLAGS) -o $@ -c $<
$(libbutl_out)/%.b.o: $(libbutl)/libbutl/%.cxx | $$(dir $$@).
$(CXX) -I$(libbutl) -DBUILD2_BOOTSTRAP $(CPPFLAGS) -std=c++1y $(CXXFLAGS) -o $@ -c $<
.PRECIOUS: %/.
%/. :
mkdir -p $*
.PHONY: all
all: $(out_root)/build2/b-boot$(exe)
# Clean.
#
.PHONY: clean cleano
cleano:
rm -f $(build2_obj)
rm -f $(libbuild2_obj)
rm -f $(libbutl_obj)
clean: cleano
rm -f $(out_root)/build2/b-boot$(exe)
ifeq ($(in_tree),false)
rm -fd $(foreach d,$(build2_sub),$(out_root)/build2/$d) $(out_root)/build2 $(foreach d,$(libbuild2_sub),$(out_root)/libbuild2/$d) $(out_root)/libbuild2 $(libbutl_out)
endif
|