Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / scripts / generator / whack_build.sh
1 #!/bin/bash
2
3 #hmmm: nice to set an interrupt handler for ctrl-c, to catch a break and send it to the cleanup of the crudfile.
4
5 # catch whether they want rigorous cleaning or not.
6 clean_src="$1"; shift
7
8 function whack_single_build_area()
9 {
10   local CLEANING_LOCALE="$1"; shift
11   if [ ! -d "$CLEANING_LOCALE" ]; then
12 #    echo "the folder $CLEANING_LOCALE does not exist.  not cleaning."
13     return 0
14   fi
15
16   local choprepo="$(basename "$(dirname "$CLEANING_LOCALE")" )/$(basename "$CLEANING_LOCALE")"
17   echo $(date): "cleaning up [$choprepo]..."
18   if [ -z "$CLEANING_LOCALE" ]; then
19     echo "The CLEANING_LOCALE variable is not set!"
20     exit 3
21   fi
22
23   export CRUDFILE="$(mktemp "$TMP/zz_whack_build.XXXXXX")"
24   echo "" &>"$CRUDFILE"
25
26 #  echo $(date): "  cleaning up the build products..."
27
28   # avoid accidentally removing important stuff if our variables have not been previously
29   # established.
30   if [ -z "$FEISTY_MEOW_GENERATED_STORE" -o -z "$TEMPORARIES_PILE" ]; then
31     echo The build whacking script cannot run because either the FEISTY_MEOW_GENERATED_STORE
32     echo variable or the TEMPORARIES_PILE variable have not been set.  This makes
33     echo it unsafe to remove anything in the build products.
34     exit 1
35   fi
36
37   # kerzap.  the cleanups in production directory remove older locations of generated files.
38   rm -rf \
39     "$FEISTY_MEOW_APEX/generatedJUnitFiles" \
40     "$FEISTY_MEOW_GENERATED_STORE/clam_tmp" \
41     "$FEISTY_MEOW_GENERATED_STORE/logs" \
42     "$PRODUCTION_STORE/__build_"*.h \
43     "$PRODUCTION_STORE/manifest.txt" \
44     "$RUNTIME_PATH/binaries" \
45     "$RUNTIME_PATH/install" \
46     "$RUNTIME_PATH/waste" \
47     "$TEMPORARIES_PILE" \
48     "$PRODUCTION_STORE/clam_bin" \
49     "$PRODUCTION_STORE/binaries" \
50     "$PRODUCTION_STORE/install" \
51     "$PRODUCTION_STORE/logs" \
52     "$PRODUCTION_STORE/waste" 
53 # last few mentioning production dir are to clean older code.
54
55 #  echo $(date): "  cleaning generated files in source hierarchy..."
56
57   if [ "$clean_src" == "clean" -o "$clean_src" == "CLEAN"  ]; then
58     echo $(date): "    ** aggressive cleaning activated..."
59
60     # get rid of the build binaries.
61     rm -rf "$CLAM_BINARIES"
62
63     perl "$FEISTY_MEOW_SCRIPTS/files/zapdirs.pl" "$FEISTY_MEOW_APEX" >>"$CRUDFILE"
64   fi
65
66   echo $(date): "cleaned [$choprepo]."
67   rm -rf "$CRUDFILE"
68   return 0
69 }
70
71 ##############
72
73 # clean all known hierarchies of build products...
74
75 whack_single_build_area "$FEISTY_MEOW_APEX"
76