comparison Makefile @ 455:0567af952cfa prerelease

merge
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 19 Jun 2016 23:31:25 +0100
parents 5e79364c9b1d 4cccb13bf406
children 84841654c606
comparison
equal deleted inserted replaced
451:7f9032f43f41 455:0567af952cfa
302 ideconnect: ## Brings in the foreground the IDE that currently is running in a screen (if any), can detach with ctrl-a ctrl-d. 302 ideconnect: ## Brings in the foreground the IDE that currently is running in a screen (if any), can detach with ctrl-a ctrl-d.
303 @screen -r -S $(BELA_IDE_SCREEN_NAME) 303 @screen -r -S $(BELA_IDE_SCREEN_NAME)
304 304
305 BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 305 BELA_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
306 UPDATES_DIR?=/root/Bela/updates 306 UPDATES_DIR?=/root/Bela/updates
307 UPDATE_SOURCE_DIR?=/tmp/belaUpdate 307 UPDATE_SOURCE_DIR_BASE?=/tmp/belaUpdate
308 UPDATE_SOURCE_DIR=$(UPDATE_SOURCE_DIR_BASE)/Bela
308 UPDATE_REQUIRED_PATHS?=scripts include core scripts/update_board 309 UPDATE_REQUIRED_PATHS?=scripts include core scripts/update_board
309 UPDATE_BELA_TEMP?=/tmp/belaTemp 310 UPDATE_BELA_PATCH?=/tmp/belaPatch
310 UPDATE_BELA_BACKUP?=/tmp/belaBak 311 UPDATE_BELA_BACKUP?=/tmp/belaBak
311 UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak 312 UPDATE_BELA_MV_BACKUP?=/tmp/belaMvBak
312 313
313 updateclean: ## Cleans the $(UPDATES_DIR) folder 314 updateclean: ## Cleans the $(UPDATES_DIR) folder
314 @[ -n $(UPDATE_DIR) ] && rm -rf $(UPDATE_DIR) && mkdir -p $(UPDATE_DIR) 315 @[ -n $(UPDATE_DIR) ] && rm -rf $(UPDATE_DIR) && mkdir -p $(UPDATE_DIR)
316 checkupdate: ## Unzips the zip file in $(UPDATES_DIR) and checks that it contains a valid 317 checkupdate: ## Unzips the zip file in $(UPDATES_DIR) and checks that it contains a valid
317 # Check that exactly one zip file exists 318 # Check that exactly one zip file exists
318 @cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"` 319 @cd $(UPDATES_DIR) && COUNT=`ls -l *.zip | wc -l` && [ $$COUNT -eq 1 ] && rm -rf `ls | grep -v "\.zip$$"`
319 @#TODO: heuristics on available space. Use unzip -l and df 320 @#TODO: heuristics on available space. Use unzip -l and df
320 @echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'` 321 @echo uncompressed size: `unzip -l \`ls $(UPDATES_DIR)/*.zip\` | tail -n1 | awk '{print $$1}'`
321 # Delete and re-create the temp directory (first, make sure it is not empty!!) 322 # Delete and re-create the temp directory (first, make sure it is not an empty string!)
322 @[ -n $(UPDATE_SOURCE_DIR) ] && rm -rf $(UPDATE_SOURCE_DIR) && mkdir -p $(UPDATE_SOURCE_DIR) 323 @[ -n $(UPDATE_SOURCE_DIR_BASE) ] && rm -rf $(UPDATE_SOURCE_DIR_BASE) && mkdir -p $(UPDATE_SOURCE_DIR_BASE)
323 # Unzip the contents to the temp folder 324 # Unzip the contents to the temp folder
324 @cd $(UPDATE_SOURCE_DIR) && unzip -qq $(UPDATES_DIR)/*zip 325 @cd $(UPDATE_SOURCE_DIR_BASE) && unzip -qq $(UPDATES_DIR)/*zip
325 # Strip the top-level folder ( if there is only one ) 326 # Strip the top-level folder ( if there is only one )
326 @DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\ 327 #@DIR=`ls -d $(UPDATE_SOURCE_DIR)` && COUNT=`echo $$DIR | wc -l` &&\
327 [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR) 328 [ $$COUNT -eq 1 ] && mv $(UPDATE_SOURCE_DIR)/* /tmp/supertemp && rm -rf $(UPDATE_SOURCE_DIR) && mv /tmp/supertemp $(UPDATE_SOURCE_DIR)
328 # Now actually check if some key-files and folders are there 329 # Now actually check if some key-files and folders are there
329 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ 330 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\
330 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } 331 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; }
332 # Success. You can continue the install with "make update"
331 UPDATE_LOG?=~/update.log 333 UPDATE_LOG?=~/update.log
332 LOG=>> $(UPDATE_LOG) 2>&1 334 LOG=>> $(UPDATE_LOG) 2>&1
333 update: ## Installs the update from $(UPDATES_DIR) 335 update: ## Installs the update from $(UPDATES_DIR)
334 update: stop 336 update: stop
335 # Truncate the log file 337 # Truncate the log file
336 @echo > $(UPDATE_LOG) 338 @echo > $(UPDATE_LOG)
337 # Re-perform the check, just in case ... 339 # Re-perform the check, just in case ...
338 # Now actually check if some key-files and folders are there 340 # Now actually check if some key-files and folders are there
339 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\ 341 @cd $(UPDATE_SOURCE_DIR) && FAIL=0 && for path in $(UPDATE_REQUIRED_PATHS); do `ls $$path >/dev/null 2>&1` || { FAIL=1; break; }; done;\
340 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; } 342 [ $$FAIL -eq 0 ] || { echo "$$path was not found in the zip archive. Maybe it is corrupted?"; exit 1; }
341 # Duplicate the Bela folder $(BELA_DIR) to $(UPDATE_BELA_TEMP) 343 # Duplicate the Bela folder $(BELA_DIR) to $(UPDATE_BELA_PATCH) ...
342 @[ -n $(UPDATE_BELA_TEMP) ] && mkdir -p $(UPDATE_BELA_TEMP) 344 @[ -n $(UPDATE_BELA_PATCH) ] && mkdir -p $(UPDATE_BELA_PATCH)
343 @#TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target 345 @#TODO: this would allow to trim trailing slashes in case we want to be safer: a="`pwd`/" ; target=${a%/} ; echo $target
344 @rsync -a --delete-before $(BELA_DIR)/ $(UPDATE_BELA_TEMP) 346 @rsync -a --delete-before $(BELA_DIR)/ $(UPDATE_BELA_PATCH)
345 # Also back it up in $(UPDATE_BELA_BACKUP). 347 # Also backing it up in $(UPDATE_BELA_BACKUP)...
346 @[ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP) 348 @[ -n $(UPDATE_BELA_BACKUP) ] && mkdir -p $(UPDATE_BELA_BACKUP)
347 @rsync -a $(BELA_DIR)/ $(UPDATE_BELA_BACKUP) 349 @rsync -a $(BELA_DIR)/ $(UPDATE_BELA_BACKUP)
348 @#TODO: add command line switch for update_board which avoids useless stuff (e.g.: setting the date, start/stop the IDE) 350 # Here's the trick: we run "update_board" ssh'ing into the BeagleBone itself!
349 @cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_TEMP) ./update_board -y 351 @cd $(UPDATE_SOURCE_DIR)/scripts && BBB_ADDRESS=root@127.0.0.1 BBB_BELA_HOME=$(UPDATE_BELA_PATCH) ./update_board -y --no-frills
350 # If everything went ok, we now have the updated version of $(BELA_DIR) in $(UPDATE_BELA_TEMP) and a backup of $(BELA_DIR) in $(UPDATE_BELA_BACKUP) 352 # If everything went ok, we now have the updated version of $(BELA_DIR) in $(UPDATE_BELA_PATCH) and a backup of $(BELA_DIR) in $(UPDATE_BELA_BACKUP)
351 # So let's operate the magic swap. $(BELA_DIR) is moved to $(UPDATE_BELA_MV_BACKUP) and $(UPDATE_BELA_TEMP) is moved to $(BELA_DIR). 353 # So let's operate the magic swap. $(BELA_DIR) is moved to $(UPDATE_BELA_MV_BACKUP) and $(UPDATE_BELA_PATCH) is moved to $(BELA_DIR).
352 # If something goes wrong at thie stage, you can always find your old $(BELA_DIR) folder at $(UPDATE_BELA_BACKUP) 354 # If something goes wrong at thie stage, you can always find your old $(BELA_DIR) folder at $(UPDATE_BELA_BACKUP)
353 # The fun part is that this Makefile is moved as well... 355 # The fun part is that this Makefile is moved as well...
354 # We are about to kill the IDE, so just in case you are running this from within the IDE, we run the remainder of this update in a screen. 356 # We are about to kill the IDE, so just in case you are running this from within the IDE, we run the remainder of this update in a screen.
355 # Output will be logged to $(UPDATE_LOG) 357 # Output will be logged to $(UPDATE_LOG)
356 @screen -S update-Bela -d -m bash -c '\ 358 @screen -S update-Bela -d -m bash -c '\
357 echo so let us just make a backup of the Makefile we are working on TODO: remove this one $(LOG);\
358 cp $(BELA_DIR)/Makefile /tmp/ $(LOG) &&\
359 [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\ 359 [ -n $(UPDATE_BELA_MV_BACKUP) ] $(LOG) && rm -rf $(UPDATE_BELA_MV_BACKUP) $(LOG) &&\
360 echo Kill the IDE $(LOG) && \ 360 echo Kill the IDE $(LOG) && \
361 $(MAKE) --no-print-directory idestop $(LOG) &&\ 361 $(MAKE) --no-print-directory idestop $(LOG) &&\
362 mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_TEMP) $(BELA_DIR) $(LOG) &&\ 362 mv $(BELA_DIR) $(UPDATE_BELA_MV_BACKUP) $(LOG) && mv $(UPDATE_BELA_PATCH) $(BELA_DIR) $(LOG) &&\
363 echo Hope we are still alive here $(LOG) &&\ 363 echo Hope we are still alive here $(LOG) &&\
364 echo Restart the IDE $(LOG) &&\ 364 echo Restart the IDE $(LOG) &&\
365 make --no-print-directory -C $(BELA_DIR) idestart $(LOG) &&\ 365 make --no-print-directory -C $(BELA_DIR) idestart $(LOG) &&\
366 echo Update succesful $(LOG); \ 366 echo Update succesful $(LOG); \
367 ' $(LOG) 367 ' $(LOG)