Add utility functions to get the software version string.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This commit is contained in:
		
							parent
							
								
									0c49d16244
								
							
						
					
					
						commit
						c3119807a3
					
				
							
								
								
									
										15
									
								
								makefile
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								makefile
									
									
									
									
									
								
							| @ -30,7 +30,8 @@ CFLAGS	= -Wall $(VER) $(INC) $(DEBUG) $(FEAT_CFLAGS) $(EXTRA_CFLAGS) | ||||
| LDLIBS	= -lm -lrt $(EXTRA_LDFLAGS) | ||||
| PRG	= ptp4l pmc phc2sys hwstamp_ctl | ||||
| OBJ	= bmc.o clock.o config.o fsm.o ptp4l.o mave.o msg.o phc.o pi.o port.o \
 | ||||
|  print.o raw.o servo.o sk.o tlv.o tmtab.o transport.o udp.o udp6.o uds.o util.o | ||||
|  print.o raw.o servo.o sk.o tlv.o tmtab.o transport.o udp.o udp6.o uds.o util.o \
 | ||||
|  version.o | ||||
| 
 | ||||
| OBJECTS	= $(OBJ) pmc.o phc2sys.o hwstamp_ctl.o sysoff.o | ||||
| SRC	= $(OBJECTS:.o=.c) | ||||
| @ -54,6 +55,15 @@ phc2sys: phc2sys.o sk.o sysoff.o print.o | ||||
| 
 | ||||
| hwstamp_ctl: hwstamp_ctl.o | ||||
| 
 | ||||
| version.o: .version version.sh $(filter-out version.d,$(DEPEND)) | ||||
| 
 | ||||
| .version: force | ||||
| 	@echo $(version) > .version.new; \
 | ||||
| 	cmp -s .version .version.new || cp .version.new .version; \
 | ||||
| 	rm -f .version.new; | ||||
| 
 | ||||
| force: | ||||
| 
 | ||||
| install: $(PRG) | ||||
| 	mkdir -p $(sbindir) $(man8dir) | ||||
| 	install $(PRG) $(sbindir) | ||||
| @ -64,6 +74,7 @@ clean: | ||||
| 
 | ||||
| distclean: clean | ||||
| 	rm -f $(PRG) | ||||
| 	rm -f .version | ||||
| 
 | ||||
| # Implicit rule to generate a C source file's dependencies.
 | ||||
| %.d: %.c | ||||
| @ -78,3 +89,5 @@ ifneq ($(MAKECMDGOALS), distclean) | ||||
| -include $(DEPEND) | ||||
| endif | ||||
| endif | ||||
| 
 | ||||
| .PHONY: all force clean distclean | ||||
|  | ||||
							
								
								
									
										35
									
								
								version.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								version.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| /**
 | ||||
|  * @file version.c | ||||
|  * @brief Provides a software version string. | ||||
|  * @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com> | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License along | ||||
|  * with this program; if not, write to the Free Software Foundation, Inc., | ||||
|  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
|  */ | ||||
| #include "version.h" | ||||
| 
 | ||||
| #define STRINGIFY_(x) #x | ||||
| #define STRINGIFY(x) STRINGIFY_(x) | ||||
| 
 | ||||
| static const char *version = STRINGIFY(VER); | ||||
| 
 | ||||
| void version_show(FILE *fp) | ||||
| { | ||||
| 	fprintf(fp, "%s\n", version); | ||||
| } | ||||
| 
 | ||||
| const char *version_string(void) | ||||
| { | ||||
| 	return version; | ||||
| } | ||||
							
								
								
									
										37
									
								
								version.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								version.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| /**
 | ||||
|  * @file version.h | ||||
|  * @brief Provides a software version string. | ||||
|  * @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com> | ||||
|  * | ||||
|  * This program is free software; you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation; either version 2 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU General Public License along | ||||
|  * with this program; if not, write to the Free Software Foundation, Inc., | ||||
|  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
|  */ | ||||
| #ifndef HAVE_VERSION_H | ||||
| #define HAVE_VERSION_H | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| /**
 | ||||
|  * Print the software version string into the given file. | ||||
|  * @param fp  File pointer open for writing. | ||||
|  */ | ||||
| void version_show(FILE *fp); | ||||
| 
 | ||||
| /**
 | ||||
|  * Provide the software version as a human readable string. | ||||
|  * @return  Pointer to a static global buffer holding the result. | ||||
|  */ | ||||
| const char *version_string(void); | ||||
| 
 | ||||
| #endif | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user