Linux C + + version release automatic script

Source: Internet
Author: User

Software release has the principle of software version management, which is a combination of Linux and C + + Project Publishing method, a brief introduction of how to automatically integrate dynamic version management scripts.

Key points for software release release
From the software version management principles we need to be aware of the following key points:

= = "Major version (Ver_major): Project (product) owner Maintenance
= = "minor version (Ver_minor): Technical (version) interface person Maintenance
= = Version number (ver_revision): code base automatic Upgrade update
= = "Compile date (build_date): Compile machine's system date
= = "Compile time (build_time): Compile the machine's system time
= = "Compile identifier (BUILD_ID): Compile unique code
= = Compiler (author_name): compiling the publisher

= = "Contact information (author_contact): Compile the Publisher contact information


Dynamic version Management scripts

= = "Supports major version, minor version, contact custom

= = "Support Publisher or publish account customization

= = "Support version number, compile date, compile time dynamic acquisition

= = "Automatic generation of Version.c/version.h (Version.h for function prototype definition, directly in the application include.) )

#!/bin/bash# parameter Checkif [$#-ne 4] && [$#-ne 5]then echo "Usage ($#): $ major_num minor_num debug/r Elease e-mail Author "echo" or: $ major_num minor_num debug/release e-mail "exitfi# functionversion () {build_date = ' Date ' +%y-%m-%d "' build_time= ' Date" +%r:%s "' version_num= ' svn info|grep Revision |cut--delimiter=" "-f2 ' Cat > VERSION.C <<eeeeeee#include "stdio.h" #include "version.h" #define Ver_major $1#define ver_minor $2#define ver_ REVISION $VERSION _num#define ver_dr_flag "$" #define Ver_build_date "$BUILD _date" #define Ver_build_time "$BUILD _time" #define AUTHOR_CONTACT "$4" #define AUTHOR_NAME "$ #define Version_all" $3_${build_date}_${build_time}_v$1_$2_$ Version_num "Char *get_version () {return version_all;} Char *get_ver_author () {return author_name;} Char *get_ver_author_contact () {return author_contact;} Char *get_ver_flag () {return ver_dr_flag;} Char *get_build_date () {return ver_build_date;} Char *get_build_time () {return ver_build_time;} int Get_ver_Major () {return ver_major;} int Get_ver_minor () {return ver_minor;} int Get_ver_rev () {return ver_revision;} Eeeeeeecat > Version.h <<eeeeeee#ifndef __version_h__ #define __VERSION_H__ Char *get_version (); Char *get_ver_ author (); Char *get_ver_author_contact (); Char *get_ver_flag (); Char *get_build_date (); Char *get_build_time (); int get_ Ver_major (); int get_ver_minor (); int Get_ver_rev (); #endif/* __version_h__ */eeeeeee}# Printecho "#################### ########### "echo" ######### $ "echo" ######### Major Number: "echo" ######### Minor Number: $ "echo" ######### d/r Flag : $ "echo" ######### Contact: $4 "If [$#-eq 4]thenauthor= ' who | Cut--delimiter= ""-f1 ' Elseauthor=$5fiecho "######### Author: $AUTHOR" version $ $ $4 $AUTHORif [$? -eq 0]then echo "######### done!" Else "######### failed! "Fiecho" ############################### "

Dynamically generated version code

In SVN version Coogan directory execution

#./version.sh 1 2 DEBUG [email protected] lida########################################. /version.sh######### Major number:1######### Minor number:2######### d/r flag:debug######### Contact: [Email protected] ######### author:lida######### done!###############################


Version.c

#include "stdio.h" #include "version.h" #define Ver_major 1#define ver_minor 2#define ver_revision 271#define Ver_dr_flag "DEBUG" #define Ver_build_date "2016-05-10" #define VER_BUILD_TIME "18:29:35" #define AUTHOR_CONTACT "[Email protected]" #define AUTHOR_NAME "    Lida" #define Version_all  "debug_2016-05-10_18:29:35_v1_2_271" char *get_version () { return version_all;} Char *get_ver_author () {return author_name;} Char *get_ver_author_contact () {return author_contact;} Char *get_ver_flag () {return ver_dr_flag;} Char *get_build_date () {return ver_build_date;} Char *get_build_time () {return ver_build_time;} int Get_ver_major () {return ver_major;} int Get_ver_minor () {return ver_minor;} int Get_ver_rev () {return ver_revision;}

Version.h

#ifndef __version_h__ #define __VERSION_H__ Char *get_version (), Char *get_ver_author (), Char *get_ver_author_contact () ; Char *get_ver_flag (); Char *get_build_date (); Char *get_build_time (); int get_ver_major (); int get_ver_minor (); int get_ Ver_rev (); #endif/* __version_h__ */

Demo Sample integrated version management

Main.c

#include <stdio.h> #include "version.h" void Main () {printf ("Get_version:%s\n", Get_version ());p rintf ("Get_ver_ Author:%s\n ", Get_ver_author ());p rintf (" Get_ver_author_contact:%s\n ", Get_ver_author_contact ());p rintf (" Get_ver_ Flag:%s\n ", Get_ver_flag ());p rintf (" Get_build_date:%s\n ", Get_build_date ());p rintf (" Get_build_time:%s\n ", get_ Build_time ());p rintf ("Get_ver_major:%d\n", Get_ver_major ());p rintf ("Get_ver_minor:%d\n", Get_ver_minor ());p rintf ("Get_ver_rev:%d\n", Get_ver_rev ());}

Compiling and executing the above version and main programs

# gcc main.c version.c#./a.outget_version:debug_2016-05-10_18:29:35_v1_2_271get_ver_author:lidaget_ver_author_ Contact: [Email protected]get_ver_flag:debugget_build_date:2016-05-10get_build_time:18:29:35get_ver_major:1get_ ver_minor:2get_ver_rev:271








Linux C + + version release automatic script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.