Created
July 17, 2018 22:10
-
-
Save slinkydeveloper/e25dc982d1d2b27f3e74eda8a538c065 to your computer and use it in GitHub Desktop.
Bash script to concatenate multiple header/impl c files and main.c into one single main file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to create prod version of project (concat all deps in one single file) | |
cd "$(dirname "$0")" | |
rm -f main_prod.c | |
tempfile=$(mktemp) | |
tempmain=$(mktemp) | |
cat main.c > "$tempmain" | |
IFS=$'\n' | |
deps=($(sed -nE 's!#include *\"([a-zA-Z_]+)\.h\"!\1!p' < main.c)) | |
for dep in "${deps[@]}"; do | |
echo "Found $dep" | |
cat "$dep.h" >> "$tempfile" | |
sed "s/#include \"$dep.h\"//" < "$dep.c" >> "$tempfile" | |
sed -i "s/#include \"$dep.h\"//" "$tempmain" | |
done | |
sed -i "s/#define DEBUG//" "$tempmain" | |
touch main_prod.c | |
echo "//This file was created using create_prod_version.sh script" >> main_prod.c | |
cat "$tempfile" >> main_prod.c | |
cat "$tempmain" >> main_prod.c | |
rm $tempfile | |
rm $tempmain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment