From d9e54ad0dd14b99b22f57cca9d76a6b6966c582c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 25 Jan 2022 10:43:41 +0100 Subject: [PATCH 1/2] Merge lib/dns/gen.h contents to lib/dns/gen.c Formerly, the gen.h header contained a compatibility layer between Win32 and POSIX platforms. Since we have already dropped the Win32 build, we can merged gen.h into gen.c as the header file is not used elsewhere. (cherry picked from commit f24b26188d466a090a85f56681d797f22bf1122d) --- lib/dns/Makefile.am | 5 +-- lib/dns/gen.c | 74 ++++++++++++++++++++++++++----- lib/dns/gen.h | 103 -------------------------------------------- 3 files changed, 65 insertions(+), 117 deletions(-) delete mode 100644 lib/dns/gen.h diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index d16dd51764..bce920c99f 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -19,13 +19,12 @@ CLEANFILES = \ $(nodist_libdns_la_SOURCES) \ gen$(BUILD_EXEEXT) -gen$(BUILD_EXEEXT): gen.c gen.h - $(CC_FOR_BUILD) -g -I. $(GEN_NEED_OPTARG) $(srcdir)/gen.c -o $@ +gen$(BUILD_EXEEXT): gen.c + $(CC_FOR_BUILD) -g -I. $(srcdir)/gen.c -o $@ EXTRA_DIST = \ dnstap.proto \ gen.c \ - gen.h \ rdata/* include/dns/enumtype.h: gen Makefile diff --git a/lib/dns/gen.c b/lib/dns/gen.c index ddc9a75b9c..e96a0adafb 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -14,21 +14,22 @@ /*! \file */ #include +#include #include #include +#include #include #include #include #include #include #include +#include #ifndef PATH_MAX #define PATH_MAX 1024 #endif /* ifndef PATH_MAX */ -#include "gen.h" - #ifndef ULLONG_MAX #define ULLONG_MAX (~0ULL) #endif /* ifndef ULLONG_MAX */ @@ -157,6 +158,11 @@ static struct ttnam { static int maxtype = -1; +typedef struct { + DIR *handle; + char *filename; +} isc_dir_t; + static char * upper(char *); static char * @@ -171,6 +177,54 @@ sd(unsigned int, const char *, const char *, char); static void insert_into_typenames(int, const char *, const char *); +static bool +start_directory(const char *path, isc_dir_t *dir) { + dir->handle = opendir(path); + + if (dir->handle != NULL) { + return (true); + } else { + return (false); + } +} + +static bool +next_file(isc_dir_t *dir) { + struct dirent *dirent; + + dir->filename = NULL; + + if (dir->handle != NULL) { + errno = 0; + dirent = readdir(dir->handle); + if (dirent != NULL) { + dir->filename = dirent->d_name; + } else { + if (errno != 0) { + fprintf(stderr, + "Error: reading directory: %s\n", + strerror(errno)); + exit(1); + } + } + } + + if (dir->filename != NULL) { + return (true); + } else { + return (false); + } +} + +static void +end_directory(isc_dir_t *dir) { + if (dir->handle != NULL) { + (void)closedir(dir->handle); + } + + dir->handle = NULL; +} + /*% * If you use more than 10 of these in, say, a printf(), you'll have problems. */ @@ -560,7 +614,7 @@ main(int argc, char **argv) { } srcdir[0] = '\0'; - while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1) { + while ((c = getopt(argc, argv, "cdits:F:P:S:")) != -1) { switch (c) { case 'c': code = 0; @@ -595,26 +649,24 @@ main(int argc, char **argv) { filetype = 'h'; break; case 's': - if (strlen(isc_commandline_argument) > + if (strlen(optarg) > PATH_MAX - 2 * TYPECLASSLEN - sizeof("/rdata/_65535_65535")) { - fprintf(stderr, "\"%s\" too long\n", - isc_commandline_argument); + fprintf(stderr, "\"%s\" too long\n", optarg); exit(1); } - n = snprintf(srcdir, sizeof(srcdir), "%s/", - isc_commandline_argument); + n = snprintf(srcdir, sizeof(srcdir), "%s/", optarg); INSIST(n > 0 && (unsigned)n < sizeof(srcdir)); break; case 'F': - file = isc_commandline_argument; + file = optarg; break; case 'P': - prefix = isc_commandline_argument; + prefix = optarg; break; case 'S': - suffix = isc_commandline_argument; + suffix = optarg; break; case '?': exit(1); diff --git a/lib/dns/gen.h b/lib/dns/gen.h deleted file mode 100644 index 1f676ca9d3..0000000000 --- a/lib/dns/gen.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * SPDX-License-Identifier: MPL-2.0 - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -/*! \file - * \brief - * This file is responsible for defining two operations that are not - * directly portable between Unix-like systems and Windows NT, option - * parsing and directory scanning. It is here because it was decided - * that the "gen" build utility was not to depend on libisc.a, so - * the functions declared in isc/commandline.h and isc/dir.h could not - * be used. - * - * The commandline stuff is really just a wrapper around getopt(). - * The dir stuff was shrunk to fit the needs of gen.c. - */ - -#pragma once - -#include -#include -#include -#include -#include /* Required on some systems for dirent.h. */ -#include /* XXXDCL Required for ?. */ - -#ifdef __cplusplus -#define ISC_LANG_BEGINDECLS extern "C" { -#define ISC_LANG_ENDDECLS } -#else /* ifdef __cplusplus */ -#define ISC_LANG_BEGINDECLS -#define ISC_LANG_ENDDECLS -#endif /* ifdef __cplusplus */ - -#ifdef NEED_OPTARG -extern char *optarg; -#endif /* ifdef NEED_OPTARG */ - -#define isc_commandline_parse getopt -#define isc_commandline_argument optarg - -typedef struct { - DIR *handle; - char *filename; -} isc_dir_t; - -ISC_LANG_BEGINDECLS - -static bool -start_directory(const char *path, isc_dir_t *dir) { - dir->handle = opendir(path); - - if (dir->handle != NULL) { - return (true); - } else { - return (false); - } -} - -static bool -next_file(isc_dir_t *dir) { - struct dirent *dirent; - - dir->filename = NULL; - - if (dir->handle != NULL) { - errno = 0; - dirent = readdir(dir->handle); - if (dirent != NULL) { - dir->filename = dirent->d_name; - } else { - if (errno != 0) { - exit(1); - } - } - } - - if (dir->filename != NULL) { - return (true); - } else { - return (false); - } -} - -static void -end_directory(isc_dir_t *dir) { - if (dir->handle != NULL) { - (void)closedir(dir->handle); - } - - dir->handle = NULL; -} - -ISC_LANG_ENDDECLS From 898d0f8ee2fd17da668966085abdad192eba138f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 25 Jan 2022 10:47:34 +0100 Subject: [PATCH 2/2] Replace AX_CC_FOR_BUILD with AX_PROG_CC_FOR_BUILD The AX_PROG_CC_FOR_BUILD implementation to find a native CC compiler is slightly better because it uses AC_PROG_CC and AC_PROG_CPP to find the native compiler instead of just defaulting to `gcc` as AX_CC_FOR_BUILD does. AX_PROG_CC_FOR_BUILD also sets BUILD_EXEEXT that we already use in the Makefile.am for `lib/dns/gen` while AX_CC_FOR_BUILD uses EXEEXT_FOR_BUILD. (cherry picked from commit b5a5eed7a0992084321c1199e5c4a64fd537e3c4) --- configure.ac | 2 +- m4/ax_cc_for_build.m4 | 79 ------------------- m4/ax_prog_cc_for_build.m4 | 157 +++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 80 deletions(-) delete mode 100644 m4/ax_cc_for_build.m4 create mode 100644 m4/ax_prog_cc_for_build.m4 diff --git a/configure.ac b/configure.ac index 03ae19764c..cae02dc0d6 100644 --- a/configure.ac +++ b/configure.ac @@ -79,7 +79,7 @@ AC_PROG_CPP_WERROR # # Find build compiler when cross compiling # -AX_CC_FOR_BUILD +AX_PROG_CC_FOR_BUILD # # Find the machine's endian flavor. diff --git a/m4/ax_cc_for_build.m4 b/m4/ax_cc_for_build.m4 deleted file mode 100644 index fdbf765426..0000000000 --- a/m4/ax_cc_for_build.m4 +++ /dev/null @@ -1,79 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later WITH Autoconf-exception-3.0 -# -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_cc_for_build.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CC_FOR_BUILD -# -# DESCRIPTION -# -# Find a build-time compiler. Sets CC_FOR_BUILD and EXEEXT_FOR_BUILD. -# -# LICENSE -# -# Copyright (c) 2010 Reuben Thomas -# Copyright (c) 1999 Richard Henderson -# -# 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 3 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, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 3 - -dnl Get a default for CC_FOR_BUILD to put into Makefile. -AC_DEFUN([AX_CC_FOR_BUILD], -[# Put a plausible default for CC_FOR_BUILD in Makefile. -if test -z "$CC_FOR_BUILD"; then - if test "x$cross_compiling" = "xno"; then - CC_FOR_BUILD='$(CC)' - else - CC_FOR_BUILD=gcc - fi -fi -AC_SUBST(CC_FOR_BUILD) -# Also set EXEEXT_FOR_BUILD. -if test "x$cross_compiling" = "xno"; then - EXEEXT_FOR_BUILD='$(EXEEXT)' -else - AC_CACHE_CHECK([for build system executable suffix], bfd_cv_build_exeext, - [rm -f conftest* - echo 'int main () { return 0; }' > conftest.c - bfd_cv_build_exeext= - ${CC_FOR_BUILD} -o conftest conftest.c 1>&5 2>&5 - for file in conftest.*; do - case $file in - *.c | *.o | *.obj | *.ilk | *.pdb) ;; - *) bfd_cv_build_exeext=`echo $file | sed -e s/conftest//` ;; - esac - done - rm -f conftest* - test x"${bfd_cv_build_exeext}" = x && bfd_cv_build_exeext=no]) - EXEEXT_FOR_BUILD="" - test x"${bfd_cv_build_exeext}" != xno && EXEEXT_FOR_BUILD=${bfd_cv_build_exeext} -fi -AC_SUBST(EXEEXT_FOR_BUILD)])dnl diff --git a/m4/ax_prog_cc_for_build.m4 b/m4/ax_prog_cc_for_build.m4 new file mode 100644 index 0000000000..efb80d40c4 --- /dev/null +++ b/m4/ax_prog_cc_for_build.m4 @@ -0,0 +1,157 @@ +# SPDX-License-Identifier: FSFAP +# +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_CC_FOR_BUILD +# +# DESCRIPTION +# +# This macro searches for a C compiler that generates native executables, +# that is a C compiler that surely is not a cross-compiler. This can be +# useful if you have to generate source code at compile-time like for +# example GCC does. +# +# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything +# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD). +# The value of these variables can be overridden by the user by specifying +# a compiler with an environment variable (like you do for standard CC). +# +# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object +# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if +# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are +# substituted in the Makefile. +# +# LICENSE +# +# Copyright (c) 2008 Paolo Bonzini +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 20 + +AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) +AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_CPP])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl + +dnl Use the standard macros, but make them use other variable names +dnl +pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl +pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl +pushdef([ac_cv_prog_cc_c99], ac_cv_build_prog_cc_c99)dnl +pushdef([ac_cv_prog_cc_c11], ac_cv_build_prog_cc_c11)dnl +pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl +pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl +pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl +pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl +pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl +pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl +pushdef([ac_cv_objext], ac_cv_build_objext)dnl +pushdef([ac_exeext], ac_build_exeext)dnl +pushdef([ac_objext], ac_build_objext)dnl +pushdef([CC], CC_FOR_BUILD)dnl +pushdef([CPP], CPP_FOR_BUILD)dnl +pushdef([GCC], GCC_FOR_BUILD)dnl +pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl +pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl +pushdef([EXEEXT], BUILD_EXEEXT)dnl +pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl +pushdef([OBJEXT], BUILD_OBJEXT)dnl +pushdef([host], build)dnl +pushdef([host_alias], build_alias)dnl +pushdef([host_cpu], build_cpu)dnl +pushdef([host_vendor], build_vendor)dnl +pushdef([host_os], build_os)dnl +pushdef([ac_cv_host], ac_cv_build)dnl +pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl +pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl +pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl +pushdef([ac_cv_host_os], ac_cv_build_os)dnl +pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl +pushdef([am_cv_CC_dependencies_compiler_type], am_cv_build_CC_dependencies_compiler_type)dnl +pushdef([am_cv_prog_cc_c_o], am_cv_build_prog_cc_c_o)dnl +pushdef([cross_compiling], cross_compiling_build)dnl + +cross_compiling_build=no + +ac_build_tool_prefix= +AS_IF([test -n "$build"], [ac_build_tool_prefix="$build-"], + [test -n "$build_alias"],[ac_build_tool_prefix="$build_alias-"]) + +AC_LANG_PUSH([C]) + +dnl The pushdef([ac_cv_c_compiler_gnu], ...) currently does not cover +dnl the use of this variable in _AC_LANG_COMPILER_GNU called by +dnl AC_PROG_CC. Unset this cache variable temporarily as a workaround. +was_set_ac_cv_c_compiler_gnu=${[ac_cv_c_compiler_gnu]+y} +AS_IF([test ${was_set_ac_cv_c_compiler_gnu}], + [saved_ac_cv_c_compiler_gnu=$[ac_cv_c_compiler_gnu] + AS_UNSET([[ac_cv_c_compiler_gnu]])]) + +AC_PROG_CC + +dnl Restore ac_cv_c_compiler_gnu +AS_IF([test ${was_set_ac_cv_c_compiler_gnu}], + [[ac_cv_c_compiler_gnu]=saved_ac_cv_c_compiler_gnu]) + +_AC_COMPILER_EXEEXT +_AC_COMPILER_OBJEXT +AC_PROG_CPP + +dnl Restore the old definitions +dnl +popdef([cross_compiling])dnl +popdef([am_cv_prog_cc_c_o])dnl +popdef([am_cv_CC_dependencies_compiler_type])dnl +popdef([ac_tool_prefix])dnl +popdef([ac_cv_host_os])dnl +popdef([ac_cv_host_vendor])dnl +popdef([ac_cv_host_cpu])dnl +popdef([ac_cv_host_alias])dnl +popdef([ac_cv_host])dnl +popdef([host_os])dnl +popdef([host_vendor])dnl +popdef([host_cpu])dnl +popdef([host_alias])dnl +popdef([host])dnl +popdef([OBJEXT])dnl +popdef([LDFLAGS])dnl +popdef([EXEEXT])dnl +popdef([CPPFLAGS])dnl +popdef([CFLAGS])dnl +popdef([GCC])dnl +popdef([CPP])dnl +popdef([CC])dnl +popdef([ac_objext])dnl +popdef([ac_exeext])dnl +popdef([ac_cv_objext])dnl +popdef([ac_cv_exeext])dnl +popdef([ac_cv_c_compiler_gnu])dnl +popdef([ac_cv_prog_cc_g])dnl +popdef([ac_cv_prog_cc_cross])dnl +popdef([ac_cv_prog_cc_works])dnl +popdef([ac_cv_prog_cc_c89])dnl +popdef([ac_cv_prog_gcc])dnl +popdef([ac_cv_prog_CPP])dnl + +dnl restore global variables ac_ext, ac_cpp, ac_compile, +dnl ac_link, ac_compiler_gnu (dependant on the current +dnl language after popping): +AC_LANG_POP([C]) + +dnl Finally, set Makefile variables +dnl +AC_SUBST(BUILD_EXEEXT)dnl +AC_SUBST(BUILD_OBJEXT)dnl +AC_SUBST([CFLAGS_FOR_BUILD])dnl +AC_SUBST([CPPFLAGS_FOR_BUILD])dnl +AC_SUBST([LDFLAGS_FOR_BUILD])dnl +])