Enable dependency tracking in makefile, so that changing a .h automatically causes .c files using it to be automatically recompiled

This commit is contained in:
UnknownShadow200 2024-04-13 08:52:20 +10:00
parent 4bda9ee2c1
commit 4a438fe907
4 changed files with 81 additions and 58 deletions

104
Makefile
View File

@ -9,6 +9,11 @@ DEL = rm -f
CFLAGS = -g -pipe -fno-math-errno
LDFLAGS = -g -rdynamic
# Enables dependency tracking (https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/)
# This ensures that changing a .h file automatically results in the .c files using it being auto recompiled when next running make
# On older systems the required GCC options may not be supported - in which case just change TRACK_DEPENDENCIES to 0
TRACK_DEPENDENCIES=1
ifndef $(PLAT)
ifeq ($(OS),Windows_NT)
PLAT = mingw
@ -18,86 +23,86 @@ ifndef $(PLAT)
endif
ifeq ($(PLAT),web)
CC = emcc
OEXT = .html
CFLAGS = -g
LDFLAGS = -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library $(SOURCE_DIR)/interop_web.js
CC = emcc
OEXT = .html
CFLAGS = -g
LDFLAGS = -s WASM=1 -s NO_EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_STACK=1Mb --js-library $(SOURCE_DIR)/interop_web.js
endif
ifeq ($(PLAT),mingw)
CC = gcc
OEXT = .exe
CFLAGS = -g -pipe -DUNICODE -fno-math-errno
LDFLAGS = -g
LIBS = -mwindows -lwinmm -limagehlp
CC = gcc
OEXT = .exe
CFLAGS = -g -pipe -DUNICODE -fno-math-errno
LDFLAGS = -g
LIBS = -mwindows -lwinmm -limagehlp
endif
ifeq ($(PLAT),linux)
CFLAGS = -g -pipe -fno-math-errno -DCC_BUILD_ICON
LIBS = -lX11 -lXi -lpthread -lGL -ldl
CFLAGS = -g -pipe -fno-math-errno -DCC_BUILD_ICON
LIBS = -lX11 -lXi -lpthread -lGL -ldl
endif
ifeq ($(PLAT),sunos)
CFLAGS = -g -pipe -fno-math-errno
LIBS = -lsocket -lX11 -lXi -lGL
CFLAGS = -g -pipe -fno-math-errno
LIBS = -lsocket -lX11 -lXi -lGL
endif
ifeq ($(PLAT),darwin)
OBJECTS += $(BUILD_DIR)/interop_cocoa.o
CFLAGS = -g -pipe -fno-math-errno -DCC_BUILD_ICON
LIBS =
LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc
OBJECTS += $(BUILD_DIR)/interop_cocoa.o
CFLAGS = -g -pipe -fno-math-errno -DCC_BUILD_ICON
LIBS =
LDFLAGS = -rdynamic -framework Cocoa -framework OpenGL -framework IOKit -lobjc
endif
ifeq ($(PLAT),freebsd)
CFLAGS = -g -pipe -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
CFLAGS = -g -pipe -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),openbsd)
CFLAGS = -g -pipe -I /usr/X11R6/include -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R6/lib -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
CFLAGS = -g -pipe -I /usr/X11R6/include -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R6/lib -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),netbsd)
CFLAGS = -g -pipe -I /usr/X11R7/include -I /usr/pkg/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R7/lib -L /usr/pkg/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
CFLAGS = -g -pipe -I /usr/X11R7/include -I /usr/pkg/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/X11R7/lib -L /usr/pkg/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),dragonfly)
CFLAGS = -g -pipe -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
CFLAGS = -g -pipe -I /usr/local/include -fno-math-errno -DCC_BUILD_ICON
LDFLAGS = -L /usr/local/lib -rdynamic
LIBS = -lexecinfo -lGL -lX11 -lXi -lpthread
endif
ifeq ($(PLAT),haiku)
OBJECTS += $(BUILD_DIR)/interop_BeOS.o
CFLAGS = -g -pipe -fno-math-errno
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
OBJECTS += $(BUILD_DIR)/interop_BeOS.o
CFLAGS = -g -pipe -fno-math-errno
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
endif
ifeq ($(PLAT),beos)
OBJECTS += $(BUILD_DIR)/interop_BeOS.o
CFLAGS = -g -pipe
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
OBJECTS += $(BUILD_DIR)/interop_BeOS.o
CFLAGS = -g -pipe
LDFLAGS = -g
LIBS = -lGL -lnetwork -lstdc++ -lbe -lgame -ltracker
endif
ifeq ($(PLAT),serenityos)
LIBS = -lgl -lSDL2
LIBS = -lgl -lSDL2
endif
ifeq ($(PLAT),irix)
CC = gcc
LIBS = -lGL -lX11 -lXi -lpthread -ldl
CC = gcc
LIBS = -lGL -lX11 -lXi -lpthread -ldl
endif
ifeq ($(OS),Windows_NT)
DEL = del
DEL = del
endif
default: $(PLAT)
@ -168,14 +173,31 @@ os/2:
clean:
$(DEL) $(OBJECTS)
$(ENAME): $(BUILD_DIR) $(OBJECTS)
$(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(LIBS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# NOTE: Tracking dependencies might not work on older systems - disable if so
ifeq ($(TRACK_DEPENDENCIES), 1)
# Compiling with dependency tracking
DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d
DEPFILES := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(C_SOURCES))
$(DEPFILES):
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c $(BUILD_DIR)/%.d
$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
include $(wildcard $(DEPFILES))
# Compiling WITHOUT dependency tracking
else
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
endif
# Platform specific file compiling
$(BUILD_DIR)/interop_cocoa.o: $(SOURCE_DIR)/interop_cocoa.m
$(CC) $(CFLAGS) -c $< -o $@

View File

@ -748,6 +748,16 @@ static void ApplyFog(float* values) {
C3D_FogLutBind(&fog_lut);
}
static float GetFogValue(float c) {
if (fogMode == FOG_LINEAR) {
return (fogEnd - c) / fogEnd;
} else if (fogMode == FOG_EXP) {
return expf(-(fogDensity * c));
} else {
return expf(-(fogDensity * c) * (fogDensity * c));
}
}
static void UpdateFog(void) {
float near = 0.01f;
float far = Game_ViewDistance;
@ -756,15 +766,8 @@ static void UpdateFog(void) {
// TODO: Exp calculation isn't right for lava ???
for (int i = 0; i <= 128; i ++)
{
float c = FogLut_CalcZ(i / 128.0f, near, far);
if (fogMode == FOG_LINEAR) {
values[i] = (fogEnd - c) / fogEnd;
} else if (fogMode == FOG_EXP) {
values[i] = expf(-fogDensity * c);
} else {
values[i] = expf(-fogDensity * c * c);
}
float c = FogLut_CalcZ(i / 128.0f, near, far);
values[i] = GetFogValue(c);
}
ApplyFog(values);
}

View File

@ -20,13 +20,12 @@
#include <imagehlp.h>
static HANDLE curProcess = CUR_PROCESS_HANDLE;
#elif defined CC_BUILD_OPENBSD || defined CC_BUILD_HAIKU || defined CC_BUILD_SERENITY
#include <signal.h>
/* These operating systems don't provide sys/ucontext.h */
/* But register constants be found from includes in <signal.h> */
#elif defined CC_BUILD_OS2
#include <signal.h>
#include <386/ucontext.h>
#include <signal.h>
/* These operating systems don't provide sys/ucontext.h */
/* But register constants be found from includes in <signal.h> */
#elif defined CC_BUILD_OS2
#include <signal.h>
#include <386/ucontext.h>
#elif defined CC_BUILD_LINUX || defined CC_BUILD_ANDROID
/* Need to define this to get REG_ constants */
#define _GNU_SOURCE

View File

@ -219,7 +219,6 @@ static inline float FogLut_CalcZ(float depth, float near, float far)
}
static void FogLut_FromArray(C3D_FogLut* lut, const float data[256]);
static void FogLut_Exp(C3D_FogLut* lut, float density, float gradient, float near, float far);
static void C3D_FogGasMode(GPU_FOGMODE fogMode, GPU_GASMODE gasMode, bool zFlip);
static void C3D_FogColor(u32 color);