Makefile : Suppression non désirée des .jpg créés.

Résolu/Fermé
Fitz_ Messages postés 5 Date d'inscription jeudi 11 décembre 2014 Statut Membre Dernière intervention 11 décembre 2014 - Modifié par Fitz_ le 11/12/2014 à 23:21
Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017 - 11 déc. 2014 à 23:40
Bonsoir à tous!

J'ai lancé des recherches sur google, lu la FAQ du forum et les règles du site et recherché sur le forum sans résultats, je me permets donc de créer un sujet.

Petite présentation : Je suis actuellement étudiant en informatique (ensimag pour ceux qui connaissent) et un projet de Makefile nous a été donné à faire. Nous venons juste de découvrire les makefile donc mes connaissances restent relativement faibles mais je pense avoir compris le principe. Je travaille sous Centos 6.5 64 bits.

But du projet : à partir d'un répertoire source contenant des images .jpg, il nous est demandé de créer une page index.html dans un répertoire /dest qui affiche ces images redimenssionnées.

Le problème : Tout fonctionne, j'ai bien vérifié avec
makefile dest/index -rRd 
sauf qu'au final, j'ai :
Successfully remade target file `dest/index.html'.
Removing intermediate files...
rm dest/black_texture_terminal_background.jpg dest/hot-keely-hazell-looking-sexy.jpg dest/images.jpg dest/youm.jpg

Make supprime donc mes images redimenssionnées du dossier /dest ce qui fait qu'en tapant :
firefox /dest/index.html

Rien n'est affiché puisque les images appellées par index.html ne sont plus dans le dossier /dest.

Ma question : Pourquoi make considère-t-il ces fichiers comme intermédiaires? J'ai cru comprendre qu'en effet, make supprimait les fichiers qu'il avait eu besoin de créer au fur et à mesure de la compilation mais ceux-ci sont explicitement créés par moi-même? Est-il possible de lui demander de conserver ces fichiers ou dois-je changer quelque chose à mon code?

Mon Makefile :
# Source and destination directories, to be configured here:
SOURCE=~/Pictures
DEST=./dest

IMAGES=${shell cd $(SOURCE) && echo *.jpg}
THUMBS=$(IMAGES:%=$(DEST)/%)
IMAGE_DESC=$(IMAGES:%.jpg=$(DEST)/%.inc)


# TODO
$(DEST)/%.inc: $(DEST)/%.jpg
 ./generate-[/contents/391-fichier-img img]-fragment_make.sh $< > $@ 

$(DEST)/index.html: $(IMAGE_DESC)
 ./generate-index.sh --html_head >> $@ ; \
 for k in $(IMAGE_DESC) ; do \
 ./generate-index.sh $$k >> $@ ; \
 done ; \
 ./generate-index.sh --html_tail >> $@ ; 


$(DEST)/%.jpg: $(SOURCE)/%.jpg
 convert $< -[/download/telecharger-34076712-resize resize] 200x200 $@


Descriptions des scripts du Makefile

generate-img-fragment_make prend en argument $1 une image.jpg et donne le code html nécessaire.
generate-index.sh donne le head et le tail du html avec --html_head et --html_tail et effectue un simple cat $1 dans les autres cas.

Le verbose complet du make :

[Fitz@localhost squelette-tpl-unix]$ make dest/index.html -rRd
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-redhat-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `dest/index.html'.
 File `dest/index.html' does not exist.
  Considering target file `dest/black_texture_terminal_background.inc'.
   File `dest/black_texture_terminal_background.inc' does not exist.
   Looking for an implicit rule for `dest/black_texture_terminal_background.inc'.
   Trying pattern rule with stem `black_texture_terminal_background'.
   Trying implicit prerequisite `dest/black_texture_terminal_background.jpg'.
   Trying pattern rule with stem `black_texture_terminal_background'.
   Trying implicit prerequisite `dest/black_texture_terminal_background.jpg'.
   Looking for a rule with intermediate file `dest/black_texture_terminal_background.jpg'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `black_texture_terminal_background'.
    Trying implicit prerequisite `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
   Found an implicit rule for `dest/black_texture_terminal_background.inc'.
     Considering target file `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
      Looking for an implicit rule for `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
      No implicit rule found for `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
      Finished prerequisites of target file `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
     No need to remake target `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
   Considering target file `dest/black_texture_terminal_background.jpg'.
    File `dest/black_texture_terminal_background.jpg' does not exist.
     Pruning file `/home/Fitz/Pictures/black_texture_terminal_background.jpg'.
    Finished prerequisites of target file `dest/black_texture_terminal_background.jpg'.
   Must remake target `dest/black_texture_terminal_background.jpg'.
convert /home/Fitz/Pictures/black_texture_terminal_background.jpg -resize 200x200 dest/black_texture_terminal_background.jpg
Putting child 0x009425a0 (dest/black_texture_terminal_background.jpg) PID 4126 on the chain.
Live child 0x009425a0 (dest/black_texture_terminal_background.jpg) PID 4126 
Reaping winning child 0x009425a0 PID 4126 
Removing child 0x009425a0 PID 4126 from chain.
   Successfully remade target file `dest/black_texture_terminal_background.jpg'.
   Finished prerequisites of target file `dest/black_texture_terminal_background.inc'.
  Must remake target `dest/black_texture_terminal_background.inc'.
./generate-img-fragment_make.sh dest/black_texture_terminal_background.jpg > dest/black_texture_terminal_background.inc 
Putting child 0x0094e020 (dest/black_texture_terminal_background.inc) PID 4130 on the chain.
Live child 0x0094e020 (dest/black_texture_terminal_background.inc) PID 4130 
Reaping winning child 0x0094e020 PID 4130 
Removing child 0x0094e020 PID 4130 from chain.
  Successfully remade target file `dest/black_texture_terminal_background.inc'.
  Considering target file `dest/hot-keely-hazell-looking-sexy.inc'.
   File `dest/hot-keely-hazell-looking-sexy.inc' does not exist.
   Looking for an implicit rule for `dest/hot-keely-hazell-looking-sexy.inc'.
   Trying pattern rule with stem `hot-keely-hazell-looking-sexy'.
   Trying implicit prerequisite `dest/hot-keely-hazell-looking-sexy.jpg'.
   Trying pattern rule with stem `hot-keely-hazell-looking-sexy'.
   Trying implicit prerequisite `dest/hot-keely-hazell-looking-sexy.jpg'.
   Looking for a rule with intermediate file `dest/hot-keely-hazell-looking-sexy.jpg'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `hot-keely-hazell-looking-sexy'.
    Trying implicit prerequisite `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
   Found an implicit rule for `dest/hot-keely-hazell-looking-sexy.inc'.
     Considering target file `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
      Looking for an implicit rule for `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
      No implicit rule found for `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
      Finished prerequisites of target file `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
     No need to remake target `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
   Considering target file `dest/hot-keely-hazell-looking-sexy.jpg'.
    File `dest/hot-keely-hazell-looking-sexy.jpg' does not exist.
     Pruning file `/home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg'.
    Finished prerequisites of target file `dest/hot-keely-hazell-looking-sexy.jpg'.
   Must remake target `dest/hot-keely-hazell-looking-sexy.jpg'.
convert /home/Fitz/Pictures/hot-keely-hazell-looking-sexy.jpg -resize 200x200 dest/hot-keely-hazell-looking-sexy.jpg
Putting child 0x0094d910 (dest/hot-keely-hazell-looking-sexy.jpg) PID 4133 on the chain.
Live child 0x0094d910 (dest/hot-keely-hazell-looking-sexy.jpg) PID 4133 
Reaping winning child 0x0094d910 PID 4133 
Removing child 0x0094d910 PID 4133 from chain.
   Successfully remade target file `dest/hot-keely-hazell-looking-sexy.jpg'.
   Finished prerequisites of target file `dest/hot-keely-hazell-looking-sexy.inc'.
  Must remake target `dest/hot-keely-hazell-looking-sexy.inc'.
./generate-img-fragment_make.sh dest/hot-keely-hazell-looking-sexy.jpg > dest/hot-keely-hazell-looking-sexy.inc 
Putting child 0x0094d970 (dest/hot-keely-hazell-looking-sexy.inc) PID 4137 on the chain.
Live child 0x0094d970 (dest/hot-keely-hazell-looking-sexy.inc) PID 4137 
Reaping winning child 0x0094d970 PID 4137 
Removing child 0x0094d970 PID 4137 from chain.
  Successfully remade target file `dest/hot-keely-hazell-looking-sexy.inc'.
  Considering target file `dest/images.inc'.
   File `dest/images.inc' does not exist.
   Looking for an implicit rule for `dest/images.inc'.
   Trying pattern rule with stem `images'.
   Trying implicit prerequisite `dest/images.jpg'.
   Trying pattern rule with stem `images'.
   Trying implicit prerequisite `dest/images.jpg'.
   Looking for a rule with intermediate file `dest/images.jpg'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `images'.
    Trying implicit prerequisite `/home/Fitz/Pictures/images.jpg'.
   Found an implicit rule for `dest/images.inc'.
     Considering target file `/home/Fitz/Pictures/images.jpg'.
      Looking for an implicit rule for `/home/Fitz/Pictures/images.jpg'.
      No implicit rule found for `/home/Fitz/Pictures/images.jpg'.
      Finished prerequisites of target file `/home/Fitz/Pictures/images.jpg'.
     No need to remake target `/home/Fitz/Pictures/images.jpg'.
   Considering target file `dest/images.jpg'.
    File `dest/images.jpg' does not exist.
     Pruning file `/home/Fitz/Pictures/images.jpg'.
    Finished prerequisites of target file `dest/images.jpg'.
   Must remake target `dest/images.jpg'.
convert /home/Fitz/Pictures/images.jpg -resize 200x200 dest/images.jpg
Putting child 0x0094dd90 (dest/images.jpg) PID 4140 on the chain.
Live child 0x0094dd90 (dest/images.jpg) PID 4140 
Reaping winning child 0x0094dd90 PID 4140 
Removing child 0x0094dd90 PID 4140 from chain.
   Successfully remade target file `dest/images.jpg'.
   Finished prerequisites of target file `dest/images.inc'.
  Must remake target `dest/images.inc'.
./generate-img-fragment_make.sh dest/images.jpg > dest/images.inc 
Putting child 0x009501e0 (dest/images.inc) PID 4144 on the chain.
Live child 0x009501e0 (dest/images.inc) PID 4144 
Reaping winning child 0x009501e0 PID 4144 
Removing child 0x009501e0 PID 4144 from chain.
  Successfully remade target file `dest/images.inc'.
  Considering target file `dest/youm.inc'.
   File `dest/youm.inc' does not exist.
   Looking for an implicit rule for `dest/youm.inc'.
   Trying pattern rule with stem `youm'.
   Trying implicit prerequisite `dest/youm.jpg'.
   Trying pattern rule with stem `youm'.
   Trying implicit prerequisite `dest/youm.jpg'.
   Looking for a rule with intermediate file `dest/youm.jpg'.
    Avoiding implicit rule recursion.
    Trying pattern rule with stem `youm'.
    Trying implicit prerequisite `/home/Fitz/Pictures/youm.jpg'.
   Found an implicit rule for `dest/youm.inc'.
     Considering target file `/home/Fitz/Pictures/youm.jpg'.
      Looking for an implicit rule for `/home/Fitz/Pictures/youm.jpg'.
      No implicit rule found for `/home/Fitz/Pictures/youm.jpg'.
      Finished prerequisites of target file `/home/Fitz/Pictures/youm.jpg'.
     No need to remake target `/home/Fitz/Pictures/youm.jpg'.
   Considering target file `dest/youm.jpg'.
    File `dest/youm.jpg' does not exist.
     Pruning file `/home/Fitz/Pictures/youm.jpg'.
    Finished prerequisites of target file `dest/youm.jpg'.
   Must remake target `dest/youm.jpg'.
convert /home/Fitz/Pictures/youm.jpg -resize 200x200 dest/youm.jpg
Putting child 0x00950750 (dest/youm.jpg) PID 4147 on the chain.
Live child 0x00950750 (dest/youm.jpg) PID 4147 
Reaping winning child 0x00950750 PID 4147 
Removing child 0x00950750 PID 4147 from chain.
   Successfully remade target file `dest/youm.jpg'.
   Finished prerequisites of target file `dest/youm.inc'.
  Must remake target `dest/youm.inc'.
./generate-img-fragment_make.sh dest/youm.jpg > dest/youm.inc 
Putting child 0x009502b0 (dest/youm.inc) PID 4151 on the chain.
Live child 0x009502b0 (dest/youm.inc) PID 4151 
Reaping winning child 0x009502b0 PID 4151 
Removing child 0x009502b0 PID 4151 from chain.
  Successfully remade target file `dest/youm.inc'.
 Finished prerequisites of target file `dest/index.html'.
Must remake target `dest/index.html'.
./generate-index.sh --html_head >> dest/index.html ; \
 for k in ./dest/black_texture_terminal_background.inc ./dest/hot-keely-hazell-looking-sexy.inc ./dest/images.inc ./dest/youm.inc ; do \
 ./generate-index.sh $k >> dest/index.html ; \
 done ; \
 ./generate-index.sh --html_tail >> dest/index.html ; \

Putting child 0x00942230 (dest/index.html) PID 4155 on the chain.
Live child 0x00942230 (dest/index.html) PID 4155 
Reaping winning child 0x00942230 PID 4155 
Removing child 0x00942230 PID 4155 from chain.
Successfully remade target file `dest/index.html'.
Removing intermediate files...
rm dest/black_texture_terminal_background.jpg dest/hot-keely-hazell-looking-sexy.jpg dest/images.jpg dest/youm.jpg


Merci à ceux qui ont eu le courage de me lire et merci pour vos futures questions/réponses/critiques!

Bonne soirée!

EDIT :

Mon Makefile qui résout le problème grâce au lien de Sugel :
# Source and destination directories, to be configured here:
.SECONDARY:

SOURCE=~/Pictures
DEST=./dest

IMAGES=${shell cd $(SOURCE) && echo *.jpg}
THUMBS=$(IMAGES:%=$(DEST)/%)
IMAGE_DESC=$(IMAGES:%.jpg=$(DEST)/%.inc)


# TODO
$(DEST)/%.inc: $(DEST)/%.jpg
 ./generate-img-fragment_make.sh $< > $@ 

$(DEST)/index.html: $(IMAGE_DESC)
 ./generate-index.sh --html_head >> $@ ; \
 for k in $(IMAGE_DESC) ; do \
 ./generate-index.sh $$k >> $@ ; \
 done ; \
 ./generate-index.sh --html_tail >> $@ ; 


$(DEST)/%.jpg: $(SOURCE)/%.jpg
 convert $< -resize 200x200 $@


gallery:

view:

clean:

all:
$(THUMBS):


Si quelqu'un a des explications du pourquoi du commennt mes .jpg étaient supprimés, je suis preneur!

1 réponse

Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017 724
11 déc. 2014 à 22:57
Je n'ai jamais touché à un makefile, mais je vois bien le problème...

Une jolie explication du problème ici:
http://www.thinkplexx.com/learn/howto/build-chain/make-based/prevent-gnu-make-from-always-removing-files-it-says-things-like-rm-or-removing-intermediate-files

PS:
*https://minus.com/lWD5Pflv6il3d* HUM HUM...
-1
Fitz_ Messages postés 5 Date d'inscription jeudi 11 décembre 2014 Statut Membre Dernière intervention 11 décembre 2014
11 déc. 2014 à 23:00
Je vais lire de ce pas, merci de ta réponse et du temps que tu as consacré à la lecture du topic (qui a dû être conséquent vu que tu as trouvé du premier coup le troll ! :p)
0
Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017 724
11 déc. 2014 à 23:07
Je n'y ai pas passé tant de temps que ça, j'ai juste l'oeil aimanté par ce genre de choses :3
0
Fitz_ Messages postés 5 Date d'inscription jeudi 11 décembre 2014 Statut Membre Dernière intervention 11 décembre 2014 > Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017
11 déc. 2014 à 23:15
Haha!

En tout cas, je ne serais te dire assez merci car la simple implémentation de la partie 3 du lien m'a résolu mon problème!

Voilà mon makefile actuel :
# Source and destination directories, to be configured here:
.SECONDARY:

SOURCE=~/Pictures
DEST=./dest

IMAGES=${shell cd $(SOURCE) && echo *.jpg}
THUMBS=$(IMAGES:%=$(DEST)/%)
IMAGE_DESC=$(IMAGES:%.jpg=$(DEST)/%.inc)


# TODO
$(DEST)/%.inc: $(DEST)/%.jpg
./generate-img-fragment_make.sh $< > $@

$(DEST)/index.html: $(IMAGE_DESC)
./generate-index.sh --html_head >> $@ ; \
for k in $(IMAGE_DESC) ; do \
./generate-index.sh $$k >> $@ ; \
done ; \
./generate-index.sh --html_tail >> $@ ;


$(DEST)/%.jpg: $(SOURCE)/%.jpg
convert $< -resize 200x200 $@


gallery:

view:

clean:

all:
$(THUMBS):
0
Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017 724
11 déc. 2014 à 23:18
Essaie de supprimer les vrais intermédiaires si il y en a...
0
Fitz_ Messages postés 5 Date d'inscription jeudi 11 décembre 2014 Statut Membre Dernière intervention 11 décembre 2014 > Sugel Messages postés 4070 Date d'inscription jeudi 18 août 2011 Statut Membre Dernière intervention 19 juin 2017
11 déc. 2014 à 23:24
Oui, il reste les fichiers.inc qui contiennent le code http lié à chaque image.


$(DEST)/index.html: $(IMAGE_DESC)
./generate-index.sh --html_head >> $@ ; \
for k in $(IMAGE_DESC) ; do \
./generate-index.sh $$k >> $@ ; \
done ; \
./generate-index.sh --html_tail >> $@ ; \
rm $(IMAGE_DESC) ;

devrait convenir, non? Je vais essayer.
0