Makefile: macOS Package Manager & Compiler detection

This commit is contained in:
GammaTendonNine 2020-11-23 08:15:36 -06:00
parent 84a3e6e953
commit 11cad56dd3
3 changed files with 39 additions and 11 deletions

View File

@ -106,6 +106,32 @@ ifeq ($(WINDOWS_BUILD),1)
endif
endif
# macOS overrides
ifeq ($(HOST_OS),Darwin)
OSX_BUILD := 1
# Using MacPorts?
ifeq ($(shell test -d /opt/local/lib && echo y),y)
OSX_GCC_VER = $(shell find /opt/local/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
CC := gcc-mp-$(OSX_GCC_VER)
CXX := g++-mp-$(OSX_GCC_VER)
CPP := cpp-mp-$(OSX_GCC_VER) -P
PLATFORM_CFLAGS := -I /opt/local/include
PLATFORM_LDFLAGS := -L /opt/local/lib
else
# Using Homebrew?
ifeq ($(shell which brew >/dev/null 2>&1 && echo y),y)
OSX_GCC_VER = $(shell find `brew --prefix`/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
CC := gcc-$(OSX_GCC_VER)
CXX := g++-$(OSX_GCC_VER)
CPP := cpp-$(OSX_GCC_VER) -P
PLATFORM_CFLAGS := -I /usr/local/include
PLATFORM_LDFLAGS := -L /usr/local/lib
else
$(error No suitable macOS toolchain found, have you installed Homebrew?)
endif
endif
endif
ifneq ($(TARGET_BITS),0)
BITS := -m$(TARGET_BITS)
endif
@ -225,6 +251,7 @@ endif
# in the makefile that we want should cover assets.)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),cleantools)
ifneq ($(MAKECMDGOALS),distclean)
# Make sure assets exist
@ -237,11 +264,12 @@ endif
endif
# Make tools if out of date
DUMMY != make -C tools >&2 || echo FAIL
DUMMY != CC=$(CC) CXX=$(CXX) $(MAKE) -C tools >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to build tools)
endif
endif
endif
endif
@ -425,8 +453,9 @@ DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(
# Segment elf files
SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)
##################### Compiler Options #######################
INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
############################ Compiler Options ##################################
INCLUDE_CFLAGS := $(PLATFORM_CFLAGS) -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
# Huge deleted N64 section was here
@ -464,7 +493,6 @@ ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
OBJCOPY := objcopy
OBJDUMP := $(CROSS)objdump
else ifeq ($(OSX_BUILD),1)
CPP := cpp-9 -P
OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy
else # Linux & other builds
@ -481,7 +509,7 @@ SDLCONFIG := $(CROSS)sdl2-config
BACKEND_CFLAGS := -DRAPI_$(RENDER_API)=1 -DWAPI_$(WINDOW_API)=1 -DAAPI_$(AUDIO_API)=1
# can have multiple controller APIs
BACKEND_CFLAGS += $(foreach capi,$(CONTROLLER_API),-DCAPI_$(capi)=1)
BACKEND_LDFLAG0S :=
BACKEND_LDFLAGS :=
SDL1_USED := 0
SDL2_USED := 0
@ -635,7 +663,7 @@ else ifeq ($(TARGET_RPI),1)
LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie
else ifeq ($(OSX_BUILD),1)
LDFLAGS := -lm $(BACKEND_LDFLAGS) -no-pie -lpthread
LDFLAGS := -lm $(PLATFORM_LDFLAGS) $(BACKEND_LDFLAGS) -lpthread
else
LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm $(BACKEND_LDFLAGS) -no-pie -lpthread
@ -697,7 +725,7 @@ res: $(BASEPACK_PATH)
# prepares the basepack.lst
$(BASEPACK_LST): $(EXE)
@mkdir -p $(BUILD_DIR)/$(BASEDIR)
@echo -n > $(BASEPACK_LST)
@touch > $(BASEPACK_LST)
@echo "$(BUILD_DIR)/sound/bank_sets sound/bank_sets" >> $(BASEPACK_LST)
@echo "$(BUILD_DIR)/sound/sequences.bin sound/sequences.bin" >> $(BASEPACK_LST)
@echo "$(BUILD_DIR)/sound/sound_data.ctl sound/sound_data.ctl" >> $(BASEPACK_LST)

View File

@ -1,5 +1,5 @@
CC := gcc
CXX := g++
CC ?= gcc
CXX ?= g++
CFLAGS := -I../include -I. -Wall -Wextra -Wno-unused-parameter -pedantic -std=c99 -O2 -s
LDFLAGS := -lm
PROGRAMS := n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv
@ -38,7 +38,7 @@ skyconv_SOURCES := skyconv.c n64graphics.c utils.c
LIBAUDIOFILE := audiofile/libaudiofile.a
$(LIBAUDIOFILE):
@$(MAKE) -C audiofile
@CC=$(CC) CXX=$(CXX) $(MAKE) -C audiofile
all: $(LIBAUDIOFILE) $(PROGRAMS) $(CXX_PROGRAMS)

View File

@ -1,4 +1,4 @@
CXX := g++
CXX ?= g++
libaudiofile.a: audiofile.o
ar rcs libaudiofile.a audiofile.o