# file : bootstrap.gmake -*- Makefile -*- # 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. Note also that this makefile does not support incremental updates, # only from scratch builds (use the clean target to rebuild). # # 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++ # # Typical out-of-tree build: # # mkdir build2-boot # cd build2-boot # make -f ../build2-X.Y.Z/bootstrap.gmake -j 8 CXX=g++ # # If used on Windows, then this makefile assumes you are building either in # the MinGW environment or with Clang targeting MSVC and sets things up # similar to bootstrap-mingw.bat or bootstrap-clang.bat, respectively (so # refer to these batch files on the choice of options, etc). # # 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 # Note that while Clang respects -m32/-m64 in its -dumpmachine output, GCC # always dumps its default target. # target := $(shell $(CXX) $(CXXFLAGS) -dumpmachine) ifneq ($(filter %-w64-mingw32,$(target)),) host := x86_64-w64-mingw32 chost := $(host) override LIBS += -limagehlp else ifneq ($(filter %-windows-msvc,$(target)),) host := x86_64-microsoft-win32-msvc chost := $(host) override CPPFLAGS += -D_MT -D_CRT_SECURE_NO_WARNINGS ifeq ($(filter x86_64-%,$(target)),) override CXXFLAGS += -m64 endif override LDFLAGS += -Xlinker /ignore:4217 override LIBS += -lshell32 -limagehlp else $(error unsupported target $(target)) endif 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=