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