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)
TARGET_RPI ?= 0
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
# Makeflag to enable OSX fixes
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
BETTERCAMERA ?= 0
# Disable no drawing distance by default
@ -36,45 +43,35 @@ EXT_OPTIONS_MENU ?= 1
# Disable text-based save-files by default
TEXTSAVES ?= 0
# Disable no bzero/bcopy workaround by default
# Enable by default for MXE builds
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-)
NO_BZERO_BCOPY := 1
else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
NO_BZERO_BCOPY := 1
else
# Various workarounds for weird toolchains
NO_BZERO_BCOPY ?= 0
NO_LDIV ?= 0
# 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
else
NO_BZERO_BCOPY ?= 0
endif
# Build for Emscripten/WebGL
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
# MXE overrides
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 32
NO_BZERO_BCOPY := 1
else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
TARGET_ARCH = i386pe
TARGET_BITS = 64
else
TARGET_BITS ?= 0
NO_BZERO_BCOPY := 1
endif
else
TARGET_BITS ?= 0
endif
ifneq ($(TARGET_BITS),0)
@ -83,18 +80,6 @@ else
BITS :=
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
ifeq ($(VERSION),jp)
@ -449,7 +434,7 @@ ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
# Huge deleted N64 section was here
AS := as
AS := $(CROSS)as
ifeq ($(OSX_BUILD),1)
AS := i686-w64-mingw32-as
@ -462,6 +447,8 @@ else
CC := emcc
endif
LD := $(CC)
ifeq ($(WINDOWS_BUILD),1)
ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL
LD := $(CC)
@ -470,16 +457,13 @@ ifeq ($(WINDOWS_BUILD),1)
else
LD := $(CXX)
endif
else
LD := $(CC)
endif
ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
CPP := cpp -P
OBJCOPY := objcopy
OBJDUMP := $(CROSS)objdump
else
ifeq ($(OSX_BUILD),1)
else ifeq ($(OSX_BUILD),1)
CPP := cpp-9 -P
OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy
@ -488,7 +472,6 @@ else # Linux & other builds
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
endif
endif
PYTHON := python3
SDLCONFIG := $(CROSS)sdl2-config
@ -545,6 +528,12 @@ ifeq ($(NO_BZERO_BCOPY),1)
CFLAGS += -DNO_BZERO_BCOPY
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)
ifeq ($(TARGET_WEB),1)

View File

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

View File

@ -1,7 +1,8 @@
#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 ret;
@ -14,7 +15,6 @@ lldiv_t lldiv(long long num, long long denom) {
return ret;
}
#endif // OSX_BUILD cannot use this
ldiv_t ldiv(long num, long denom) {
ldiv_t ret;
@ -28,3 +28,5 @@ ldiv_t ldiv(long num, long denom) {
return ret;
}
#endif

View File

@ -29,11 +29,9 @@ extern f32 gCosineTable[];
#define sqr(x) ((x) * (x))
#ifndef TARGET_WEB
#define abs(x) ((x) < 0 ? -(x) : (x))
#else
#define absx(x) ((x) < 0 ? -(x) : (x))
#include "../../include/libc/stdlib.h"
#endif
void *vec3f_copy(Vec3f dest, Vec3f src);
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
if (abs(dir[0]) >= abs(dir[2]))
step = abs(dir[0]) / CELL_SIZE;
if (absx(dir[0]) >= absx(dir[2]))
step = absx(dir[0]) / CELL_SIZE;
else
step = abs(dir[2]) / CELL_SIZE;
step = absx(dir[2]) / CELL_SIZE;
dx = dir[0] / step / CELL_SIZE;
dz = dir[2] / step / CELL_SIZE;