Build on macOS/Darwin

This commit is contained in:
Greg Haerr 2022-04-16 16:48:17 -07:00
parent f6b6204b9e
commit 3e4f8b0b58
8 changed files with 73 additions and 21 deletions

View file

@ -85,6 +85,7 @@ PKGS =
-include ~/.cosmo.mk
include build/functions.mk #─┐
include build/compiler.mk #─┐
include build/definitions.mk # ├──META
include build/config.mk # │ You can build
include build/rules.mk # │ You can topologically order

43
build/compiler.mk Normal file
View file

@ -0,0 +1,43 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Cosmopolitan Compiler and Toold Definitions
#
# see build/compile, etc. which run third_party/gcc/unbundle.sh
AR = build/bootstrap/ar.com
PKG = build/bootstrap/package.com
MKDEPS = build/bootstrap/mkdeps.com
ZIPOBJ = build/bootstrap/zipobj.com
ifeq ($(MODE), darwin)
TOOLPREFIX=/usr/local/bin/x86_64-linux-musl-
AS = $(TOOLPREFIX)as
CC = $(TOOLPREFIX)gcc
CXX = $(TOOLPREFIX)g++
CXXFILT = $(TOOLPREFIX)c++filt
LD = $(TOOLPREFIX)ld.bfd
NM = $(TOOLPREFIX)nm
GCC = $(TOOLPREFIX)gcc
STRIP = $(TOOLPREFIX)strip
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)ojbdump
ADDRLINE = $(TOOLPREFIX)addr2line
else
AS = o/third_party/gcc/bin/x86_64-linux-musl-as
CC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
CXX = o/third_party/gcc/bin/x86_64-linux-musl-g++
CXXFILT = o/third_party/gcc/bin/x86_64-linux-musl-c++filt
LD = o/third_party/gcc/bin/x86_64-linux-musl-ld.bfd
NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
OBJCOPY = o/third_party/gcc/bin/x86_64-linux-musl-objcopy
OBJDUMP = o/third_party/gcc/bin/x86_64-linux-musl-objdump
ADDR2LINE = $(shell pwd)/o/third_party/gcc/bin/x86_64-linux-musl-addr2line
endif

View file

@ -308,6 +308,23 @@ OBJDUMP = llvm-objdump
ADDR2LINE = llvm-addr2line
endif
# macOS using gcc - options copied from Tiny Metallic Unix Mode
ifeq ($(MODE), darwin)
CONFIG_CPPFLAGS += \
-DTINY \
-DNDEBUG \
-DTRUSTWORTHY \
-DSUPPORT_VECTOR=251
CONFIG_CCFLAGS += \
-Os \
-fno-align-functions \
-fno-align-jumps \
-fno-align-labels \
-fno-align-loops
TARGET_ARCH ?= \
-msse3
endif
# ANSI Mode
#
# These flags cause GCC to predefine __STRICT_ANSI__. Please be warned

View file

@ -54,23 +54,6 @@ GZ ?= gzip
CLANG = clang
FC = gfortran #/opt/cross9f/bin/x86_64-linux-musl-gfortran
# see build/compile, etc. which run third_party/gcc/unbundle.sh
AR = build/bootstrap/ar.com
PKG = build/bootstrap/package.com
MKDEPS = build/bootstrap/mkdeps.com
ZIPOBJ = build/bootstrap/zipobj.com
AS = o/third_party/gcc/bin/x86_64-linux-musl-as
CC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
CXX = o/third_party/gcc/bin/x86_64-linux-musl-g++
CXXFILT = o/third_party/gcc/bin/x86_64-linux-musl-c++filt
LD = o/third_party/gcc/bin/x86_64-linux-musl-ld.bfd
NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
OBJCOPY = o/third_party/gcc/bin/x86_64-linux-musl-objcopy
OBJDUMP = o/third_party/gcc/bin/x86_64-linux-musl-objdump
ADDR2LINE = $(shell pwd)/o/third_party/gcc/bin/x86_64-linux-musl-addr2line
COMMA := ,
PWD := $(shell pwd)
IMAGE_BASE_VIRTUAL ?= 0x400000

View file

@ -18,8 +18,10 @@
# links GCC runtimes when using later versions, so some concerns might
# not apply.
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
if [ x`uname -s` != xDarwin ]; then
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
fi
set -e

View file

@ -9,7 +9,7 @@
# This script is launched at the start of Makefile to detect if
# binfmt_misc was tuned to launch 'MZ' shell scripts under WINE
if [ x`uname -s` != xLinux ]; then
if [ x`uname -s` != xLinux -a x`uname -s` != xDarwin ]; then
cat <<'EOF' >&2
ERROR

View file

@ -8,6 +8,10 @@ if [ "$MODE" = opt ] || [ "$MODE" = optlinux ]; then
exit
fi
if [ "$MODE" = darwin ]; then
exit # TODO
fi
# smoke test userspace binary emulation
CMD="o/$MODE/tool/build/blinkenlights.com.dbg o/$MODE/examples/hello.com"
if OUTPUT="$($CMD)"; then

View file

@ -946,7 +946,9 @@ int main(int argc, char *argv[]) {
AddArg("-Wno-unused-command-line-argument");
AddArg("-Wno-incompatible-pointer-types-discards-qualifiers");
}
AddArg("-no-canonical-prefixes");
if (!IsXnu()) {
AddArg("-no-canonical-prefixes");
}
if (!__nocolor) {
AddArg(firstnonnull(colorflag, "-fdiagnostics-color=always"));
}