Thursday, October 24, 2013

Simple Makefile to compile and link all the cpp files in the folder

DEFINC := /usr/include/
LIBS := /usr/lib/
INC := $(DEFINC)


CXXFLAGS :=
CXXFLAGS = -I$(INC)
CXXFLAGS += -O2 -march=native
CXXFLAGS += -fPIC

LINK :=
LDFLAGS :=
LDFLAGS += -L$(LIBS) $(LINK)


CXX = g++
LD = g++

SRC := $(wildcard ./*.cpp)
OBJ := $(addprefix ./,$(notdir $(SRC:.cpp=.o)))
TARGET := test


all: $(TARGET)

$(TARGET): $(OBJ)
$(CXX) $(LDFLAGS) -o $@ $^

obj/%.o: src/%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<

clean :
rm -rf ./*.o $(TARGET)

No comments:

Post a Comment