Skip to content

Commit ce7a954

Browse files
committed
Re-write build scripts
- pre-requisites of a target do not define the order in which they are executed -> specify order by making them a part of recipe instead of a pre-requisite - use .PHONY for targets which are not file names - use a common makefile to be used by all the subdirectories - pass the note name as a parameter to `make`
1 parent c5dff4c commit ce7a954

File tree

7 files changed

+63
-54
lines changed

7 files changed

+63
-54
lines changed

Makefile

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,64 @@ DIRS=$(sort $(DIRS_UNSORTED))
77
## print sorted DIRS
88
#$(info $$(DIRS) is [${DIRS}])
99

10-
include vars.mk
10+
include constants.mk
1111

1212
LOWDOWN_PATH=./lowdown
1313
CSS_PATH=style.css
1414
OBJS= build.sh README.md style.css style.css.map index.html
1515

16-
build: clean script README index.html fix_index.html
16+
MAKE=make --no-print-directory
17+
18+
.PHONY: build
19+
build:
20+
@$(MAKE) clean
21+
@$(MAKE) script_wrapper
22+
@$(MAKE) README
23+
@$(MAKE) index.html
24+
@$(MAKE) fix_index.html
1725
@echo -e "$(COLOR_GREEN)DONE$(COLOR_NONE)"
1826

27+
.PHONY: clean
1928
clean:
2029
@echo -e "$(COLOR_YELLOW)Deleting$(COLOR_NONE) pre-existing (if any) files $(COLOR_BLUE)$(OBJS)$(COLOR_NONE)"
2130
@rm -f $(OBJS)
2231

32+
## create dir-specific temporary makefiles
33+
.PHONY: gen_temp_mk
34+
gen_temp_mk:
35+
@for dirname in $(DIRS); do \
36+
echo "# AUTOGENERATED!! DO NOT EDIT" > $${dirname}/$${dirname}.mk; \
37+
echo "include ../constants.mk" >> $${dirname}/$${dirname}.mk; \
38+
echo "include ../common.mk" >> $${dirname}/$${dirname}.mk; \
39+
done
40+
41+
## remove dir-specific temporary makefiles
42+
.PHONY: clean_temp_mk
43+
clean_temp_mk:
44+
@for dirname in $(DIRS); do \
45+
rm -f $${dirname}/$${dirname}.mk; \
46+
done
47+
48+
## create main build shell script which calls all the dir-specific temporary makefiles
49+
.PHONY: script
2350
script:
2451
@echo -e "$(COLOR_YELLOW)Generating$(COLOR_NONE) script file $(COLOR_BLUE)build.sh$(COLOR_NONE)"
2552
@echo "# AUTOGENERATED!! DO NOT EDIT" > build.sh
53+
2654
@for dirname in $(DIRS); do \
27-
echo "make -C $${dirname} -f $${dirname}.mk --no-print-directory" >> build.sh ; \
55+
echo "make NOTE_NAME=$${dirname}_notes -C $${dirname} -f $${dirname}.mk --no-print-directory" >> build.sh ; \
2856
done
57+
2958
@chmod +x build.sh
3059
@./build.sh
3160

61+
.PHONY: script_wrapper
62+
script_wrapper:
63+
@$(MAKE) clean_temp_mk
64+
@$(MAKE) gen_temp_mk
65+
@$(MAKE) script
66+
67+
.PHONY: README
3268
README:
3369
@echo -e "$(COLOR_YELLOW)Generating$(COLOR_NONE) README file $(COLOR_BLUE)README.md$(COLOR_NONE)"
3470
@echo '# devpogi notes' > README.md
@@ -51,6 +87,7 @@ index.html: README.md style.css
5187
@rm -f $@.temp
5288
@echo -e "generated $(COLOR_BLUE)index.html$(COLOR_NONE)"
5389

90+
.PHONY: fix_index.html
5491
fix_index.html:
5592
@sed -i 's/.md/.html/g' index.html
5693

brave_browser/brave_browser.mk

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
NOTE_NAME=brave_browser_notes
2-
3-
include ../vars.mk
4-
5-
build: clean html
6-
7-
clean:
8-
@rm -f $(NOTE_NAME).html
9-
10-
html: $(NOTE_NAME).md
11-
@$(LOWDOWN_PATH) -s $< -o $(NOTE_NAME).$@ -thtml \
12-
-M author="$(AUTHOR)" \
13-
-M title="$(TITLE)" \
14-
-M css="$(CSS_PATH)"
15-
@echo -e "generated $(COLOR_BLUE)$(NOTE_NAME).html$(COLOR_NONE)"
1+
# AUTOGENERATED!! DO NOT EDIT
2+
include ../constants.mk
3+
include ../common.mk

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# AUTOGENERATED!! DO NOT EDIT
2-
make -C brave_browser -f brave_browser.mk --no-print-directory
3-
make -C linux -f linux.mk --no-print-directory
4-
make -C rpi -f rpi.mk --no-print-directory
2+
make NOTE_NAME=brave_browser_notes -C brave_browser -f brave_browser.mk --no-print-directory
3+
make NOTE_NAME=linux_notes -C linux -f linux.mk --no-print-directory
4+
make NOTE_NAME=rpi_notes -C rpi -f rpi.mk --no-print-directory

common.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LOWDOWN_PATH=../lowdown
2+
CSS_PATH=../style.css
3+
4+
.PHONY: html
5+
html: $(NOTE_NAME).md
6+
@rm -f $(NOTE_NAME).html
7+
@$(LOWDOWN_PATH) -s $< -o $(NOTE_NAME).$@ -thtml \
8+
-M author="$(AUTHOR)" \
9+
-M title="$(TITLE)" \
10+
-M css="$(CSS_PATH)"
11+
@echo -e "generated $(COLOR_BLUE)$(NOTE_NAME).html$(COLOR_NONE)"

vars.mk renamed to constants.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ COLOR_BLUE=\033[1;34m
66
COLOR_GREEN=\033[1;32m
77
COLOR_YELLOW=\033[1;33m
88
COLOR_NONE=\033[0m
9-
10-
LOWDOWN_PATH=../lowdown
11-
CSS_PATH=../style.css

linux/linux.mk

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
NOTE_NAME=linux_notes
2-
3-
include ../vars.mk
4-
5-
build: clean html
6-
7-
clean:
8-
@rm -f $(NOTE_NAME).html
9-
10-
html: $(NOTE_NAME).md
11-
@$(LOWDOWN_PATH) -s $< -o $(NOTE_NAME).$@ -thtml \
12-
-M author="$(AUTHOR)" \
13-
-M title="$(TITLE)" \
14-
-M css="$(CSS_PATH)"
15-
@echo -e "generated $(COLOR_BLUE)$(NOTE_NAME).html$(COLOR_NONE)"
1+
# AUTOGENERATED!! DO NOT EDIT
2+
include ../constants.mk
3+
include ../common.mk

rpi/rpi.mk

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
NOTE_NAME=rpi_notes
2-
3-
include ../vars.mk
4-
5-
build: clean html
6-
7-
clean:
8-
@rm -f $(NOTE_NAME).html
9-
10-
html: $(NOTE_NAME).md
11-
@$(LOWDOWN_PATH) -s $< -o $(NOTE_NAME).$@ -thtml \
12-
-M author="$(AUTHOR)" \
13-
-M title="$(TITLE)" \
14-
-M css="$(CSS_PATH)"
15-
@echo -e "generated $(COLOR_BLUE)$(NOTE_NAME).html$(COLOR_NONE)"
1+
# AUTOGENERATED!! DO NOT EDIT
2+
include ../constants.mk
3+
include ../common.mk

0 commit comments

Comments
 (0)