diff --git a/Makefile b/Makefile index 49f05be43..bba865fe0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build/compiler.mk b/build/compiler.mk new file mode 100644 index 000000000..c641d684c --- /dev/null +++ b/build/compiler.mk @@ -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 diff --git a/build/config.mk b/build/config.mk index 17827a02e..427b8b8ce 100644 --- a/build/config.mk +++ b/build/config.mk @@ -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 diff --git a/build/definitions.mk b/build/definitions.mk index 7a08e72a7..e7310250d 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -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 diff --git a/build/getccversion b/build/getccversion index ed74ba39a..f0bc8cf86 100755 --- a/build/getccversion +++ b/build/getccversion @@ -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 diff --git a/build/sanitycheck b/build/sanitycheck index c2da2d263..235d10af4 100755 --- a/build/sanitycheck +++ b/build/sanitycheck @@ -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 diff --git a/test/libc/release/emulate.sh b/test/libc/release/emulate.sh index cb9152877..416450c12 100755 --- a/test/libc/release/emulate.sh +++ b/test/libc/release/emulate.sh @@ -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 diff --git a/tool/build/compile.c b/tool/build/compile.c index a30df1e30..164c99676 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -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")); }