#!/bin/bash

# based on CocoaLumberJack wiki

# Get user name of current user
full1="`whoami`"
#echo $full1

# Convert to lower case
full2=$(echo $full1 | awk '{print tolower($0)}')
#echo $full2

# Replace spaces with underscores
full3=$(echo ${full2// /_})
#echo $full3

# Remove any characters that are illegal in a macro name
full4=$(echo $full3 | sed 's/[^0-9a-zA-Z_]*//g')
#echo $full4

# If we output directly to our intended file, even when nothing has changed,
# then we'll essentially be doing a touch on the file.
# The compiler will see this, and recompile any files that include the header.
# This may mean recompiling every single source file, every single time we do a build!
# So instead we're going to output to a temporary file, and use diff to detect changes.

header_path=`find "${SRCROOT}" \( -name "KZBootstrapUserMacros.h" \)`
temp_filepath="/tmp/PerUserMacros.temp.h"

echo "// This file is automatically generated" > ${temp_filepath}
echo "#define $full4 1" >> ${temp_filepath}

if [ -a ${header_path} ]
    then
    DIFF=$(diff ${temp_filepath} ${header_path})
    if [ "$DIFF" != "" ] 
    then
        cp -f ${temp_filepath} ${header_path}
    fi
else
    cp -f ${temp_filepath} ${header_path}
fi
#!/bin/bash

# based on CocoaLumberJack wiki

# Get user name of current user
full1="`whoami`"
#echo $full1

# Convert to lower case
full2=$(echo $full1 | awk '{print tolower($0)}')
#echo $full2

# Replace spaces with underscores
full3=$(echo ${full2// /_})
#echo $full3

# Remove any characters that are illegal in a macro name
full4=$(echo $full3 | sed 's/[^0-9a-zA-Z_]*//g')
#echo $full4

# If we output directly to our intended file, even when nothing has changed,
# then we'll essentially be doing a touch on the file.
# The compiler will see this, and recompile any files that include the header.
# This may mean recompiling every single source file, every single time we do a build!
# So instead we're going to output to a temporary file, and use diff to detect changes.

header_path=`find "${SRCROOT}" \( -name "KZBootstrapUserMacros.h" \)`
temp_filepath="/tmp/PerUserMacros.temp.h"

echo "// This file is automatically generated" > ${temp_filepath}
echo "#define $full4 1" >> ${temp_filepath}

if [ -a "${header_path}" ]
    then
    DIFF=$(diff ${temp_filepath} ${header_path})
    if [ "$DIFF" != "" ] 
    then
        cp -f ${temp_filepath} ${header_path}
    fi
else
    cp -f ${temp_filepath} ${header_path}
fi

Fix for spaces in header path
Fix for spaces in header path

If header path has spaces in it, this script fails at line: 33.