Last active
July 9, 2021 13:14
-
-
Save pouya-abbassi/2be0785705ac091d1d194737c80cd063 to your computer and use it in GitHub Desktop.
My beloved C makefile
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
# Latest version: https://gist.github.com/pouya-abbassi/2be0785705ac091d1d194737c80cd063 | |
# The compiler: gcc for C program. | |
CC = gcc | |
# Optimize as much as possible. | |
CFLAGS += -O3 | |
# GNU dialect of ISO C17. | |
CFLAGS += -std=gnu17 | |
# Turn on most, but not all compiler warnings. | |
CFLAGS += -Wall | |
# Turn on some extra warnings. | |
CFLAGS += -Wextra | |
# Turn warnings into errors. | |
CFLAGS += -Werror | |
# Warn if floating-point values are used in quality comparisons. | |
CFLAGS += -Wfloat-equal | |
# Warn whenever a local variable or type declaration shadows something. | |
CFLAGS += -Wshadow | |
# Warn if a function is declared or defined without specifying the argument types. | |
CFLAGS += -Wstrict-prototypes | |
# Warn if a global function is defined without a previous prototype declaration. | |
CFLAGS += -Wmissing-prototypes | |
# Error if a function is undeclared. | |
CFLAGS += -Werror-implicit-function-declaration | |
# Warn whenever a `switch` statement does not have a `default` case. | |
CFLAGS += -Wswitch-default | |
# Warn if a variable is used without first being initialized. | |
CFLAGS += -Wuninitialized | |
# Warn about variables that are initialized with themselves. | |
CFLAGS += -Winit-self | |
# Warn about duplicated conditions in a if-else-if chain. | |
CFLAGS += -Wduplicated-cond | |
# Warn when an if-else-if has identical branches. | |
CFLAGS += -Wduplicated-branches | |
# Warn about uses of logical operators in where a bit-wise operator is expected. | |
CFLAGS += -Wlogical-op | |
# Warn if the compiler detects path that might dereference a Null pointer. | |
CFLAGS += -Wnull-dereference | |
# Issue all the warnings demanded by strict ISO C. | |
CFLAGS += -pedantic | |
# Generates traps for signed overflow on addition; Slightly slower runtime! | |
CFLAGS += -ftrapv | |
# Specify the name of the target architecture. | |
# CFLAGS += -march=native | |
TARGET = main | |
build: | |
$(CC) $(CFLAGS) $(TARGET).c -o $(TARGET) && ./main | |
native: | |
$(CC) $(CFLAGS) -march=native $(TARGET).c -o $(TARGET) && ./main | |
static: | |
$(CC) $(CFLAGS) -static $(TARGET).c -o $(TARGET) | |
debug: | |
$(CC) -O0 -std=gnu17 -g $(TARGET).c -o $(TARGET) | |
temps: | |
$(CC) -O3 -std=gnu17 -save-temps -fverbose-asm -masm=intel $(TARGET).c | |
run: | |
./$(TARGET) | |
clean: | |
$(RM) $(TARGET) $(TARGET).o $(TARGET).s $(TARGET).i a.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment