dos-3D-Engine/Makefile
2026-05-15 15:17:48 +02:00

88 lines
No EOL
2.7 KiB
Makefile

# --- Options de Build ---
# Valeurs possibles : causeway (recommandé), dos4g (classique)
EXTENDER = causeway
STACK_SIZE = 64k
WATCOM_WIN = D:\WatCom
WATCOM_WSL = /mnt/d/WatCom
NASM_WIN = /mnt/c/Program\ Files/NASM/nasm.exe
# --- Configuration Dynamique du Linker ---
ifeq ($(EXTENDER), causeway)
# Configuration optimisée pour CauseWay
L_SYS = system causeway
L_OPTS = option osname='CauseWay' \
option stub=$(WATCOM_WIN)/binw/cwstub.exe \
option stack=$(STACK_SIZE)
else
# Configuration classique pour DOS/4GW
L_SYS = system dos4g
L_OPTS = option stack=$(STACK_SIZE)
endif
# Binaires Windows exécutés par WSL
CC = $(WATCOM_WSL)/binnt64/wcc386.exe
CXX = $(WATCOM_WSL)/binnt64/wpp386.exe
AS = $(NASM_WIN)
LINK = $(WATCOM_WSL)/binnt64/wlink.exe
# --- Flags de Performance ---
# On utilise wslpath pour que les outils Windows comprennent les chemins Linux
INC_FLAGS = -i="$(WATCOM_WIN)\h" -i="$(WATCOM_WIN)\CustomH"
CFLAGS = -bt=dos -6s -fp6 -ox -od -oh -ot -ei -zp8 $(INC_FLAGS)
LFLAGS = $(L_SYS) $(L_OPTS) \
libpath "$(WATCOM_WIN)\lib386" \
libpath "$(WATCOM_WIN)\lib386\dos" \
libpath "$(WATCOM_WIN)\CustomLib"
# --- Détection des Sources ---
# On force le shell à trouver les fichiers
SRCS_CPP := $(shell find src -name "*.cpp")
SRCS_C := $(shell find src -name "*.c")
SRCS_ASM := $(shell find src -name "*.asm")
# Création de la liste des objets (src/main/main.cpp -> build/main.obj)
OBJS := $(patsubst src/%.cpp, build/%.obj, $(SRCS_CPP)) \
$(patsubst src/%.c, build/%.obj, $(SRCS_C)) \
$(patsubst src/%.asm, build/%.obj, $(SRCS_ASM))
# --- Règles ---
all: prepare build/app.exe
prepare:
@mkdir -p build
@# Crée les sous-dossiers dans build pour correspondre à src
@$(foreach dir, $(sort $(dir $(SRCS_CPP) $(SRCS_C) $(SRCS_ASM))), mkdir -p $(subst src,build,$(dir));)
build/%.obj: src/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CFLAGS) $< -fo='$(shell wslpath -w $@)'
@rm -f $*.err
build/%.obj: src/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $< -fo='$(shell wslpath -w $@)'
@rm -f $*.err
build/%.obj: src/%.asm
@mkdir -p $(dir $@)
$(AS) -f obj $< -o '$(shell wslpath -w $@)'
# --- PARTIE LINK CORRIGÉE ---
build/app.exe: $(OBJS) MakeFile
@if [ -z "$(OBJS)" ]; then echo "ERREUR: Aucun objet trouvé!"; exit 1; fi
@echo "Generating linker file: build/link.lnk"
@printf '%s\n' '$(LFLAGS)' > build/link.lnk
@printf 'name %s\n' '$(shell wslpath -w $@)' >> build/link.lnk
@$(foreach f,$(OBJS),printf 'file %s\n' '$(shell wslpath -w $f)' >> build/link.lnk;)
@echo "Linking..."
$(LINK) @build/link.lnk
clean:
rm -rf build/*.obj build/*.exe
# Nettoyage des logs d'erreurs
rm -f *.err src/**/*.err
cleanall:
@$(MAKE) clean
@$(MAKE) all