[编程语言][Bash]项目管理脚本

项目管理脚本

#! /bin/bash

# Project.sh
# Writed by Huo Yun(cloudblaze@yeah.net)
#
# 1. 2022-10-01 20:58 Implement creation project with template.


# Create project
function createProject()
{
	# Verify the name of the new project.
	if [ $# -lt 1 ]
	then
		echo "What is the name of the new project?"
		return 1
	fi

	echo "Create the new project $1 ..."

	# Copy project template.
	cp -r ./Demo_Template ./$1
	# Adjust the parameters in template
	sed -i 's/<Project_Name>/'$1'/g' ./$1/Makefile
}

# Verify the command
if [ $# == 0 ]
then
	echo "Usage: Project.sh <command> [<argument>]"
	exit 1
fi

case "$1" in
	# Create new project
	"new") createProject $2
	exit $?
	;;
esac
# Makefile
# Writed by Huo Yun(cloudblaze@yeah.net)
#
# 1. 2022-10-01 20:58 Implement creation project with template.


ROOT				= $(shell pwd)
export RULE_FILE	= $(ROOT)/Makefile.rule

include $(RULE_FILE)

CXXFLAGS	+=
LDFLAGS		+= `pkg-config --libs fmt`

PROJECT_NAME	= <Project_Name>
all: $(PROJECT_NAME)

SOURCES = $(shell ls *.cpp)
include $(SOURCES:.cpp=.d)

$(PROJECT_NAME): $(SOURCES:.cpp=.o)
	$(CXX) $^ -o $@ $(LDFLAGS)
	
.PHONY: run zip clear_screen clean

run: $(PROJECT_NAME)
	@echo "==========" $(shell date +"%F %T") "=========="
	@./$(PROJECT_NAME)

zip: clean clear_screen
	zip -r $(PROJECT_NAME)_$(shell date +%Y%m%d%H%M%S).zip . -x $(PROJECT_NAME)_*.zip

clear_screen:
	clear

clean:
	rm -f *.d \
		*.o \
		$(PROJECT_NAME)
# Makefile.rule
# Writed by Huo Yun(cloudblaze@yeah.net)
#
# 1. 2022-10-01 20:58 Implement creation project with template.


CXX			= g++
CXXFLAGS	= -Wall -std=c++20
LDFLAGS		= 

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

%.a: %.o
	$(AR) $(ARFLAGS) $@ $^

%: %.o
	$(CXX) $^ -o $@ $(LDFLAGS)

%.d: %.cpp
	@set -e; rm -f $@; \
	$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值