Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
*.o
*.a
main
main.exe

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does removing these make it any cleaner?
This just allows the potential for people to add binaries to their fork of the repo.

main-sb*
main-lb*
output.txt
build
145 changes: 89 additions & 56 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
CUBIOMES_SRC := $(addprefix cubiomes/,biomenoise.c biomes.c finders.c generator.c layers.c noise.c)

LARGE_BIOMES ?= 0
UNBOUND ?= 0
MAKEFLAGS += -j$(if $(filter Windows_NT,$(OS)),$(NUMBER_OF_PROCESSORS),$(shell getconf _NPROCESSORS_ONLN))

LARGE_BIOMES ?= 0
UNBOUND ?= 0
PRINT_INTERVAL ?= 256


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this format change

# Auto-detect GPU architecture:
# - RTX 40xx/50xx series: sm_89 is faster than native sm_120
# - Everything else: use native
# Override manually with: make ARCH=sm_89
ifndef ARCH
GPU_NAMES := $(shell nvidia-smi --query-gpu=name --format=csv,noheader)
GPU_NAMES := $(shell nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think /dev/null is a thing on windows.

ifneq (,$(findstring RTX 40,$(GPU_NAMES)))
ARCH := sm_89
else ifneq (,$(findstring RTX 50,$(GPU_NAMES)))
Expand All @@ -19,78 +23,107 @@ ifndef ARCH
endif

$(info Using ARCH = $(ARCH))
override CFLAGS += -O3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this format change

override CFLAGS += -O3 -fwrapv

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do anything outside of cubiomes? We previously only applied it to cubiomes.

override CXXFLAGS += -O3 -std=c++20 -I asio/asio/include -DOMISSION_LARGE_BIOMES=$(LARGE_BIOMES) -DOMISSION_UNBOUND=$(UNBOUND) -DPRINT_INTERVAL=$(PRINT_INTERVAL)
override NVCC_FLAGS += $(CXXFLAGS) --expt-relaxed-constexpr --default-stream per-thread -arch=$(ARCH) -use_fast_math
override NVCC_FLAGS += $(CXXFLAGS) --expt-relaxed-constexpr --default-stream per-thread -arch=$(ARCH) -use_fast_math

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with the format changes

BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/obj

ifeq ($(OS),Windows_NT)
all: main.exe
SRC_CPP := $(wildcard src/*.cpp)
SRC_C := $(wildcard src/*.c)
SRC_GPU := src/gpu.cu
SRC := $(SRC_CPP) $(SRC_C) $(SRC_GPU)
SRC_HEADERS := $(wildcard src/*.h)

ifeq ($(MSYSTEM),)
MKDIR = if not exist $(subst /,\\,$(1)) mkdir $(subst /,\\,$(1))
RMDIR = if exist $(subst /,\\,$(1)) rmdir /s /q $(subst /,\\,$(1))
else
MKDIR = mkdir -p $(1)
RMDIR = rm -rf $(1)
endif
TARGET := $(BUILD_DIR)/main.exe
else
MKDIR = mkdir -p $(1)
RMDIR = rm -rf $(1)
TARGET := $(BUILD_DIR)/main
endif

SRC_CPP := $(wildcard src/*.cpp)
SRC_C := $(wildcard src/*.c)
SRC_CU := $(wildcard src/*.cu)
SRC := $(SRC_CPP) $(SRC_C) $(SRC_CU)
.PHONY: all clean

clean:
del /Q main.exe
all: $(TARGET)

# nvcc src/*.cpp src/*.c src/*.cu -o main.exe cubiomes/biomenoise.c cubiomes/biomes.c cubiomes/finders.c cubiomes/generator.c cubiomes/layers.c cubiomes/noise.c -arch=native -O3 -std=c++20 -I asio-1.34.2/include -DOMISSION_LARGE_BIOMES=1 --expt-relaxed-constexpr --default-stream per-thread -D_WIN32_WINNT=0x0601
main.exe: $(SRC) $(CUBIOMES_SRC)
ifeq ($(OS),Windows_NT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point in moving all the build stuff for windows out of the previous windows block if you're just gonna make a new windows block to put those things in instead?

$(TARGET): $(SRC) $(SRC_HEADERS) $(CUBIOMES_SRC)
$(call MKDIR,$(BUILD_DIR))
nvcc $(SRC) $(CUBIOMES_SRC) -o $@ $(NVCC_FLAGS) -D_WIN32_WINNT=0x0601
else
override NVCC_FLAGS += -ccbin $(CXX)
override NVCC_FLAGS += -ccbin $(CXX)
MAIN_OBJ_NAMES := main.o
CUBIOMES_LIB := $(OBJ_DIR)/libcubiomes.a
CUBIOMES_OBJS := $(addprefix $(OBJ_DIR)/,$(notdir $(CUBIOMES_SRC:.c=.o)))

MAIN_SRC := src/main.cpp
MAIN_DEP := $(MAIN_SRC) src/common.h
ifndef NO_GPU
MAIN_OBJ_NAMES += gpu.o
MAIN_CXX := nvcc
MAIN_CXXFLAGS += $(NVCC_FLAGS)
GPU_SRC := src/gpu.cu
else
MAIN_CXX := $(CXX)
MAIN_CXXFLAGS += $(CXXFLAGS) -DNO_GPU
endif

ifndef NO_GPU
MAIN_SRC += gpu.o
MAIN_DEP += gpu.o src/gpu.h
MAIN_CXX := nvcc
MAIN_CXXFLAGS += $(NVCC_FLAGS)
else
MAIN_CXX := $(CXX)
MAIN_CXXFLAGS += $(CXXFLAGS) -DNO_GPU
endif
ifndef NO_CPU
MAIN_OBJ_NAMES += cpu.o cubiomes.o
EXTRA_DEPS += $(CUBIOMES_LIB)
else
MAIN_CXXFLAGS += -DNO_CPU
endif

ifndef NO_CPU
MAIN_SRC += cpu.o cubiomes.o libcubiomes.a
MAIN_DEP += cpu.o cubiomes.o libcubiomes.a src/cpu.h
else
MAIN_CXXFLAGS += -DNO_CPU
endif
ifndef NO_NET
MAIN_OBJ_NAMES += client.o server.o
else
MAIN_CXXFLAGS += -DNO_NET
endif

ifndef NO_NET
MAIN_SRC += client.o server.o
MAIN_DEP += client.o server.o src/client.h src/server.h
else
MAIN_CXXFLAGS += -DNO_NET
endif
MAIN_OBJS := $(addprefix $(OBJ_DIR)/, $(MAIN_OBJ_NAMES))

all: main
$(MAIN_OBJS) $(CUBIOMES_LIB) $(CUBIOMES_OBJS): | $(OBJ_DIR)
$(TARGET): | $(BUILD_DIR)

clean:
rm -f main libcubiomes.a biomenoise.o biomes.o finders.o generator.o layers.o noise.o cubiomes.o gpu.o cpu.o client.o server.o
$(OBJ_DIR) $(BUILD_DIR):
$(call MKDIR,$@)

$(TARGET): $(MAIN_OBJS) $(EXTRA_DEPS)
$(MAIN_CXX) $(MAIN_OBJS) $(if $(filter $(CUBIOMES_LIB),$(EXTRA_DEPS)),$(CUBIOMES_LIB),) -o $@ $(MAIN_CXXFLAGS)

$(CUBIOMES_LIB): $(CUBIOMES_OBJS)
$(AR) rcs $@ $(CUBIOMES_OBJS)

libcubiomes.a: $(CUBIOMES_SRC)
$(CC) -c $(CUBIOMES_SRC) -fwrapv $(CFLAGS)
$(AR) rcs libcubiomes.a biomenoise.o biomes.o finders.o generator.o layers.o noise.o
$(CUBIOMES_OBJS): $(OBJ_DIR)/%.o: cubiomes/%.c
$(CC) -c $< -o $@ $(CFLAGS)

cubiomes.o: src/cubiomes.c src/cubiomes.h
$(CC) -c $< -o $@ $(CFLAGS)
$(OBJ_DIR)/cubiomes.o: src/cubiomes.c src/cubiomes.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these compile options will work on windows since they're under the else of your new conditional block.

$(CC) -c $< -o $@ $(CFLAGS)

gpu.o: src/gpu.cu src/gpu.h src/common.h src/Random.h src/kernel_0A.h src/kernel_0B.h
nvcc -c $< -o $@ $(NVCC_FLAGS)
$(OBJ_DIR)/gpu.o: $(GPU_SRC) src/gpu.h src/common.h src/Random.h src/kernel_0A.h src/kernel_0B.h
$(MAIN_CXX) -c $< -o $@ $(MAIN_CXXFLAGS)

cpu.o: src/cpu.cpp src/cpu.h src/common.h src/cubiomes.h
$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJ_DIR)/cpu.o: src/cpu.cpp src/cpu.h src/common.h src/cubiomes.h
$(CXX) -c $< -o $@ $(CXXFLAGS)

client.o: src/client.cpp src/client.h src/common.h
$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJ_DIR)/client.o: src/client.cpp src/client.h src/common.h
$(CXX) -c $< -o $@ $(CXXFLAGS)

server.o: src/server.cpp src/server.h src/common.h
$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJ_DIR)/server.o: src/server.cpp src/server.h src/common.h
$(CXX) -c $< -o $@ $(CXXFLAGS)

main: $(MAIN_DEP)
$(MAIN_CXX) $(MAIN_SRC) -o $@ $(MAIN_CXXFLAGS)
$(OBJ_DIR)/main.o: src/main.cpp src/common.h
$(MAIN_CXX) -c $< -o $@ $(MAIN_CXXFLAGS)
endif

clean:
$(call RMDIR,$(BUILD_DIR))