Skip to content

Instantly share code, notes, and snippets.

@ElectricCoffee
Created November 24, 2014 10:29
Show Gist options
  • Save ElectricCoffee/00b2c22d489c83409f7c to your computer and use it in GitHub Desktop.
Save ElectricCoffee/00b2c22d489c83409f7c to your computer and use it in GitHub Desktop.
convenience functions for dealing with c compilation
#!/bin/bash
function compile-c() {
if [ $# -eq 0 ]
then INPUT="*.c"
else INPUT="$1.c"
fi
gcc -ansi -pedantic -Wall -Werror $INPUT -o program
}
function make-makefile() {
if [ -f makefile ]
then echo "makefile already exists."
else
echo "creating makefile..."
touch makefile
echo "# Basic makefile for the project" > makefile
echo "CC = gcc" >> makefile
echo "CFLAGS = -ansi -pedantic -Wall -Werror" >> makefile
echo ".PHONY: clean" >> makefile
echo -en '\n' >> makefile
echo "program: %.o" >> makefile
echo -e '\t$(CC) *.o -o program\n' >> makefile
echo "%.o:" >> makefile
echo -e '\t$(CC) $(CFLAGS) *.c -c\n' >> makefile
echo "clean:" >> makefile
echo -e '\trm -f *.o *~ program' >> makefile
echo "makefile created."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment