码迷,mamicode.com
首页 > 其他好文 > 详细

一个简单的Makefile示例

时间:2016-02-18 13:35:20      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

#*
#***********************************************************************************************
#	Makefile
#
#	Author    	: Lyu Yang
#	Description : Makefile for GNU/GCC
#
#***********************************************************************************************
#*

# Project Name
PROJECT = main

# Architecture and Platform
ARCH = x86
PLATFORM = Debug
CROSS = 

# Include Dirs and Library Dirs
INCLUDE_DIRS = -I ./
LIBRARY_DIRS = -L ./

# GCC Parameters
CC = $(CROSS)gcc
CFLAGS = -c $(INCLUDE_DIRS)

CXX = $(CROSS)g++
CXXFLAGS = -c $(INCLUDE_DIRS)

AS = $(CROSS)gcc
ASFLAGS =  -x assembler-with-cpp

LD = $(CROSS)g++
LDFLAGS = $(LIBRARY_DIRS)

OBJCP = $(CROSS)objcopy
OBJCPFLAGS = -O binary -S -R .note -R .commen

AR = $(CROSS)ar
ARFLAGS = cr

DUMP = $(CROSS)objdump
DUMPFLAG = -d

SIZE = $(CROSS)size

# Make Temp Dirs
$(shell mkdir $(PLATFORM) && mkdir $(PLATFORM)/$(ARCH))

# Source Files
SRCS := $(wildcard dir1/*.cpp)
SRCS += $(wildcard dir2/*.cpp)

# Build Objects
OBJS = $(SRCS:.cpp=.o)
OBJB = $(patsubst %.cpp, $(PLATFORM)/$(ARCH)/%.o, $(notdir ${SRCS}))

# Make ALL
.PHONY: all clean debug
all: $(PROJECT).exe

$(PROJECT).exe: $(OBJB)
	@$(LD) $(LDFLAGS) $^ -o $(PLATFORM)/$(ARCH)/$@
	@echo "$(CXX) $(notdir $^) -o $(notdir $@)"

$(OBJB): $(OBJS)

%.o: %.cpp
	@$(CXX) $(CFLAGS) $^ -o $(PLATFORM)/$(ARCH)/$(notdir $@)
	@echo "$(CXX) $(notdir $^) -o $(notdir $@)"

clean:
	@rm -rf $(PLATFORM)
	@echo "Clean All!"
	
debug:
	@$(CROSS)gdb $(PLATFORM)/$(ARCH)/$(PROJECT).exe

  

一个简单的Makefile示例

标签:

原文地址:http://www.cnblogs.com/lyuyangly/p/5197808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!