Skip to content

Instantly share code, notes, and snippets.

@kiyui
Last active August 29, 2015 14:05
Show Gist options
  • Save kiyui/b043ed46da8db8a86b73 to your computer and use it in GitHub Desktop.
Save kiyui/b043ed46da8db8a86b73 to your computer and use it in GitHub Desktop.
Simple makefile
#CC = gcc or g++
CC = gcc
#CFLAGS are compile flags such as -lm to include <math.h>
#or -std=c++0x for C++11
CFLAGS = -Wall -std=c99
#TARGET is the name of your main file
TARGET = myMain
#OBJECTS = $(TARGET).o library1.o library.o, all the header files here
OBJECTS = $(TARGET).o myLib.o
#EXTRA Command line arguments
#Syntax: make EXTRA="arg1 arg2"
EXTRA? = ""
#Do not modify
$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(EXTRA) $(OBJECTS) -o $(TARGET).bin
#%.c or %.cpp
%.o : %.c
$(CC) $(CFLAGS) $(EXTRA) -c $<
clean:
rm -rvf $(OBJECTS) $(TARGET).bin *~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment