Created
April 15, 2014 14:30
-
-
Save vuryleo/10737273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# $File: Makefile | |
# $Date: Tue Apr 15 22:29:46 2014 +0800 | |
# | |
# A single output portable Makefile for | |
# simple c project | |
OBJ_DIR = obj | |
LIB_DIR = lib | |
BIN_DIR = bin | |
TARGET = minact | |
SRC_DIR = src | |
BIN_TARGET = $(BIN_DIR)/$(TARGET) | |
DEFINES += | |
MPIARG ?= | |
PARAM ?= | |
DIRNAME=$(shell basename `pwd`) | |
PKGCONFIG_LIBS = | |
INCLUDE_DIR = -Iinclude/ -I/usr/include/ -I/opt/local/include/ | |
CXXFLAGS += -O0 -g | |
CXXFLAGS += #-static -static-libstdc++ | |
CXXFLAGS += $(DEFINES) | |
CXXFLAGS += -std=c99 | |
CXXFLAGS += -Wall -Wextra | |
CXXFLAGS += $(INCLUDE_DIR) | |
CXXFLAGS += #$(shell pkg-config --cflags --libs $(PKGCONFIG_LIBS)) | |
CXXFLAGS += #$(shell Magick++-config --cppflags --cxxflags) | |
CXXFLAGS += #-m64 | |
LDFLAGS = | |
LDFLAGS += #$(shell Magick++-config --ldflags --libs) | |
CXX = clang | |
CXXSOURCES = $(shell find $(SRC_DIR) -name "*.c") | |
OBJS = $(addprefix $(OBJ_DIR)/,$(notdir $(CXXSOURCES:.c=.o))) | |
LIBS = $(addprefix $(LIB_DIR)/,lib$(notdir $(CXXSOURCES:.c=.a))) | |
DYLIBS = $(LIBS:.a=.dylib) | |
DEPFILES = $(OBJS:.o=.d) | |
.PHONY: all clean run rebuild gdb check | |
all: $(BIN_TARGET) | |
@echo "compilation succeed." | |
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | |
@mkdir -pv $(dir $@) | |
@echo "[cxx] $< ..." | |
@$(CXX) -c $< $(CXXFLAGS) -o $@ | |
$(OBJ_DIR)/%.d: $(SRC_DIR)/%.c | |
@mkdir -pv $(dir $@) | |
@echo "[dep] $< ..." | |
@$(CXX) $(INCLUDE_DIR) $(CXXFLAGS) -MM -MT "$(OBJ_DIR)/$(<:.c=.o) $(OBJ_DIR)/$(<:.c=.d)" "$<" > "$@" | |
sinclude $(DEPFILES) | |
$(BIN_DIR): | |
@mkdir -pv $(BIN_DIR) | |
$(BIN_TARGET): $(BIN_DIR) $(OBJS) | |
@echo "[link] $@ ..." | |
@$(CXX) $(OBJS) -o $@ $(LDFLAGS) | |
clean: | |
rm -rf $(OBJ_DIR) $(LIB_DIR) $(BIN_DIR) | |
rebuild: | |
+@make clean | |
+@make | |
run: $(BIN_TARGET) | |
./$(BIN_TARGET) $(PARAM) $(ARG) | |
gdb: $(BIN_TARGET) | |
gdb ./$(BIN_TARGET) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment