diff --git a/.gitignore b/.gitignore index 515ad842..8d7ea98b 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ clean.log make.log .previous_build .current_build +*.defines # Visual Studio .vs diff --git a/scripts/dump-preprocessor-defines.sh b/scripts/dump-preprocessor-defines.sh new file mode 100755 index 00000000..a5478318 --- /dev/null +++ b/scripts/dump-preprocessor-defines.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Copyright (C) 2020 Kevin Croft +# SPDX-License-Identifier: GPL-2.0-or-later +# +# This script captures pre-processor #define statements +# matching the as-compiled state of the source file. +# The script runs recursively for all source files, and +# saves the results in corresponding .defines file. +# +set -euo pipefail + +# Ensure the project has been configured +if [[ ! -f config.h ]]; then + echo "config.h not found. Please ./configure the project first" + exit 1 +fi + +# Gather include paths +root_dir="$(pwd)" +root_include="$root_dir/include" +gcc_includes="$(gcc -xc++ -E -v - < /dev/null 2>&1 | grep '^ ' | tail -n +2 | sed 's/^ /-I/' | xargs)" +sdl_includes="$(sdl2-config --cflags)" + +# Round up our source files +sources=( "$(find . -name '*.cpp' -o -name '*.c')" ) + +# Run it +parallel \ + "g++ -std=gnu++11 \ + $gcc_includes \ + $sdl_includes \ + -I$root_dir \ + -I$root_include \ + -I{//} \ + -DHAVE_CONFIG_H \ + -E -dM -include '{}' - < /dev/null 2> /dev/null \ + | grep '^#define' > '{.}.defines' \ + ; echo '{} to {.}.defines'" ::: "${sources[@]}"