# engine.mk -- compilation du moteur embarqué, de ses données et d'engine-cli. # # Lancé dans l'image Docker ustagammon/build-c par `make engine` (Makefile # racine), depuis la racine du dépôt. Tout est produit dans build/ : # # build/libengine.a le moteur : cœur de gnubg + shim GLib + engine.c # build/engine-cli le programme en ligne de commande # build/data/ les données lues par le moteur à l'exécution # build/host/ les outils officiels de gnubg qui génèrent les # données (makeweights, makebearoff), avec la vraie GLib # # Les dépendances vers les en-têtes sont suivies (-MMD) : un second appel ne # recompile rien si aucune source n'a changé. BUILD := build GNUBG := engine/gnubg COMPAT := engine/compat CC := gcc AR := ar # Options du build officiel de gnubg (configure.ac) : -O3 -ffast-math et # assertions GLib désactivées. Elles s'appliquent à tout le code, pour que # le moteur calcule comme gnubg de bureau. OPTIMISATION := -O3 -ffast-math -DG_DISABLE_ASSERT # Notre propre C : C11 strict, aucun avertissement toléré. OUR_WARNINGS := -std=c11 -Wall -Wextra -Werror # Code de gnubg : compilé tel quel, avec ses propres réglages d'avertissement. GNUBG_WARNINGS := ENGINE_INCLUDES := -I$(COMPAT) -I$(COMPAT)/glib-shim -I$(GNUBG) -I$(GNUBG)/lib -Iengine/include HOST_INCLUDES := -I$(COMPAT) -I$(GNUBG) -I$(GNUBG)/lib $(shell pkg-config --cflags glib-2.0) HOST_DEFINES := -DLOCALEDIR=\"/usr/share/locale\" HOST_LIBS := $(shell pkg-config --libs glib-2.0) -lm # Fichiers de gnubg compilés dans le moteur (liste : engine/gnubg/PROVENANCE.md). GNUBG_CORE := eval.c positionid.c matchid.c matchequity.c mec.c bearoff.c \ bearoffgammon.c mtsupport.c lib/neuralnet.c lib/neuralnetsse.c lib/inputs.c \ lib/cache.c lib/list.c lib/isaac.c lib/md5.c GNUBG_ENGINE := $(GNUBG_CORE) drawboard.c ENGINE_OBJECTS := $(GNUBG_ENGINE:%.c=$(BUILD)/obj/gnubg/%.o) \ $(BUILD)/obj/compat/glib-shim.o $(BUILD)/obj/compat/gnubg-support.o \ $(BUILD)/obj/engine.o CLI_OBJECTS := $(BUILD)/obj/engine-cli/main.o HOST_CORE_OBJECTS := $(GNUBG_CORE:%.c=$(BUILD)/host/gnubg/%.o) $(BUILD)/host/compat/gnubg-support.o DATA := $(BUILD)/data/gnubg.wd $(BUILD)/data/gnubg_os0.bd $(BUILD)/data/gnubg_ts0.bd \ $(BUILD)/data/Kazaross-XG2.xml .PHONY: all all: $(BUILD)/engine-cli $(DATA) # ------------------------------------------------------------------ Moteur $(BUILD)/obj/gnubg/%.o: $(GNUBG)/%.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(GNUBG_WARNINGS) $(ENGINE_INCLUDES) -MMD -MP -c $< -o $@ $(BUILD)/obj/compat/%.o: $(COMPAT)/%.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(OUR_WARNINGS) $(ENGINE_INCLUDES) -MMD -MP -c $< -o $@ $(BUILD)/obj/engine.o: engine/engine.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(OUR_WARNINGS) $(ENGINE_INCLUDES) -MMD -MP -c $< -o $@ $(BUILD)/obj/engine-cli/%.o: engine-cli/%.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(OUR_WARNINGS) -Iengine/include -MMD -MP -c $< -o $@ $(BUILD)/libengine.a: $(ENGINE_OBJECTS) rm -f $@ $(AR) rcs $@ $^ $(BUILD)/engine-cli: $(CLI_OBJECTS) $(BUILD)/libengine.a $(CC) $^ -lm -o $@ # ----------------------------------------- Outils de génération des données $(BUILD)/host/gnubg/%.o: $(GNUBG)/%.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(GNUBG_WARNINGS) $(HOST_INCLUDES) $(HOST_DEFINES) -MMD -MP -c $< -o $@ $(BUILD)/host/compat/%.o: $(COMPAT)/%.c @mkdir -p $(@D) $(CC) $(OPTIMISATION) $(OUR_WARNINGS) $(HOST_INCLUDES) -MMD -MP -c $< -o $@ $(BUILD)/host/makeweights: $(BUILD)/host/gnubg/makeweights.o $(BUILD)/host/gnubg/lib/neuralnet.o \ $(BUILD)/host/gnubg/lib/neuralnetsse.o $(BUILD)/host/compat/gnubg-support.o $(CC) $^ $(HOST_LIBS) -o $@ $(BUILD)/host/makebearoff: $(BUILD)/host/gnubg/makebearoff.o $(HOST_CORE_OBJECTS) \ $(BUILD)/host/compat/host-tools-support.o $(CC) $^ $(HOST_LIBS) -o $@ # ------------------------------------------------------------------ Données # Mêmes commandes que le Makefile.am de gnubg. Écriture dans un fichier # temporaire, pour ne jamais laisser une base à moitié écrite. $(BUILD)/data/gnubg.wd: engine/data/gnubg.weights $(BUILD)/host/makeweights @mkdir -p $(@D) $(BUILD)/host/makeweights -f $@.tmp $< mv $@.tmp $@ # Comme dans gnubg, les bases ne sont générées que si elles manquent : elles # ne dépendent pas du code (longues à produire). $(BUILD)/data/gnubg_os0.bd: | $(BUILD)/host/makebearoff @mkdir -p $(@D) $(BUILD)/host/makebearoff -o 6 -s 7999999 -f $@.tmp mv $@.tmp $@ $(BUILD)/data/gnubg_ts0.bd: | $(BUILD)/host/makebearoff @mkdir -p $(@D) $(BUILD)/host/makebearoff -t 6x6 -f $@.tmp mv $@.tmp $@ $(BUILD)/data/Kazaross-XG2.xml: engine/data/Kazaross-XG2.xml @mkdir -p $(@D) cp $< $@ -include $(shell find $(BUILD) -name '*.d' 2>/dev/null)