derobert

Config Manager: Makefile

Nov 2nd, 2018
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 1.36 KB | None | 0 0
  1. HOSTNAME   := $(shell hostname)
  2. BUILD      := $(patsubst %.d,build/%,$(wildcard *.d))
  3. BUILD_DEST := $(patsubst %.d,%,$(wildcard *.d))
  4. ASIS       := $(filter-out Makefile build tools %.d,$(wildcard *))
  5. INSTALL    := $(addprefix ~/.,$(subst \#,/,$(BUILD_DEST) $(ASIS)))
  6.  
  7. FORCE      := a # available: y=yes, always; n=no, never; a=ask
  8.  
  9. COMBINE    := tools/combine-config
  10. ISL        := tools/install-symlink
  11.  
  12. all: $(BUILD)
  13.  
  14. clean:
  15.     @echo "You probably don't want to actually do a 'make clean' as the"
  16.     @echo "symlinks in your home directory can point to files in build/"
  17.     @echo
  18.     @echo "If you really want to, just rm -Rf build/"
  19.     @exit 1
  20.  
  21. install: $(INSTALL)
  22.  
  23. .DELETE_ON_ERROR:
  24. .SECONDARY:
  25. .PHONY: all clean install
  26.  
  27. ~/.%: %
  28.     $(ISL) $(FORCE) "$<" "$@"
  29. ~/.%: build/%
  30.     $(ISL) $(FORCE) "$<" "$@"
  31.  
  32. .SECONDEXPANSION:
  33.  
  34. # Note that patsubst does not seem to work in second expansion. Its
  35. # documented to, but doesn't, at least with Debian GNU make 3.81-8.3.
  36. build/%: %.d $(COMBINE) $$(wildcard $$(addsuffix .d,$$(subst build/,,$$<))/*)
  37.     @mkdir -p build
  38.     if [ -e "$@" ]; then chmod u+w "$@"; fi
  39.     $(COMBINE) "$(HOSTNAME)" $(wordlist 3,66535,$+) > "$@"
  40.     chmod u-w "$@"
  41.  
  42. ~/.%: build/$$(subst /,\#,$$(subst $(HOME)/.,,$$@))
  43.     mkdir -p $(dir $@)
  44.     $(ISL) $(FORCE) "$<" "$@"
  45.  
  46. ~/.%: $$(subst /,\#,$$(subst $(HOME)/.,,$$@))
  47.     mkdir -p $(dir $@)
  48.     $(ISL) $(FORCE) "$<" "$@"
Add Comment
Please, Sign In to add comment