@@ -470,7 +470,8 @@ def emit(*args, into=None):
470470
471471def emit_rule (self , ins , outs , cmds = [], label = None ):
472472 name = self .name
473- fins = set (filenamesof (ins ))
473+ fins_list = filenamesof (ins )
474+ fins = set (fins_list )
474475 fouts = filenamesof (outs )
475476 nonobjs = [f for f in fouts if not f .startswith ("$(OBJ)" )]
476477
@@ -481,21 +482,22 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
481482 emit ("clean::" , into = lines )
482483 emit ("\t $(hide) rm -f" , * nonobjs , into = lines )
483484
485+ hashable = cmds + fins_list + fouts
486+ hash = hashlib .sha1 (bytes ("\n " .join (hashable ), "utf-8" )).hexdigest ()
487+ hashfile = join (self .dir , f"hash_{ hash } " )
488+
484489 emit (".PHONY:" , name , into = lines )
485490 if outs :
486- emit (name , ":" , * fouts , into = lines )
487- if len (fouts ) == 1 :
488- emit (* fouts , ":" , * fins , "\x01 " , into = lines )
489- else :
490- emit ("ifeq ($(MAKE4.3),yes)" , into = lines )
491- emit (* fouts , "&:" , * fins , "\x01 " , into = lines )
492- emit ("else" , into = lines )
493- emit (* (fouts [1 :]), ":" , fouts [0 ], into = lines )
494- emit (fouts [0 ], ":" , * fins , "\x01 " , into = lines )
495- emit ("endif" , into = lines )
491+ emit (name , ":" , hashfile , * fouts , into = lines )
492+ emit ("ifeq ($(MAKE4.3),yes)" , into = lines )
493+ emit (hashfile , * fouts , "&:" , * fins , into = lines )
494+ emit ("else" , into = lines )
495+ emit (* fouts , ":" , hashfile , into = lines )
496+ emit (hashfile , ":" , * fins , into = lines )
497+ emit ("endif" , into = lines )
496498
497499 if label :
498- emit ("\t $(hide)" , "$(ECHO) $(PROGRESSINFO)" , label , into = lines )
500+ emit ("\t $(hide)" , "$(ECHO) $(PROGRESSINFO)" + label , into = lines )
499501
500502 sandbox = join (self .dir , "sandbox" )
501503 emit ("\t $(hide)" , f"rm -rf { sandbox } " , into = lines )
@@ -517,16 +519,10 @@ def emit_rule(self, ins, outs, cmds=[], label=None):
517519 assert len (cmds ) == 0 , "rules with no outputs cannot have commands"
518520 emit (name , ":" , * fins , into = lines )
519521
520- cmd = "" .join (lines )
521- hash = hashlib .sha1 (bytes (cmd , "utf-8" )).hexdigest ()
522-
523- outputFp .write (cmd .replace ("\x01 " , f"$(OBJ)/.hashes/{ hash } " ))
522+ outputFp .write ("" .join (lines ))
524523
525524 if outs :
526- emit (f"$(OBJ)/.hashes/{ hash } :" )
527- emit (
528- f"\t $(hide) mkdir -p $(OBJ)/.hashes && touch $(OBJ)/.hashes/{ hash } "
529- )
525+ emit (f"\t $(hide) touch { hashfile } " )
530526 emit ("" )
531527
532528
0 commit comments