Refactor makefile

For better cross platform compatibility (rely on Emacs; nofewer bash
commands) and correctness (keep tasks synchronous, even when make is
called with -j|--jobs)
This commit is contained in:
Henrik Lissner 2018-03-12 13:26:34 -04:00
parent 88d3e91ee4
commit 3e0e5bcad8
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,11 +1,11 @@
# Ensure emacs always runs from this makefile's PWD # Ensure emacs always runs from this makefile's PWD
EMACS_FLAGS=--eval '(setq user-emacs-directory default-directory)' -l init.el EMACS = emacs -q --eval "(setq user-emacs-directory default-directory)"
EMACS=emacs --quick --batch $(EMACS_FLAGS) DOOM = $(EMACS) --batch -l init.el
EMACSI=emacs -q $(EMACS_FLAGS) DOOMI = $(subst --batch,,$(DOOM))
MODULES=$(patsubst modules/%/, %, $(sort $(dir $(wildcard modules/*/ modules/*/*/)))) MODULES = $(patsubst modules/%/, %, $(sort $(dir $(wildcard modules/*/ modules/*/*/))))
all: autoloads autoremove install all: | autoloads autoremove install
## Shortcuts ## Shortcuts
a: autoloads a: autoloads
@ -15,19 +15,20 @@ r: autoremove
c: compile c: compile
cc: compile-core cc: compile-core
ce: compile-elpa ce: compile-elpa
d: doctor
## Package management ## Package management
install: init.el .local/autoloads.el install: | init.el .local/autoloads.el
@$(EMACS) -f doom//packages-install @$(DOOM) -f doom//packages-install
update: init.el .local/autoloads.el update: | init.el .local/autoloads.el
@$(EMACS) -f doom//packages-update @$(DOOM) -f doom//packages-update
autoremove: init.el .local/autoloads.el autoremove: | init.el .local/autoloads.el
@$(EMACS) -f doom//packages-autoremove @$(DOOM) -f doom//packages-autoremove
autoloads: init.el autoloads: | init.el
@$(EMACS) -f doom//reload-autoloads @$(DOOM) -f doom//reload-autoloads
## Byte compilation ## Byte compilation
@ -35,23 +36,23 @@ autoloads: init.el
# compile-core # compile-core
# compile-module # compile-module
# compile-module/submodule # compile-module/submodule
compile: init.el clean compile: | init.el clean
@$(EMACS) -f doom//byte-compile @$(DOOM) -f doom//byte-compile
compile-core: init.el clean compile-core: | init.el clean
@$(EMACS) -f doom//byte-compile-core @$(DOOM) -f doom//byte-compile-core
compile-elpa: init.el compile-elpa: | init.el
@$(EMACS) -f doom//byte-recompile-plugins @$(DOOM) -f doom//byte-recompile-plugins
$(patsubst %, compile-%, $(MODULES)): init.el .local/autoloads.el $(patsubst %, compile-%, $(MODULES)): | init.el .local/autoloads.el
@$(EMACS) -f doom//byte-compile -- $(patsubst compile-%, %, $@) @$(DOOM) -f doom//byte-compile -- $(patsubst compile-%, %, $@)
recompile: init.el recompile: | init.el
@$(EMACS) -f doom//byte-compile -- -r @$(DOOM) -f doom//byte-compile -- -r
clean: clean:
@$(EMACS) -f doom//clean-byte-compiled-files @$(DOOM) -f doom//clean-byte-compiled-files
## Unit tests ## Unit tests
@ -59,35 +60,35 @@ clean:
# test-core # test-core
# test-module # test-module
# test-module/submodule # test-module/submodule
test: init.el .local/autoloads.el test: | init.el .local/autoloads.el
@$(EMACS) -f doom//run-tests @$(DOOM) -f doom//run-tests
test-core $(patsubst %, test-%, $(MODULES)): init.el .local/autoloads.el test-core $(patsubst %, test-%, $(MODULES)): | init.el .local/autoloads.el
@$(EMACS) -f doom//run-tests -- $(subst test-, , $@) @$(DOOM) -f doom//run-tests -- $(subst test-, , $@)
# run tests interactively # run tests interactively
testi: init.el .local/autoloads.el testi: | init.el .local/autoloads.el
@$(EMACSI) -f doom//run-tests @$(DOOMI) -f doom//run-tests
## Utility tasks ## Utility tasks
# Runs Emacs from a different folder than ~/.emacs.d; only use this for testing! # Runs Emacs from a different folder than ~/.emacs.d; only use this for testing!
run: run:
@$(EMACSI) --eval "(run-hooks 'after-init-hook 'emacs-startup-hook 'window-setup-hook)" @$(DOOMI) --eval "(run-hooks 'after-init-hook 'emacs-startup-hook 'window-setup-hook)"
# Diagnoses potential OS/environment issues # Diagnoses potential OS/environment issues
doctor: doctor:
@bin/doom-doctor @$(EMACS) --script bin/doom-doctor
# Prints debug info about your current setup # Prints debug info about your current setup
info: info:
@$(EMACS) -l core/autoload/debug.el -f doom/info @$(EMACS) --batch -l core/autoload/debug.el -f doom/info
## Internal tasks ## Internal tasks
init.el: init.el:
@$(error No init.el file; create one or copy init.example.el) @$(error No init.el file; create one or copy init.example.el)
.local/autoloads.el: .local/autoloads.el:
@$(EMACS) -f doom-initialize-autoloads @$(DOOM) -f doom-initialize-autoloads
.PHONY: all compile test testi clean .PHONY: all compile test testi clean