[编译环境][Bash]一个简单的项目管理系统(逐步完善)

一个简单的项目管理系统(逐步完善)

  • Project.sh
  • Demo_Template/Makefile
  • Demo_Template/Makefile.rule
  • Demo_Template/main.cpp

Project.sh

#! /bin/bash

# Project.sh
# Writed by Huo Yun([email protected])
#
# 1. 2022-10-01 20:58 Implement creation project with template.
# 2. 2022-12-31 21:37 Output message when use unknown command.


# 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 -n "Create the new project $1 ... "

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

	echo "Done!"
}

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

case "$1" in
	# Create new project
	"new") createProject $2
	exit $?
	;;
	*) 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	= 
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)

Demo_Template/Makefile.rule

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 $@.$$$$

Demo_Template/main.cpp

#include 

int main(int argc, char *argv[])
{
	std::cout << "hello, world!" << std::endl;

	return EXIT_SUCCESS;
}

你可能感兴趣的:(编译环境,bash,c++,linux)