#!/bin/sh # # Script to generate debug.h # Output goes to stdout, this should be redirected by the caller # Configuration DEBUG_LEVELS=4 DEBUG_PARTS="MAIN ARGPARSE SYSFS CPUFREQ LOG" DEBUG_HELPER_DEF=`grep -o "void .*()" debug.c | head -n 1` DEBUG_HELPER=${DEBUG_HELPER_DEF##* } HEXDUMP_HELPER_DEF=`grep -o "void .*(unsigned char \*data,int len)" debug.c` HEXDUMP_HELPER=${HEXDUMP_HELPER_DEF#* } HEXDUMP_HELPER=${HEXDUMP_HELPER%%(*} # Generate the configuration part cat << EOF #ifndef HAVE_DEBUG_H #define HAVE_DEBUG_H // Configuration EOF for PART in ALL $DEBUG_PARTS do VALUE=0 if [ -r "debug.h" ] then VALUE=`grep "^#define SET_DEBUG_$PART " debug.h | head -n 1 | awk '{ print $NF }' | tr -cd "[0-9]"` fi if [ -n "$VALUE" ] then echo "#define SET_DEBUG_$PART $VALUE" else echo "#define SET_DEBUG_$PART 0" fi done for SETTING in SET_DEBUG_PRINT_LEVEL SET_DEBUG_PRINT_TIME SET_DEBUG_PRINT_LINE SET_DEBUG_PRINT_FUNCTION do if [ -r "debug.h" ] then if grep -q "^#define $SETTING" debug.h then echo "#define $SETTING" else echo "//#define $SETTING" fi else echo "#define $SETTING" fi done echo "// End of configuration" echo "" # Configure prefix echo "// Set prefix" if [ -n "$DEBUG_PREFIX_CONDITION" ] then echo "$DEBUG_PREFIX_CONDITION" fi echo "#define SET_DEBUG_PRINT_PREFIX \"$DEBUG_PREFIX\"" if [ -n "$DEBUG_PREFIX_CONDITION" ] then echo "#endif" fi echo "" # Generate the part to make ALL work echo "// Make ALL work" for PART in $DEBUG_PARTS do echo "#if (SET_DEBUG_ALL>SET_DEBUG_$PART)" echo " #undef SET_DEBUG_$PART" echo " #define SET_DEBUG_$PART SET_DEBUG_ALL" echo "#endif" echo "" done # Check if we need stdio pr the helper echo "// Check if we need stdio.h or the helpers" for PART in $DEBUG_PARTS do echo "#if (SET_DEBUG_$PART>0)" echo " #ifndef NEED_STDIO_H" echo " #define NEED_STDIO_H" echo " #endif" echo " #ifdef SET_DEBUG_PRINT_TIME" # echo " #ifdef NEED_DEBUG_HELPER" # echo " #undef NEED_DEBUG_HELPER" # echo " #endif" echo " #ifndef NEED_DEBUG_HELPER" echo " #define NEED_DEBUG_HELPER" echo " #endif" echo " #endif" echo " #ifndef NEED_HEXDUMP_HELPER" echo " #define NEED_HEXDUMP_HELPER" echo " #endif" echo "#endif" echo "" done # Print the format definitions # Define printing of prefixes cat <$((COUNT-1)))" echo " #define DEBUG${COUNT}_$PART(...) DEBUG${COUNT}_FORMAT(__VA_ARGS__)" echo " #define HEXDUMP${COUNT}_$PART(data,datalen) $HEXDUMP_HELPER(data,datalen);" echo "#else" echo " #define DEBUG${COUNT}_$PART(...)" echo " #define HEXDUMP${COUNT}_$PART(data,datalen)" echo "#endif" echo "" done done # Include stdio when needed echo "#ifdef NEED_STDIO_H" echo " #include " echo "#endif" # Define helper function echo "#ifdef NEED_DEBUG_HELPER" echo " $DEBUG_HELPER_DEF;" echo "#endif" # Define hexdump function echo "#ifdef NEED_HEXDUMP_HELPER" echo " $HEXDUMP_HELPER_DEF;" echo "#endif" # Finish the ifdef HAVE_DEBUG_H echo "" echo "#endif"