Commit 9c4bef37 authored by Aaron Plattner's avatar Aaron Plattner

319.12

parents
This diff is collapsed.
#
# Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# include common variables and functions
##############################################################################
include utils.mk
##############################################################################
# assign variables
##############################################################################
NVIDIA_MODPROBE = $(OUTPUTDIR)/nvidia-modprobe
NVIDIA_MODPROBE_PROGRAM_NAME = "nvidia-modprobe"
NVIDIA_MODPROBE_VERSION := $(NVIDIA_VERSION)
MANPAGE_GZIP ?= 1
MANPAGE_not_gzipped = $(OUTPUTDIR)/nvidia-modprobe.1
MANPAGE_gzipped = $(OUTPUTDIR)/nvidia-modprobe.1.gz
ifeq ($(MANPAGE_GZIP),1)
MANPAGE = $(MANPAGE_gzipped)
else
MANPAGE = $(MANPAGE_not_gzipped)
endif
GEN_MANPAGE_OPTS = $(OUTPUTDIR)/gen-manpage-opts
OPTIONS_1_INC = $(OUTPUTDIR)/options.1.inc
##############################################################################
# The common-utils directory may be in one of two places: either
# elsewhere in the driver source tree when building nvidia-modprobe as
# part of the NVIDIA driver build (in which case, COMMON_UTILS_DIR
# should be defined by the calling makefile), or directly in the
# source directory when building from the nvidia-modprobe source
# tarball (in which case, the below conditional assignment should be
# used)
##############################################################################
COMMON_UTILS_DIR ?= common-utils
##############################################################################
# The modprobe-utils directory may be in one of two places: either
# elsewhere in the driver source tree when building as part of the
# NVIDIA driver build (in which case, MODPROBE_UTILS_DIR should be
# defined by the calling makefile), or directly in the source
# directory when building from source tarball (in which case, the
# below conditional assignment should be used)
##############################################################################
MODPROBE_UTILS_DIR ?= modprobe-utils
# include the list of source files; defines SRC
include dist-files.mk
SRC += $(STAMP_C)
include $(COMMON_UTILS_DIR)/src.mk
SRC += $(addprefix $(COMMON_UTILS_DIR)/,$(COMMON_UTILS_SRC))
include $(MODPROBE_UTILS_DIR)/nvidia-modprobe-utils.mk
SRC += $(addprefix $(MODPROBE_UTILS_DIR)/,$(MODPROBE_UTILS_SRC))
OBJS = $(call BUILD_OBJECT_LIST,$(SRC))
common_cflags += -I $(OUTPUTDIR)
common_cflags += -I $(COMMON_UTILS_DIR)
common_cflags += -I $(MODPROBE_UTILS_DIR)
common_cflags += -DPROGRAM_NAME=\"$(NVIDIA_MODPROBE_PROGRAM_NAME)\"
common_cflags += -D_BSD_SOURCE
common_cflags += -ansi
common_cflags += -pedantic
CFLAGS += $(common_cflags)
HOST_CFLAGS += $(common_cflags)
##############################################################################
# build rules
##############################################################################
.PNONY: all install NVIDIA_MODPROBE_install
.PHONY: MANPAGE_install clean clobber
all: $(NVIDIA_MODPROBE) $(MANPAGE)
install: NVIDIA_MODPROBE_install MANPAGE_install
NVIDIA_MODPROBE_install: $(NVIDIA_MODPROBE)
$(MKDIR) $(BINDIR)
$(INSTALL) $(INSTALL_BIN_ARGS) $< $(BINDIR)/$(notdir $<)
MANPAGE_install: $(MANPAGE)
$(MKDIR) $(MANDIR)
$(INSTALL) $(INSTALL_BIN_ARGS) $< $(MANDIR)/$(notdir $<)
$(NVIDIA_MODPROBE): $(OBJS)
$(call quiet_cmd,LINK) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ \
$(BIN_LDFLAGS)
$(call quiet_cmd,STRIP_CMD) $@
# define the rule to build each object file
$(foreach src,$(SRC),$(eval $(call DEFINE_OBJECT_RULE,TARGET,$(src))))
# define the rule to generate $(STAMP_C)
$(eval $(call DEFINE_STAMP_C_RULE, $(OBJS),$(NVIDIA_MODPROBE_PROGRAM_NAME)))
clean clobber:
rm -rf $(NVIDIA_MODPROBE) $(MANPAGE) *~ $(STAMP_C) \
$(OUTPUTDIR)/*.o $(OUTPUTDIR)/*.d \
$(GEN_MANPAGE_OPTS) $(OPTIONS_1_INC)
##############################################################################
# Documentation
##############################################################################
AUTO_TEXT = ".\\\" WARNING: THIS FILE IS AUTO-GENERATED! Edit $< instead."
doc: $(MANPAGE)
GEN_MANPAGE_OPTS_SRC = gen-manpage-opts.c
GEN_MANPAGE_OPTS_SRC += $(COMMON_UTILS_DIR)/gen-manpage-opts-helper.c
GEN_MANPAGE_OPTS_OBJS = $(call BUILD_OBJECT_LIST,$(GEN_MANPAGE_OPTS_SRC))
$(foreach src,$(GEN_MANPAGE_OPTS_SRC), \
$(eval $(call DEFINE_OBJECT_RULE,HOST,$(src))))
$(GEN_MANPAGE_OPTS): $(GEN_MANPAGE_OPTS_OBJS)
$(call quiet_cmd,HOST_LINK) \
$(HOST_CFLAGS) $(HOST_LDFLAGS) $(HOST_BIN_LDFLAGS) $^ -o $@
$(OPTIONS_1_INC): $(GEN_MANPAGE_OPTS)
@./$< > $@
$(MANPAGE_not_gzipped): nvidia-modprobe.1.m4 $(OPTIONS_1_INC) $(VERSION_MK)
$(call quiet_cmd,M4) -D__HEADER__=$(AUTO_TEXT) -I $(OUTPUTDIR) \
-D__VERSION__=$(NVIDIA_VERSION) \
-D__DATE__="`$(DATE) +%F`" \
-D__BUILD_OS__=$(TARGET_OS) \
$< > $@
$(MANPAGE_gzipped): $(MANPAGE_not_gzipped)
$(GZIP_CMD) -9f < $< > $@
This diff is collapsed.
/*
* Copyright (C) 2010-2012 NVIDIA Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses>.
*/
#ifndef __COMMON_UTILS_H__
#define __COMMON_UTILS_H__
#include <stdio.h>
#include <stdarg.h>
#if !defined(TRUE)
#define TRUE 1
#endif
#if !defined(FALSE)
#define FALSE 0
#endif
#define ARRAY_LEN(_arr) (sizeof(_arr) / sizeof(_arr[0]))
#define TAB " "
#define BIGTAB " "
#define VERBOSITY_NONE 0 /* nothing */
#define VERBOSITY_ERROR 1 /* errors only */
#define VERBOSITY_WARNING 2 /* errors and warnings */
#define VERBOSITY_ALL 3 /* errors, warnings and other info */
#define VERBOSITY_DEFAULT VERBOSITY_ERROR
/*
* Define a printf format attribute macro. This definition is based on the one
* from Xfuncproto.h, available in the 'xproto' package at
* http://xorg.freedesktop.org/releases/individual/proto/
*/
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
# define NV_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
#else /* not gcc >= 2.3 */
# define NV_ATTRIBUTE_PRINTF(x,y)
#endif
typedef struct {
char **t; /* the text rows */
int n; /* number of rows */
int m; /* maximum row length */
} TextRows;
void *nvalloc(size_t size);
char *nvstrcat(const char *str, ...);
void *nvrealloc(void *ptr, size_t size);
char *nvstrdup(const char *s);
char *nvstrndup(const char *s, size_t n);
char *nvstrtolower(char *s);
char *nvstrtoupper(char *s);
char *nvstrchrnul(char *s, int c);
char *nvasprintf(const char *fmt, ...) NV_ATTRIBUTE_PRINTF(1, 2);
void nvfree(void *s);
char *tilde_expansion(const char *str);
TextRows *nv_format_text_rows(const char *prefix,
const char *str,
int width, int word_boundary);
void nv_text_rows_append(TextRows *t, const char *msg);
void nv_concat_text_rows(TextRows *t0, TextRows *t1);
void nv_free_text_rows(TextRows *t);
void reset_current_terminal_width(unsigned short new_val);
void silence_fmt(int val);
void fmtout(const char *fmt, ...) NV_ATTRIBUTE_PRINTF(1, 2);
void fmtoutp(const char *prefix, const char *fmt, ...) NV_ATTRIBUTE_PRINTF(2, 3);
void fmterr(const char *fmt, ...) NV_ATTRIBUTE_PRINTF(1, 2);
void fmtwarn(const char *fmt, ...) NV_ATTRIBUTE_PRINTF(1, 2);
void fmt(FILE *stream, const char *prefix, const char *fmt, ...) NV_ATTRIBUTE_PRINTF(3, 4);
char *fget_next_line(FILE *fp, int *eof);
/*
* NV_VSNPRINTF(): macro that assigns buf using vsnprintf(). This is
* correct for differing semantics of the vsnprintf() return value:
*
* -1 when the buffer is not long enough (glibc < 2.1)
*
* or
*
* the length the string would have been if the buffer had been large
* enough (glibc >= 2.1)
*
* This macro allocates memory for buf; the caller should free it when
* done.
*/
#define NV_FMT_BUF_LEN 256
#define NV_VSNPRINTF(buf, fmt) \
do { \
if (!fmt) { \
(buf) = NULL; \
} else { \
va_list ap; \
int len, current_len = NV_FMT_BUF_LEN; \
\
while (1) { \
(buf) = nvalloc(current_len); \
\
va_start(ap, fmt); \
len = vsnprintf((buf), current_len, (fmt), ap); \
va_end(ap); \
\
if ((len > -1) && (len < current_len)) { \
break; \
} else if (len > -1) { \
current_len = len + 1; \
} else { \
current_len += NV_FMT_BUF_LEN; \
} \
\
nvfree(buf); \
} \
} \
} while (0)
#endif /* __COMMON_UTILS_H__ */
/*
* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "nvgetopt.h"
#include "gen-manpage-opts-helper.h"
static void print_option(const NVGetoptOption *o)
{
char scratch[64], *s;
int j, len;
int italics, bold, omitWhiteSpace;
/* if we are going to need the argument, process it now */
if (o->flags & NVGETOPT_HAS_ARGUMENT) {
if (o->arg_name) {
strcpy(scratch, o->arg_name);
} else {
len = strlen(o->name);
for (j = 0; j < len; j++) scratch[j] = toupper(o->name[j]);
scratch[len] = '\0';
}
}
printf(".TP\n.BI \"");
/* Print the name of the option */
/* XXX We should backslashify the '-' characters in o->name. */
if (isalpha(o->val)) {
/* '\-c' */
printf("\\-%c", o->val);
if (o->flags & NVGETOPT_HAS_ARGUMENT) {
/* ' " "ARG" "' */
printf(" \" \"%s\" \"", scratch);
}
/* ', ' */
printf(", ");
}
/* '\-\-name' */
printf("\\-\\-%s", o->name);
/* '=" "ARG' */
if (o->flags & NVGETOPT_HAS_ARGUMENT) {
printf("=\" \"%s", scratch);
/* '" "' */
if ((o->flags & NVGETOPT_IS_BOOLEAN) ||
(o->flags & NVGETOPT_ALLOW_DISABLE)) {
printf("\" \"");
}
}
/* ', \-\-no\-name' */
if (((o->flags & NVGETOPT_IS_BOOLEAN) &&
!(o->flags & NVGETOPT_HAS_ARGUMENT)) ||
(o->flags & NVGETOPT_ALLOW_DISABLE)) {
printf(", \\-\\-no\\-%s", o->name);
}
printf("\"\n");
/* Print the option description */
/* XXX Each sentence should be on its own line! */
/*
* Print the option description: write each character one at a
* time (ugh) so that we can special-case a few characters:
*
* '&' : toggles italics on and off
* '^' : toggles bold on and off
* '-' : is backslashified: "\-"
*
* Whitespace is omited when italics or bold is on
*/
italics = 0;
bold = 0;
omitWhiteSpace = 0;
for (s = o->description; s && *s; s++) {
switch (*s) {
case '&':
if (italics) {
printf("\n");
} else {
printf("\n.I ");
}
omitWhiteSpace = italics;
italics = !italics;
break;
case '^':
if (bold) {
printf("\n");
} else {
printf("\n.B ");
}
omitWhiteSpace = bold;
bold = !bold;
break;
case '-':
printf("\\-");
omitWhiteSpace = 0;
break;
case ' ':
if (!omitWhiteSpace) {
printf(" ");
}
break;
default:
printf("%c", *s);
omitWhiteSpace = 0;
break;
}
}
printf("\n");
}
void gen_manpage_opts_helper(const NVGetoptOption *options)
{
int i;
int has_advanced_options = 0;
/* Print the "simple" options; i.e. the ones you get with --help. */
printf(".SH OPTIONS\n");
for (i = 0; options[i].name; i++) {
const NVGetoptOption *o = &options[i];
if (!o->description) {
continue;
}
if (!(o->flags & NVGETOPT_HELP_ALWAYS)) {
has_advanced_options = 1;
continue;
}
print_option(o);
}
if (has_advanced_options) {
/*
* If any exist, print the advanced options; i.e., the ones
* you get with --advanced-help
*/
printf(".SH \"ADVANCED OPTIONS\"\n");
for (i = 0; options[i].name; i++) {
const NVGetoptOption *o = &options[i];
if (!o->description) {
continue;
}
if (o->flags & NVGETOPT_HELP_ALWAYS) {
continue;
}
print_option(o);
}
}
}
/*
* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
#if !defined(__GEN_MANPAGE_OPTS_HELPER_H__)
#define __GEN_MANPAGE_OPTS_HELPER_H__
#include "nvgetopt.h"
void gen_manpage_opts_helper(const NVGetoptOption *options);
#endif /* __GEN_MANPAGE_OPTS_HELPER_H__ */
This diff is collapsed.
/*
* Copyright (C) 2004-2010 NVIDIA Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses>.
*
*
* nvgetopt.h
*/
#ifndef __NVGETOPT_H__
#define __NVGETOPT_H__
#define NVGETOPT_FALSE 0
#define NVGETOPT_TRUE 1
/*
* mask of bits not used by nvgetopt in NVGetoptOption::flags;
* these bits are available for use within specific users of
* nvgetopt
*/
#define NVGETOPT_UNUSED_FLAG_RANGE 0xffff0000
/*
* indicates that the option is a boolean value; the presence of the
* option will be interpretted as a TRUE value; if the option is
* prepended with '--no-', the option will be interpretted as a FALSE
* value. On success, nvgetopt will return the parsed boolean value
* through 'boolval'.
*/
#define NVGETOPT_IS_BOOLEAN 0x01
/*
* indicates that the option takes an argument to be interpreted as a
* string; on success, nvgetopt will return the parsed string argument
* through 'strval'.
*/
#define NVGETOPT_STRING_ARGUMENT 0x02
/*
* indicates that the option takes an argument to be interpreted as an
* integer; on success, nvgetopt will return the parsed integer
* argument through 'intval'.
*/
#define NVGETOPT_INTEGER_ARGUMENT 0x04
/*
* indicates that the option takes an argument to be interpreted as
* an double; on success, nvgetopt will return the parsed double
* argument through 'doubleval'.
*/
#define NVGETOPT_DOUBLE_ARGUMENT 0x08
/* helper macro */
#define NVGETOPT_HAS_ARGUMENT (NVGETOPT_STRING_ARGUMENT | \
NVGETOPT_INTEGER_ARGUMENT | \
NVGETOPT_DOUBLE_ARGUMENT)
/*
* indicates that the option, which normally takes an argument, can be
* disabled if the option is prepended with '--no-', in which case,
* the option does not take an argument. If the option is disabled,
* nvgetopt will return TRUE through 'disable_val'.
*
* Note that NVGETOPT_ALLOW_DISABLE can only be used with options that
* take arguments.
*/
#define NVGETOPT_ALLOW_DISABLE 0x10
/*
* indicates that the argument for this option is optional; if no
* argument is present (either the option is already at the end of the
* argv array, or the next option in argv starts with '-'), then the
* option is returned without an argument.
*/
#define NVGETOPT_ARGUMENT_IS_OPTIONAL 0x20
/*
* The NVGETOPT_HELP_ALWAYS flag is not used by nvgetopt() itself, but
* is often used by other users of NVGetoptOption tables, who print
* out basic and advanced help. In such cases, OPTION_HELP_ALWAYS is
* used to indicate that the help for the option should always be
* printed.
*/
#define NVGETOPT_HELP_ALWAYS 0x40
typedef struct {
const char *name;
int val;
unsigned int flags;
char *arg_name; /* not used by nvgetopt() */
char *description; /* not used by nvgetopt() */
} NVGetoptOption;
/*
* nvgetopt() - see the glibc getopt_long(3) manpage for usage
* description. Options can be prepended with "--", "-", or "--no-".
*
* A global variable stores the current index into the argv array, so
* subsequent calls to nvgetopt() will advance through argv[].
*
* On success, the matching NVGetoptOption.val is returned.
*
* If the NVGETOPT_IS_BOOLEAN flag is set, boolval will be set to TRUE
* (or FALSE, if the option string was prepended with "--no-").
*
* disable_val will be assigned TRUE if the option string was
* prepended with "--no-", otherwise it will be assigned FALSE.
*
* If an argument is successfully parsed, one of strval, intval, or
* doubleval will be assigned, based on which of
* NVGETOPT_STRING_ARGUMENT, NVGETOPT_INTEGER_ARGUMENT, or
* NVGETOPT_DOUBLE_ARGUMENT is set in the option's flags. If strval
* is assigned to a non-NULL value by nvgetopt, then it is the
* caller's responsibility to free the string when done with it.
*
* On failure, an error is printed to stderr, and 0 is returned.
*
* When there are no more options to parse, -1 is returned.
*/
int nvgetopt(int argc,
char *argv[],
const NVGetoptOption *options,
char **strval,
int *boolval,
int *intval,
double *doubleval,
int *disable_val);
/*
* nvgetopt_print_help() - print a help message for each option in the
* provided NVGetoptOption array. This is useful for a utility's
* "--help" output.
*
* Options will only be printed if they have every bit set that
* include_mask includes.
*
* For each option, the provided callback function wil be called with
* two strings: a name string that lists the option's name, and a
* description string for the option. The callback function is
* responsible for actually printing these strings. Examples:
*
* name = "-v, --version";
* description = "Print usage information for the common commandline "
* "options and exit.";
*/
typedef void nvgetopt_print_help_callback_ptr(const char *name,
const char *description);
void nvgetopt_print_help(const NVGetoptOption *options,
unsigned int include_mask,
nvgetopt_print_help_callback_ptr callback);
#endif /* __NVGETOPT_H__ */
# makefile fragment included by nvidia-xconfig, nvidia-settings, and nvidia-installer
COMMON_UTILS_SRC += nvgetopt.c
COMMON_UTILS_SRC += common-utils.c
COMMON_UTILS_EXTRA_DIST += nvgetopt.h
COMMON_UTILS_EXTRA_DIST += common-utils.h
COMMON_UTILS_EXTRA_DIST += src.mk
# gen-manpage-opts-helper.c is listed in EXTRA_DIST, rather than SRC,
# because it is not compiled into the utilities themselves, but used
# when building the utility's gen-manpage-opts
COMMON_UTILS_EXTRA_DIST += gen-manpage-opts-helper.c
COMMON_UTILS_EXTRA_DIST += gen-manpage-opts-helper.h
SRC += nvidia-modprobe.c
DIST_FILES := $(SRC)
DIST_FILES += COPYING
DIST_FILES += dist-files.mk
DIST_FILES += option-table.h
DIST_FILES += nvidia-modprobe.1.m4
DIST_FILES += gen-manpage-opts.c
/*
* Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "gen-manpage-opts-helper.h"
#include "option-table.h"
int main(int argc, char* argv[])
{
gen_manpage_opts_helper(__options);
return 0;
}