Skip to content

Instantly share code, notes, and snippets.

@daa233
Last active March 26, 2020 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daa233/d8582185c7d889d38ad966ddd0bce841 to your computer and use it in GitHub Desktop.
Save daa233/d8582185c7d889d38ad966ddd0bce841 to your computer and use it in GitHub Desktop.
#
# A simple makefile for managing build of project composed of C source files.
# References: https://web.stanford.edu/class/cs107/resources/make
#
# It is likely that default C compiler is already gcc, but explicitly
# set, just to be sure
CC = gcc
# The CFLAGS variable sets compile flags for gcc:
# -g compile with debug information
# -Wall give verbose compiler warnings
# -O0 do not optimize generated code
# -std=gnu99 use the GNU99 standard language definition
CFLAGS = -g -Wall -O0 -std=gnu99
# The LDFLAGS variable sets flags for linker
# -lm says to link in libm (the math library)
LDFLAGS = -lm
# In this section, you list the files that are part of the project.
# If you add/change names of source files, here is where you
# edit the Makefile.
SOURCES = demo.c vector.c map.c
OBJECTS = $(SOURCES:.c=.o)
TARGET = demo
# The first target defined in the makefile is the one
# used when make is invoked with no argument. Given the definitions
# above, this Makefile file will build the one named TARGET and
# assume that it depends on all the named OBJECTS files.
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Phony means not a "real" target, it doesn't build anything
# The phony target "clean" is used to remove all compiled object files.
# 'core' is the name of the file outputted in some cases when you get a
# crash (SEGFAULT) with a "core dump"; it can contain more information about
# the crash.
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJECTS) core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment