clean up some toolchain compatibility fixes

also rename the abs() macro to not cause any fucking conflicts ever again
This commit is contained in:
fgsfds 2020-05-19 22:22:52 +03:00
parent 06f02dc210
commit c57bacdfd7
5 changed files with 52 additions and 67 deletions

View file

@ -22,9 +22,16 @@ NON_MATCHING ?= 1
# Build and optimize for Raspberry Pi(s) # Build and optimize for Raspberry Pi(s)
TARGET_RPI ?= 0 TARGET_RPI ?= 0
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
# Makeflag to enable OSX fixes # Makeflag to enable OSX fixes
OSX_BUILD ?= 0 OSX_BUILD ?= 0
# Specify the target you are building for, TARGET_BITS=0 means native
TARGET_ARCH ?= native
TARGET_BITS ?= 0
# Disable better camera by default # Disable better camera by default
BETTERCAMERA ?= 0 BETTERCAMERA ?= 0
# Disable no drawing distance by default # Disable no drawing distance by default
@ -36,45 +43,35 @@ EXT_OPTIONS_MENU ?= 1
# Disable text-based save-files by default # Disable text-based save-files by default
TEXTSAVES ?= 0 TEXTSAVES ?= 0
# Disable no bzero/bcopy workaround by default # Various workarounds for weird toolchains
# Enable by default for MXE builds
ifeq ($(WINDOWS_BUILD),1) NO_BZERO_BCOPY ?= 0
ifeq ($(CROSS),i686-w64-mingw32.static-) NO_LDIV ?= 0
NO_BZERO_BCOPY := 1
else ifeq ($(CROSS),x86_64-w64-mingw32.static-) # Automatic settings for PC port(s)
NO_BZERO_BCOPY := 1
else NON_MATCHING := 1
NO_BZERO_BCOPY ?= 0 GRUCODE := f3dex2e
endif WINDOWS_BUILD ?= 0
else
NO_BZERO_BCOPY ?= 0 ifeq ($(TARGET_WEB),0)
ifeq ($(OS),Windows_NT)
WINDOWS_BUILD := 1
endif
endif endif
# Build for Emscripten/WebGL # MXE overrides
TARGET_WEB ?= 0
# Specify the target you are building for, 0 means native
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-)
TARGET_ARCH = i386pe
else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
TARGET_ARCH = i386pe
else
TARGET_ARCH ?= native
endif
else
TARGET_ARCH ?= native
endif
ifeq ($(WINDOWS_BUILD),1) ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-) ifeq ($(CROSS),i686-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 32 TARGET_BITS = 32
NO_BZERO_BCOPY := 1
else ifeq ($(CROSS),x86_64-w64-mingw32.static-) else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 64 TARGET_BITS = 64
else NO_BZERO_BCOPY := 1
TARGET_BITS ?= 0
endif endif
else
TARGET_BITS ?= 0
endif endif
ifneq ($(TARGET_BITS),0) ifneq ($(TARGET_BITS),0)
@ -83,18 +80,6 @@ else
BITS := BITS :=
endif endif
# Automatic settings for PC port(s)
NON_MATCHING := 1
GRUCODE := f3dex2e
WINDOWS_BUILD := 0
ifeq ($(TARGET_WEB),0)
ifeq ($(OS),Windows_NT)
WINDOWS_BUILD := 1
endif
endif
# Release (version) flag defs # Release (version) flag defs
ifeq ($(VERSION),jp) ifeq ($(VERSION),jp)
@ -449,7 +434,7 @@ ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
# Huge deleted N64 section was here # Huge deleted N64 section was here
AS := as AS := $(CROSS)as
ifeq ($(OSX_BUILD),1) ifeq ($(OSX_BUILD),1)
AS := i686-w64-mingw32-as AS := i686-w64-mingw32-as
@ -462,6 +447,8 @@ else
CC := emcc CC := emcc
endif endif
LD := $(CC)
ifeq ($(WINDOWS_BUILD),1) ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL
LD := $(CC) LD := $(CC)
@ -470,16 +457,13 @@ ifeq ($(WINDOWS_BUILD),1)
else else
LD := $(CXX) LD := $(CXX)
endif endif
else
LD := $(CC)
endif endif
ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
CPP := cpp -P CPP := cpp -P
OBJCOPY := objcopy OBJCOPY := objcopy
OBJDUMP := $(CROSS)objdump OBJDUMP := $(CROSS)objdump
else else ifeq ($(OSX_BUILD),1)
ifeq ($(OSX_BUILD),1)
CPP := cpp-9 -P CPP := cpp-9 -P
OBJDUMP := i686-w64-mingw32-objdump OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy OBJCOPY := i686-w64-mingw32-objcopy
@ -488,7 +472,6 @@ else # Linux & other builds
OBJCOPY := $(CROSS)objcopy OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump OBJDUMP := $(CROSS)objdump
endif endif
endif
PYTHON := python3 PYTHON := python3
SDLCONFIG := $(CROSS)sdl2-config SDLCONFIG := $(CROSS)sdl2-config
@ -545,6 +528,12 @@ ifeq ($(NO_BZERO_BCOPY),1)
CFLAGS += -DNO_BZERO_BCOPY CFLAGS += -DNO_BZERO_BCOPY
endif endif
# Use internal ldiv()/lldiv()
ifeq ($(NO_LDIV),1)
CC_CHECK += -DNO_LDIV
CFLAGS += -DNO_LDIV
endif
ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS) ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS)
ifeq ($(TARGET_WEB),1) ifeq ($(TARGET_WEB),1)

View file

@ -1,8 +1,9 @@
#ifndef STDLIB_H #ifndef STDLIB_H
#define STDLIB_H #define STDLIB_H
#ifndef TARGET_WEB #include <stdlib.h>
#ifdef NO_LDIV
typedef struct lldiv_t typedef struct lldiv_t
{ {
long long quot; long long quot;
@ -17,11 +18,6 @@ typedef struct ldiv_t
lldiv_t lldiv(long long num, long long denom); lldiv_t lldiv(long long num, long long denom);
ldiv_t ldiv(long num, long denom); ldiv_t ldiv(long num, long denom);
#else
#include <stdlib.h>
#endif #endif
#endif #endif

View file

@ -1,7 +1,8 @@
#include "libultra_internal.h" #include "libultra_internal.h"
#include <stdlib.h> #include "stdlib.h"
#ifdef NO_LDIV
#ifndef OSX_BUILD
lldiv_t lldiv(long long num, long long denom) { lldiv_t lldiv(long long num, long long denom) {
lldiv_t ret; lldiv_t ret;
@ -14,7 +15,6 @@ lldiv_t lldiv(long long num, long long denom) {
return ret; return ret;
} }
#endif // OSX_BUILD cannot use this
ldiv_t ldiv(long num, long denom) { ldiv_t ldiv(long num, long denom) {
ldiv_t ret; ldiv_t ret;
@ -28,3 +28,5 @@ ldiv_t ldiv(long num, long denom) {
return ret; return ret;
} }
#endif

View file

@ -29,11 +29,9 @@ extern f32 gCosineTable[];
#define sqr(x) ((x) * (x)) #define sqr(x) ((x) * (x))
#ifndef TARGET_WEB #define absx(x) ((x) < 0 ? -(x) : (x))
#define abs(x) ((x) < 0 ? -(x) : (x))
#else
#include "../../include/libc/stdlib.h" #include "../../include/libc/stdlib.h"
#endif
void *vec3f_copy(Vec3f dest, Vec3f src); void *vec3f_copy(Vec3f dest, Vec3f src);
void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z); void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);

View file

@ -925,10 +925,10 @@ void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Ve
} }
// Get cells we cross using DDA // Get cells we cross using DDA
if (abs(dir[0]) >= abs(dir[2])) if (absx(dir[0]) >= absx(dir[2]))
step = abs(dir[0]) / CELL_SIZE; step = absx(dir[0]) / CELL_SIZE;
else else
step = abs(dir[2]) / CELL_SIZE; step = absx(dir[2]) / CELL_SIZE;
dx = dir[0] / step / CELL_SIZE; dx = dir[0] / step / CELL_SIZE;
dz = dir[2] / step / CELL_SIZE; dz = dir[2] / step / CELL_SIZE;