Amélioration du Makefile

This commit is contained in:
Moncef STITI 2025-03-11 18:24:29 +01:00
parent 80bdd3c964
commit 17d26395b8
2 changed files with 119 additions and 33 deletions

144
Makefile

@ -1,6 +1,6 @@
# Définition des variables
PACKAGE = fr.monlouyan.bakefile
ENTRY = Main
SOURCEDIR = ./src/fr/monlouyan/bakefile/
BUILDDIR = ./build/
DOCDIR = ./doc/
JARNAME = bakefile.jar
@ -9,42 +9,120 @@ MANIFESTPATH = Manifest.MF
SOURCEDIR = ./src/
TESTDIR = ./tests/
SOURCES := $(shell find $(SOURCEDIR) -name '*.java')
# Liste des fichiers source et leurs correspondances en .class
BAKECLI_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakeCLI.class
TIMESTAMPMANAGER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/TimestampManager.class
BAKEFILEPARSER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakefileParser.class
DEPENDENCYRESOLVER_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/DependencyResolver.class
COMMANDEXECUTOR_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/CommandExecutor.class
BAKEENGINE_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/BakeEngine.class
RULE_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/Rule.class
MAIN_CLASS = $(BUILDDIR)fr/monlouyan/bakefile/Main.class
all:
@make clean
@make compile
@make jar
# Fichiers source
BAKECLI_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakeCLI.java
TIMESTAMPMANAGER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/TimestampManager.java
BAKEFILEPARSER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakefileParser.java
DEPENDENCYRESOLVER_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/DependencyResolver.java
COMMANDEXECUTOR_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/CommandExecutor.java
BAKEENGINE_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/BakeEngine.java
RULE_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/Rule.java
MAIN_SRC = $(SOURCEDIR)fr/monlouyan/bakefile/Main.java
compile:
@echo "Compiling..."
javac -cp $(CLASSP) -d $(BUILDDIR) $(SOURCES) -Xlint:unchecked -Xlint:deprecation
@echo "Done."
# Cible principale
all: init $(JARNAME) deploy-tests
# Initialiser les répertoires nécessaires
init:
@echo "Création des répertoires nécessaires..."
@mkdir -p $(BUILDDIR)
@mkdir -p $(BUILDDIR)fr/monlouyan/bakefile/
@echo "Répertoires créés."
# ---- Phase 1: Compilation des classes sans dépendances circulaires ----
phase1: init $(BAKECLI_CLASS) $(TIMESTAMPMANAGER_CLASS)
$(BAKECLI_CLASS): $(BAKECLI_SRC)
@echo "Compilation de BakeCLI.java..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
$(TIMESTAMPMANAGER_CLASS): $(TIMESTAMPMANAGER_SRC)
@echo "Compilation de TimestampManager.java..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
# ---- Phase 2: Création de stubs pour gérer les dépendances circulaires ----
STUBS_DIR = $(BUILDDIR)stubs/fr/monlouyan/bakefile/
RULE_STUB = $(STUBS_DIR)Rule.java
BAKEENGINE_STUB = $(STUBS_DIR)BakeEngine.java
stubs: phase1
@echo "Création des stubs pour les classes avec dépendances circulaires..."
@mkdir -p $(STUBS_DIR)
@echo "package fr.monlouyan.bakefile; public class Rule { private String name; private java.util.List<String> dependencies; private java.util.List<String> commands; private boolean isPhony; public Rule(String name, java.util.List<String> dependencies, java.util.List<String> commands, boolean isPhony) { this.name = name; this.dependencies = dependencies; this.commands = commands; this.isPhony = isPhony; } public String getName() { return name; } public java.util.List<String> getDependencies() { return dependencies; } public java.util.List<String> getCommands() { return commands; } public boolean isPhony() { return isPhony; } public boolean needsUpdate() { return false; } public boolean isEmpty() { return dependencies.isEmpty() && commands.isEmpty(); } }" > $(RULE_STUB)
@echo "package fr.monlouyan.bakefile; public class BakeEngine { public void run() {} public static boolean hasRule(String target) { return false; } public static Rule getRule(String target) { return null; } }" > $(BAKEENGINE_STUB)
@javac -cp $(CLASSP) -d $(BUILDDIR) $(STUBS_DIR)*.java
@echo "Stubs créés."
# ---- Phase 3: Compilation des classes avec stubs pour résoudre les dépendances circulaires ----
phase3: stubs $(BAKEFILEPARSER_CLASS) $(DEPENDENCYRESOLVER_CLASS) $(COMMANDEXECUTOR_CLASS)
$(BAKEFILEPARSER_CLASS): $(BAKEFILEPARSER_SRC)
@echo "Compilation de BakefileParser.java avec stubs..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
$(DEPENDENCYRESOLVER_CLASS): $(DEPENDENCYRESOLVER_SRC)
@echo "Compilation de DependencyResolver.java avec stubs..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
$(COMMANDEXECUTOR_CLASS): $(COMMANDEXECUTOR_SRC)
@echo "Compilation de CommandExecutor.java avec stubs..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
# ---- Phase 4: Compilation finale des classes avec dépendances circulaires ----
phase4: phase3 $(BAKEENGINE_CLASS) $(RULE_CLASS) $(MAIN_CLASS)
$(BAKEENGINE_CLASS): $(BAKEENGINE_SRC)
@echo "Compilation finale de BakeEngine.java..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
$(RULE_CLASS): $(RULE_SRC)
@echo "Compilation finale de Rule.java..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
$(MAIN_CLASS): $(MAIN_SRC)
@echo "Compilation de Main.java..."
@javac -cp $(CLASSP) -d $(BUILDDIR) $< -Xlint:unchecked -Xlint:deprecation
# Création du fichier JAR (dépend de phase4 pour s'assurer que tout est compilé)
$(JARNAME): phase4
@echo "Création du fichier JAR..."
@jar cfm $(JARNAME) $(MANIFESTPATH) -C $(BUILDDIR) fr/monlouyan/bakefile
@echo "Fichier JAR créé : $(JARNAME)"
# Génération de la documentation Javadoc
javadoc:
@echo "Génération de la documentation Javadoc..."
@javadoc -d $(DOCDIR) -sourcepath $(SOURCEDIR) -subpackages $(PACKAGE)
@echo "Documentation Javadoc générée dans $(DOCDIR)"
see-javadoc: javadoc
@echo "Ouverture de la documentation Javadoc sur Firefox..."
@firefox $(DOCDIR)/index.html
# Déploiement du JAR dans les répertoires de test
deploy-tests: $(JARNAME)
@echo "Déploiement du JAR dans les répertoires de test..."
@find $(TESTDIR) -type d -name 'bake' -exec cp $(JARNAME) {} \;
@echo "Déploiement terminé."
# Nettoyage des fichiers générés
clean:
@echo "Cleaning up..."
@rm -rf $(BUILDDIR)* $(DOCDIR)*
@echo "Nettoyage des fichiers générés..."
@rm -rf $(BUILDDIR)
@rm -rf $(DOCDIR)
@rm -f $(JARNAME)
@find $(TESTDIR) -name "$(JARNAME)" -delete
@echo "Done."
@echo "Nettoyage terminé."
javadoc:
@echo "Generating javadoc..."
@javadoc -d $(DOCDIR) -sourcepath src -subpackages $(PACKAGE)
@echo "Done."
jar:
@echo "Creating jar..."
@jar cfm $(JARNAME) $(MANIFESTPATH) -C $(BUILDDIR) fr/monlouyan/bakefile
@echo "Done."
@make deploy-tests
deploy-tests:
@echo "Deploying JAR to 'bake' directories..."
@find $(TESTDIR) -type d -name 'bake' -exec cp $(JARNAME) {} \;
@echo "Done."
run_test:
@echo "Running tests..."
@java -cp build fr.monlouyan.bakefile.tests.BakeTestRunner
@echo "Done."
# Cibles spéciales
.PHONY: all init phase1 stubs phase3 phase4 javadoc deploy-tests clean

@ -33,6 +33,14 @@ Le répertoire **tests** contient une liste de tests pour vérifier que Bake ré
- **Contenu**:
- **[README.md](./tests/README.md)** : Documentation qui explique l'utilisation des tests.
Pour générer et visualiser la documentation JavaDoc :
```bash
# Générer uniquement la JavaDoc
make javadoc
# Générer et afficher la JavaDoc dans votre navigateur
make see-javadoc
```
## Documentation
Le répertoire **documentation** contient un rapport et des diagrammes détaillant le fonctionnement de Bake.