ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was loking at a way to automaticly increment the build number in a gcc project written in C.
I could make a small program to re-write a header file containing the version number. Everytime make is run, the program parses the header, gets the version number, incremetns it, writes back the file (as a #define) , then the rest of the compilation process is ran.
It would work, but it is lot of work simply to have a build number!! Is there a better way to do it?
By the way, I could manualy update the build number, but seriously, who can remember to always change a number every time he presses the build button!!
Hmm.. interesting idea.. can't say that I have any ideas offhand, except for something similar to the method you described. In projects where I'm maintaining builds, I typically just manually change the build number when I do major revisions.
You might be able to do what you want with a simple one-line awk script.
For example:
1. Let's say your version is in a header file that looks like this:
less version.h =>
#define VERSION 2.0.1
2. Your awk script might then look something like this:
awk '/VERSION/ {
split ($3, a,.);
a[2] = a[2] + 1;
printf ("#define VERSION %d.%d.%d", a[0], a[1], a[2]);
}' version.h
'Hope that helps .. PSM
PS:
This is just a suggestion - I haven't tested or debugged it yet.
At a minimum, you'll need to update your "version.h" header with the
"awk" output.
I think I will give it a try. Especially since gawk is available on both Linux and Windows. (we developp everything cross platform).
As for writing back to the file, if I used a file simply for this version number I could simply do a
"myAwkScript > version.h"
in the make file.
Be the way, if you are wondering why version numbers are so important, it is beacause, I'm developping for a microcontrolleur (using avr-gcc). This version is the only way I have to know what version of the code is running in the chip!
When I run the code, it does what I want but also execute the print statement even if the pattern does not match. For exemple, the above file will give this result
If I put aditionnal lines (white lines or not) , the instructions will execute once for every line. The question is, its the pattern at the top of the bracket supposed to specify the code will only execute if the pattern is matched?
If you mean the last number, it is only the build number.
Version number will not actually be shown to the user. The version number is in the code of a microcontrolleur. I need it to let my drivers know what version of firmware the card is running.
The build number itself is more for myself. This way I dont have to ask myself: "did I reprogram the number 1 card or was it number 2?" With this build numbers, I can make sure all my cards are running the same version of firmware.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.