Skip to content

Instantly share code, notes, and snippets.

@kaovilai
Last active April 30, 2018 20:12
Show Gist options
  • Save kaovilai/96e6a60ab55935a18fd76f3bceebf148 to your computer and use it in GitHub Desktop.
Save kaovilai/96e6a60ab55935a18fd76f3bceebf148 to your computer and use it in GitHub Desktop.
CSC230 Makefile(s)
#############USER#############
#compiles a single exercise
ex = []#name here
arg = []#arguments here
##############################
#######################DEV############################
all:
gcc -g -pg -Wall -std=c99 $(ex).c -o $(ex)
run: all
./$(ex) $(arg)
######################################################
#####################################COMPILER SETTINGS######################################
#set c complier to GNU C Compiler
CC = gcc
#Show all warning, C99 Standard, with Source, with Profiler, with non-standard GNU source
CFLAGS = -Wall -std=c99 -g -pg -D_GNU_SOURCE
#Link non-standard libraries
LDLIBS = -lm
############################################################################################
##################################PROJECT SPECIFIC VARIABLES############
#list of non-executable objects to make
objects = []#**INSERT LIST OF OBJECTS HERE with .o extension**#
#list of executable objects
prg = []#**INSERT LIST OF OBJECTS TO BE TURNED INTO EXECUTABLE**#
#things that needs to be made into object files before compiling
ingredients = $(objects) $(prg)
########################################################################
#####################################MAKING-OUT-AREA##############################################
#clean and create program executables
all: clean exe
#create each executables using objects given ingredients are prepared
exe: $(ingredients)
$(foreach p,$(prg), $(CC) $(CFLAGS) $(p) $(objects) -o $(patsubst %.o,%,$(p)) $(LDLIBS);)
#for now, all objects file are created using .c and header files of the same name
*.o: *.c
#clean ingredients off the table on both UNIX and DOS platforms
clean:
rm -f $(ingredients) || del -f $(ingredients)
##################################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment