Makefile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. default: help
  2. SRC := ../contracts
  3. DST := patched
  4. DIFF := diff
  5. SRCS := $(shell find $(SRC) -type f)
  6. DSTS := $(shell find $(DST) -type f)
  7. DIFFS := $(shell find $(DIFF) -type f)
  8. ###############################################################################
  9. # Apply all patches in the $DIFF folder to the $DST folder
  10. apply: $(DST) $(patsubst $(DIFF)/%.patch,$(DST)/%,$(subst _,/,$(DIFFS)))
  11. # Reset the $DST folder
  12. $(DST): FORCE
  13. @rm -rf $@
  14. @cp -r $(SRC) $@
  15. # Update a solidity file in the $DST directory using the corresponding patch
  16. $(DST)/%.sol: FORCE | $(DST)
  17. @echo Applying patch to $@
  18. @patch -p0 -d $(DST) < $(patsubst $(DST)_%,$(DIFF)/%.patch,$(subst /,_,$@))
  19. ###############################################################################
  20. # Record all difference between $SRC and $DST in patches
  21. record: $(DIFF) $(patsubst %,$(DIFF)/%.patch,$(subst /,_,$(subst $(SRC)/,,$(SRCS)) $(subst $(DST)/,,$(DSTS))))
  22. # Create the $DIFF folder
  23. $(DIFF): FORCE
  24. @rm -rf $@
  25. @mkdir $@
  26. # Create the patch file by comparing the source and the destination
  27. $(DIFF)/%.patch: FORCE | $(DIFF)
  28. @echo Generating patch $@
  29. @diff -ruN \
  30. $(patsubst $(DIFF)/%.patch,$(SRC)/%,$(subst _,/,$@)) \
  31. $(patsubst $(DIFF)/%.patch,$(DST)/%,$(subst _,/,$@)) \
  32. | sed 's+$(SRC)/++g' \
  33. | sed 's+$(DST)/++g' \
  34. > $@
  35. @[ -s $@ ] || rm $@
  36. ###############################################################################
  37. help:
  38. @echo "usage:"
  39. @echo " make apply: create $(DST) directory by applying the patches to $(SRC)"
  40. @echo " make record: record the patches capturing the differences between $(SRC) and $(DST)"
  41. @echo " make clean: remove all generated files (those ignored by git)"
  42. clean:
  43. git clean -fdX
  44. FORCE: ;