Skip to content

Instantly share code, notes, and snippets.

@sagidayan
Created February 3, 2015 12:23
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 sagidayan/577da25c7e23b133623c to your computer and use it in GitHub Desktop.
Save sagidayan/577da25c7e23b133623c to your computer and use it in GitHub Desktop.
Generic Makefile
# Sagi Dayan - Makefile
# 2014-2015
# compiler - for C++ change to g++
CC=gcc
# compile arguments
CFLAGS+=-c -g -Wall
# linker flags
LDFLAGS+=
# libraries
LIBS+=
# our source files
SOURCES=########ADD_SOURCES#######
# a macro to define the objects from sources
OBJECTS=$(SOURCES:.c=.o)
# executable name
EXECUTABLE=########CHANGE_NAME#######
$(EXECUTABLE): $(OBJECTS)
@echo "Building target" $@ "..."
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)
@echo "Done!"
# a rule for generating object files given their c files
.c.o:
@echo "Compiling" $< "..."
$(CC) $(CFLAGS) $< -o $@
@echo "Done!"
clean:
@echo "Ceaning up *.o Files..."
rm -rf *s *o $(EXECUTABLE)
@echo "Done!"
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment