#! /bin/bash# Project.sh# Writed by Huo Yun(cloudblaze@yeah.net)## 1. 2022-10-01 20:58 Implement creation project with template.# 2. 2022-12-31 21:37 Output message when use unknown command.# Create projectfunctioncreateProject(){# Verify the name of the new project.if[$#-lt1]thenecho"What is the name of the new project?"return1fiecho-n"Create the new project $1 ... "# Copy project template.cp-r ./Demo_Template ./$1# Adjust the parameters in templatesed-i's/<Project_Name>/'$1'/g' ./$1/Makefile
echo"Done!"}# Verify the commandif[$#==0]thenecho"Usage: Project.sh <command> [<argument>]"exit1ficase"$1"in# Create new project"new") createProject $2exit$?;;
*)echo"Unknown command '$1'";;esac
Demo_Template/Makefile
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)