4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-02 04:20:28 +08:00

Cygwin: uname: generate default release string from git as well

When building a release with cygport, we get uname version info
from cygport, which in turn gets version info from `git describe'.

During development, the release info for local builds was not
that helpful yet.  Fix that, by creating version info from
`git describe' if CYGPORT_RELEASE_INFO isn't given.  Make sure to
always force rebuild of the version info to pick up source file
changes as well as git actions.

Rearrange code slightly to generate machine info first, release info
after that.  Use snprintf to generate release string safely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-12-07 21:14:27 +01:00
parent b9ebb4e9a5
commit ea0a84424c
2 changed files with 24 additions and 15 deletions

View File

@ -365,7 +365,8 @@ GMON_FILES= \
profil.c
GENERATED_FILES= \
sigfe.s
sigfe.s \
uname_version.c
liblib_a_SOURCES= \
$(LIB_FILES)
@ -418,6 +419,11 @@ dirs = $(srcdir) $(srcdir)/fhandler $(srcdir)/lib $(srcdir)/libc $(srcdir)/math
find_src_files = $(wildcard $(dir)/*.[chS]) $(wildcard $(dir)/*.cc)
src_files := $(foreach dir,$(dirs),$(find_src_files))
uname_version.c: .FORCE
$(AM_V_GEN)cd $(srcdir) && \
echo "const char *uname_dev_version = \"$$(git describe --dirty | sed -e 's/cygwin-//')\";" > $(abs_builddir)/uname_version.c
.FORCE:
# mkvers.sh creates version.cc in the first place, winver.o always
# second, so version.cc is always older than winver.o
version.cc: scripts/mkvers.sh include/cygwin/version.h winver.rc $(src_files)

View File

@ -9,6 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include <stdio.h>
#include <sys/utsname.h>
#include <netdb.h>
#include "cygwin_version.h"
@ -41,29 +42,31 @@ uname_x (struct utsname *name)
memset (buf, 0, sizeof buf);
cygwin_gethostname (buf, sizeof buf - 1);
strncat (name->nodename, buf, sizeof (name->nodename) - 1);
/* release */
#ifdef CYGPORT_RELEASE_INFO
stpcpy (name->release, __XSTRING (CYGPORT_RELEASE_INFO));
#else
__small_sprintf (name->release, "%d.%d.%d-0.%d.local.",
cygwin_version.dll_major / 1000,
cygwin_version.dll_major % 1000,
cygwin_version.dll_minor,
cygwin_version.api_minor);
#endif
/* version */
stpcpy (name->version, cygwin_version.dll_build_date);
strcat (name->version, " UTC");
/* machine */
switch (wincap.cpu_arch ())
{
case PROCESSOR_ARCHITECTURE_AMD64:
strcat (name->release, strcpy (name->machine, "x86_64"));
strcpy (name->machine, "x86_64");
break;
default:
strcpy (name->machine, "unknown");
break;
}
/* release */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation="
#ifdef CYGPORT_RELEASE_INFO
snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
__XSTRING (CYGPORT_RELEASE_INFO), name->machine);
#else
extern const char *uname_dev_version;
snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
uname_dev_version, name->machine);
#endif
#pragma GCC diagnostic pop
/* version */
stpcpy (name->version, cygwin_version.dll_build_date);
strcat (name->version, " UTC");
/* domainame */
memset (buf, 0, sizeof buf);
getdomainname (buf, sizeof buf - 1);