diff --git a/make/build/clear_vars.mk b/make/build/clear_vars.mk new file mode 100644 index 0000000..e69de29 diff --git a/make/build/config.mk b/make/build/config.mk new file mode 100644 index 0000000..a7743fe --- /dev/null +++ b/make/build/config.mk @@ -0,0 +1,55 @@ +# This file is included by the top-level Makefile. It sets up +# standard variables based on the current configuration and +# platform that are not specific to what is being built. + +# Always use bash, not whatever is installed as /bin/sh +SHELL := /bin/bash + +# Utility variables + +empty := +space := $(empty) $(empty) +comma := , + +# Note: make removes the newline immediately prior to `endef` +define newline + + +endef + +backslash := \a +backslash := $(patsubst %a,%,$(backslash)) + + +# ############################################################### +# Build system internal files +# ############################################################### + +BUILD_COMBOS:= $(BUILD_SYSTEM)/combo + +CLEAR_VARS:= $(BUILD_SYSTEM)/clear_vars.mk +# TODO: BUILD_STATIC_LIBRARY := $(BUILD_SYSTEM)/static_library.mk +# TODO: BUILD_HOST_EXECUTABLE := $(BUILD_SYSTEM)/host_executable.mk +# TODO: BUILD_TARGET_EXECUTABLE := $(BUILD_SYSTEM)/target_executable.mk + + +# ############################################################### +# Include sub-configuration files +# ############################################################### + +# This sets up most of the global variables that are specific to the +# user's build configuration. +include $(BUILD_SYSTEM)/envsetup.mk + +# ############################################################### +# Generic tools +# ############################################################### + +COLUMN := column + +# It's called md5 on Mac OS and md5sum on Linux +ifeq ($(HOST_OS),darwin) +MD5SUM:=md5 -q +else +MD5SUM:=md5sum +endif diff --git a/make/build/definitions.mk b/make/build/definitions.mk new file mode 100644 index 0000000..c1b6296 --- /dev/null +++ b/make/build/definitions.mk @@ -0,0 +1,80 @@ +# Common build system definitions. Mostly helpful shortcuts or +# functions, since we don't actually compile code here. + +# The names of all packages in the system. +ALL_PACKAGES := + + +########################################################### +## Debugging; prints a variable list to stdout +########################################################### + +# $(1): variable name list, not variable values +define print-vars +$(foreach var,$(1), \ + $(info $(var):) \ + $(foreach word,$($(var)), \ + $(info $(space)$(space)$(word)) \ + ) \ + ) +endef + + +########################################################### +## Retrieve the directory of the current makefile +## Must be called before including any other makefile!! +########################################################### + +# Figure out where we are. +define my-dir +$(strip \ + $(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \ + $(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \ + $(error my-dir must be called before including any other makefile.) \ + , \ + $(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \ + ) \ + ) +endef + + +########################################################### +## Function we can evaluate to introduce a dynamic dependency +########################################################### + +define add-dependency +$(1): $(2) +endef + + +########################################################### +## Run rot13 on a string +## $(1): the string. Must be one line. +########################################################### + +define rot13 +$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M') +endef + + +########################################################### +## Returns true if $(1) and $(2) are equal. Returns +## the empty string if they are not equal. +########################################################### + +define streq +$(strip $(if $(strip $(1)),\ + $(if $(strip $(2)),\ + $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \ + ),\ + $(if $(strip $(2)),\ + ,\ + true)\ + )) +endef + + +########################################################### +## TODO: Command for running 'make' to build an output +## TODO: Command for running ./configure to prepare a build +########################################################### diff --git a/make/build/envsetup.mk b/make/build/envsetup.mk new file mode 100644 index 0000000..4144a9f --- /dev/null +++ b/make/build/envsetup.mk @@ -0,0 +1,43 @@ +# --------------------------------------------------------------- +# Set up configuration for the host machine. +UNAME := $(shell uname -sm) + +ifneq (,$(findstring Linux,$(UNAME))) + HOST_OS := linux +endif +ifneq (,$(findstring Darwin,$(UNAME))) + HOST_OS := darwin +endif +ifneq (,$(findstring Macintosh,$(UNAME))) + HOST_OS := darwin +endif +ifneq (,$(findstring CYGWIN,$(UNAME))) + HOST_OS := windows +endif + +ifeq ($(HOST_OS),) +$(error Unable to determine HOST_OS from uname -sm: $(UNAME)!) +endif + +ifneq (,$(findstring x86_64,$(UNAME))) + HOST_ARCH := x86_64 +else +ifneq (,$(findstring x86,$(UNAME))) +$(error Building on a 32-bit x86 host is not supported: $(UNAME)!) +endif +endif + +ifeq ($(HOST_ARCH),) +$(error Unable to determine HOST_ARCH from uname -sm: $(UNAME)!) +endif + + +# --------------------------------------------------------------- +# Figure out the output directory +ifeq (,$(strip $(OUT_DIR))) +OUT_DIR := $(TOPDIR)out +endif + + +# --------------------------------------------------------------- +# TODO: figure out the target output dir, etc... diff --git a/make/build/main.mk b/make/build/main.mk new file mode 100644 index 0000000..c80d64f --- /dev/null +++ b/make/build/main.mk @@ -0,0 +1,76 @@ +# Always use bash, not whatever is installed as /bin/sh +SHELL := /bin/bash + +# Disable built-in suffix rules. +.SUFFIXES: + +# Turn off the RCS / SCCS implicit rules of GNU Make +% : RCS/%,v +% : RCS/% +% : %,v +% : s.% +% : SCCS/s.% + +# If a rule fails, delete $@. +.DELETE_ON_ERROR: + +# Check for broken versions of make. +# (Allow any version under Cygwin since we don't actually build the platform there.) +ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81))) +$(warning ********************************************************************************) +$(warning * You are using version $(MAKE_VERSION) of make.) +$(warning * Android can only be built by versions 3.81 and higher.) +$(warning * see https://source.android.com/source/download.html) +$(warning ********************************************************************************) +$(error stopping) +endif + +# Absolute path of the present working direcotry. +# This overrides the shell variable $PWD, which does not necessarily point to +# the top of the source tree, for example when "make -C" is used. +PWD := $(shell pwd) + +TOP := . +TOPDIR := + +# This is the default target. It must be the first declared target. +.PHONY: all +DEFAULT_GOAL := all +$(DEFAULT_GOAL): + +# The path to the directory containing our build system's Makefiles. +BUILD_SYSTEM := $(TOPDIR)build + +# Set up standard variables based on configuration. +include $(BUILD_SYSTEM)/config.mk + +# Check the sanity of the build tools. +VERSION_CHECK_SEQUENCE_NUMBER := 5 +-include $(OUT_DIR)/versions_checked.mk +ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED)) + +$(info Checking build tools versions...) + +# Make sure that there are no spaces in the absolute path; the +# build system can't deal with them. +ifneq ($(words $(shell pwd)),1) +$(warning ************************************************************) +$(warning You are building in a directory whose absolute path contains) +$(warning a space character:) +$(warning $(space)) +$(warning "$(shell pwd)") +$(warning $(space)) +$(warning Please move your source tree to a path that does not contain) +$(warning any spaces.) +$(warning ************************************************************) +$(error Directory names containing spaces not supported) +endif + +# Now that we've checked all our build tools, write the include file that we +# load next time. +$(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \ + > $(OUT_DIR)/versions_checked.mk) +endif + +# Bring in standard build system definitions +include $(BUILD_SYSTEM)/definitions.mk diff --git a/make/out/.gitignore b/make/out/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/make/out/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore