#!/bin/sh # # This file is part of cputemp2maxfreq. # # Copyright (C) 2023-2024 pa4wdh # # cputemp2maxfreq is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # cputemp2maxfreq is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with cputemp2maxfreq. If not, see . # # 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 CPUTEMP CPULIST" 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 a GPL license header head -n 17 cputemp2maxfreq.c echo "" echo " This file is generated by $0," echo " do not edit anything other than the configuration section." echo "*/" # 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"