Skip to content

Commit e73479b

Browse files
committed
Allow build directory to be overriden with CH_BUILD
1 parent f5f2573 commit e73479b

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

Bashrc

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ if [ ! -f $CH_HOME/make/cpphash.mk ]; then
1717
return 1
1818
fi
1919

20+
if [[ "$CH_BUILD" == "" ]]; then
21+
CH_BUILD="build"
22+
fi
23+
2024
if [[ "$ESPMAKE_PREFIX" == "" ]]; then
2125
ESPMAKE_PREFIX="esp_"
2226
fi
@@ -76,12 +80,11 @@ if [[ "$_ESPMAKE_DEV1" == "" ]]; then
7680
_ESPMAKE_DEV1=/dev/ttyACM1
7781
fi
7882

79-
8083
# Helper function that returns the path to the build directory
8184
# of the last project built. Example: $ESPMAKE_PRJ_HOME/build/espinit
8285

8386
_ESPMAKE_LAST_BUILD() {
84-
echo "${ESPMAKE_PRJ_HOME}/build/$(basename $(dirname $(cat $ESPMAKE_PRJ_LAST)))_$(basename $(cat $ESPMAKE_PRJ_LAST) .mk)"
87+
echo "${ESPMAKE_PRJ_HOME}/$(CH_BUILD)/$(basename $(dirname $(cat $ESPMAKE_PRJ_LAST)))_$(basename $(cat $ESPMAKE_PRJ_LAST) .mk)"
8588
}
8689

8790
# Helper function that returns the name of the esphome device as
@@ -100,12 +103,12 @@ alias _ESPMAKE_USB='function _ESPMAKE_USB { _VERB=${1}; _DEV=${2}; cd $(_ESPMAKE
100103
# Helper alias to upload last project using OTA update to IP _ESPMAKE_IP<arg>
101104
# Note the indirect variable reference ${!_IP} to choose the _IP
102105

103-
alias _ESPMAKE_UPLOAD='function _ESPMAKE_UPLOAD { _IPNUM=${1}; _IP=_ESPMAKE_IP${_IPNUM}; esphome -v upload --device ${!_IP} --file $(_ESPMAKE_LAST_BUILD)/.esphome/build/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME)/firmware.bin $(_ESPMAKE_LAST_BUILD)/espmake.yaml;}; _ESPMAKE_UPLOAD'
106+
alias _ESPMAKE_UPLOAD='function _ESPMAKE_UPLOAD { _IPNUM=${1}; _IP=_ESPMAKE_IP${_IPNUM}; esphome -v upload --device ${!_IP} --file $(_ESPMAKE_LAST_BUILD)/.esphome/$(CH_BUILD)/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME)/firmware.bin $(_ESPMAKE_LAST_BUILD)/espmake.yaml;}; _ESPMAKE_UPLOAD'
104107

105108
# _ESPMAKE_IDF_JTAG uses esp-idf directly to burn firmware to /dev/ttyACM0
106109

107110
export ESPTOOL_TESTING=1 # as per esptool/esp32s2.py
108-
alias _ESPMAKE_IDF_JTAG='(cd $(_ESPMAKE_LAST_BUILD)/.esphome/build/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME) && esptool.py --before default_reset --after no_reset --baud 1500000 --port $_ESPMAKE_DEV0 --chip esp32s2 write_flash -z --flash_size detect 0x10000 firmware.bin 0x1000 bootloader.bin 0x8000 partitions.bin 0x9000 ota_data_initial.bin)'
111+
alias _ESPMAKE_IDF_JTAG='(cd $(_ESPMAKE_LAST_BUILD)/.esphome/$(CH_BUILD)/$(_ESPMAKE_LAST_ESPNAME)/.pioenvs/$(_ESPMAKE_LAST_ESPNAME) && esptool.py --before default_reset --after no_reset --baud 1500000 --port $_ESPMAKE_DEV0 --chip esp32s2 write_flash -z --flash_size detect 0x10000 firmware.bin 0x1000 bootloader.bin 0x8000 partitions.bin 0x9000 ota_data_initial.bin)'
109112

110113
# Convenience aliases
111114

@@ -154,7 +157,7 @@ alias ${ESPMAKE_PREFIX}esphome='view $(_ESPMAKE_LAST_BUILD)/esphome.yaml'
154157
# Aliases to find strings including or excluding the build directory
155158

156159
alias ${ESPMAKE_PREFIX}search="find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' -type f -print0 | xargs -0 grep -i"
157-
alias ${ESPMAKE_PREFIX}search_home="find $ESPMAKE_PRJ_HOME ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/build/*' ! -path '*/cpphash/*' -type f -print0 | xargs -0 grep -i"
160+
alias ${ESPMAKE_PREFIX}search_home="find $ESPMAKE_PRJ_HOME ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/$(CH_BUILD)/*' ! -path '*/cpphash/*' -type f -print0 | xargs -0 grep -i"
158161
alias ${ESPMAKE_PREFIX}search_all="find $ESPMAKE_PRJ_HOME ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' -type f -print0 | xargs -0 grep -i"
159162

160163
# Aliases to search for arg1 and replace it with arg2 in all files.
@@ -163,13 +166,13 @@ alias ${ESPMAKE_PREFIX}search_all="find $ESPMAKE_PRJ_HOME ! -name '*.swp' ! -nam
163166
# bash does not seem to allow these to be defined with ESPMAKE_PREFIX.
164167

165168
esp_replace_nohash() {
166-
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/build/*' ! -path '*/cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s#$1#$2#g"
169+
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/$(CH_BUILD)/*' ! -path '*/cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s#$1#$2#g"
167170
}
168171
esp_replace_nocomma() {
169-
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/build/*' ! -path '*/cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s,$1,$2,g"
172+
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/$(CH_BUILD)/*' ! -path '*/cpphash/*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s,$1,$2,g"
170173
}
171174
esp_replace_noslash() {
172-
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/build/*' ! -path '*/cpphash*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s/$1/$2/g"
175+
find . ! -name '*.swp' ! -name '*.bak' ! -path '*/.git/*' ! -path '*/$(CH_BUILD)/*' ! -path '*/cpphash*' ! -path '*/.esphome/*' -type f -print0 | xargs -0 grep -l "$1" | xargs $SED --in-place=.bak "s/$1/$2/g"
173176
}
174177
alias esp_replace="esp_replace_noslash"
175178

Makefile.cpphash

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ ifeq (,$(wildcard $(CH_HOME)/install.sh))
3737
$(info git clone https://github.com/maartenSXM/cpphash.git)
3838
$(info ./cpphash/install.sh -y)
3939
$(info source cpphash/Bashrc)
40-
$(error and try again)
40+
$(info and try again)
41+
$(error Or, alternatively, set a CH_HOME environment or make variable)
4142
endif
4243

4344
ifeq (,$(VIRTUAL_ENV))
@@ -55,8 +56,9 @@ MY_PRJ_DIR = $(patsubst %/,%,$(dir $(PRJ)))
5556
MY_PROJECT = $(basename $(notdir $(MY_PRJ_PATH)))
5657
MY_GEN_FILES ?= $(PRJ)
5758

58-
ifeq (,$(wildcard build/$(MY_PROJECT)))
59-
$(shell mkdir -p build/$(MY_PROJECT))
59+
CH_BUILD ?= build
60+
ifeq (,$(wildcard $(CH_BUILD)/$(MY_PROJECT)))
61+
$(shell mkdir -p $(CH_BUILD)/$(MY_PROJECT))
6062
endif
6163

6264
# CH_BUILD_DIR is where projects are built. If changed, review
@@ -65,7 +67,7 @@ endif
6567
# because realpath does not support the --relative-to option on many
6668
# non-Linux OSs.
6769

68-
CH_BUILD_DIR = ./build/$(MY_PROJECT)
70+
CH_BUILD_DIR = $(CH_BUILD)/$(MY_PROJECT)
6971

7072
include $(CH_HOME)/make/log.mk
7173

@@ -108,7 +110,7 @@ endif
108110
# Use this to list additional #include directories
109111

110112
# Allow #include from all source directories. Note these
111-
# directories come after -I build/<project>/dehashed so
113+
# directories come after -I $(CH_BUILD_DIR)/dehashed so
112114
# includes of yaml files are taken from there.
113115

114116
CH_EXTRA_INCS += $(foreach d,$(MY_DIRS),-I $(d))

Makefile.esphome

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ MY_PROJECT = $(basename $(notdir $(MY_PRJ_PATH)))
5656
# because realpath does not support the --relative-to option on many
5757
# non-Linux OSs.
5858

59-
CH_BUILD_DIR = build/$(MY_PROJECT)
59+
CH_BUILD ?= build
60+
CH_BUILD_DIR = $(CH_BUILD)/$(MY_PROJECT)
6061

6162
# include $(CH_HOME)/make/log.mk
6263

make/cpphash.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ifeq (,$(CH_HOME))
2323
CH_HOME := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
2424
endif
2525
ifeq (,$(CH_BUILD_DIR))
26-
CH_BUILD_DIR := build
26+
CH_BUILD_DIR := $(CH_BUILD)
2727
endif
2828
ifeq (,$(CH_TMP_SUBDIR))
2929
CH_TMP_SUBDIR := dehashed

0 commit comments

Comments
 (0)