346.16

parent 08718cd3
......@@ -522,6 +522,68 @@ char *nv_basename(const char *path)
}
/*
* nv_mkdir_recursive() - make a directory and all parent directories as needed.
* dir_list is an optional arguments that if not empty, will be set to a string
* containing a newline separated list of all directories created.
*/
int nv_mkdir_recursive(const char *path, const mode_t mode,
char **error_str, char **dir_list)
{
char *c, *tmp, ch, *list;
int success = FALSE;
if (!path || !path[0]) {
return FALSE;
}
tmp = nvstrdup(path);
remove_trailing_slashes(tmp);
list = NULL;
c = tmp;
do {
c++;
if ((*c == '/') || (*c == '\0')) {
ch = *c;
*c = '\0';
if (!directory_exists(tmp)) {
char *tmplist;
if (mkdir(tmp, mode) != 0) {
*error_str =
nvasprintf("Failure creating directory '%s' : (%s)",
tmp, strerror(errno));
goto done;
}
/* Prepend the created directory path to a running list */
if (dir_list) {
tmplist = list;
list = nvstrcat(tmp, "\n", tmplist, NULL);
free(tmplist);
}
}
*c = ch;
}
} while (*c);
/* Log any created directories */
if (dir_list && list) {
*dir_list = list;
}
success = TRUE;
done:
if (!dir_list) {
free(list);
}
free(tmp);
return success;
}
/****************************************************************************/
/* string helper functions */
/****************************************************************************/
......@@ -611,3 +673,39 @@ char *nv_trim_char_strict(char *string, char trim) {
return NULL;
}
/*
* directory_exists() - test whether the given directory exists
*/
int directory_exists(const char *dir)
{
struct stat stat_buf;
if ((stat (dir, &stat_buf) == -1) || (!S_ISDIR(stat_buf.st_mode))) {
return FALSE;
} else {
return TRUE;
}
}
/*
* remove_trailing_slashes() - begin at the end of the given string,
* and overwrite slashes with NULL as long as we find slashes.
*/
void remove_trailing_slashes(char *string)
{
int len;
if (string == NULL) {
return;
}
len = strlen(string);
while (string[len-1] == '/') {
string[--len] = '\0';
}
}
......@@ -62,10 +62,15 @@ int nv_get_file_length(const char *filename);
void nv_set_file_length(const char *filename, int fd, int len);
void *nv_mmap(const char *filename, size_t len, int prot, int flags, int fd);
char *nv_basename(const char *path);
int nv_mkdir_recursive(const char *path, const mode_t mode,
char **error_str, char **log_str);
char *nv_trim_space(char *string);
char *nv_trim_char(char *string, char trim);
char *nv_trim_char_strict(char *string, char trim);
void remove_trailing_slashes(char *string);
int directory_exists(const char *dir);
#if defined(__GNUC__)
# define NV_INLINE __inline__
......
......@@ -42,6 +42,7 @@ int nvgetopt(int argc,
int ret = 0;
int negate = NVGETOPT_FALSE;
int disable = NVGETOPT_FALSE;
int double_dash = NVGETOPT_FALSE;
const NVGetoptOption *o = NULL;
static int argv_index = 0;
......@@ -65,6 +66,7 @@ int nvgetopt(int argc,
if ((arg[0] == '-') && (arg[1] == '-')) {
name = arg + 2;
double_dash = NVGETOPT_TRUE;
} else if (arg[0] == '-') {
name = arg + 1;
} else {
......@@ -80,16 +82,26 @@ int nvgetopt(int argc,
c = name;
while (*c) {
if (*c == '=') { argument = c + 1; *c = '\0'; break; }
if (*c == '=') {
argument = c + 1;
*c = '\0';
break;
}
c++;
}
/*
* if there is no character after '--' then stop processing options.
* if the string is terminated after one character, interpret it
* as a short option. Otherwise, interpret it as a long option.
*/
if (name[1] == '\0') { /* short option */
if (name[0] == '\0') {
if (double_dash && argument == NULL) { /* option list terminator */
ret = -1;
goto done;
}
} else if (name[1] == '\0') { /* short option */
for (i = 0; options[i].name; i++) {
if (options[i].val == name[0]) {
o = &options[i];
......
......@@ -55,6 +55,7 @@ endif
INSTALL ?= install
INSTALL_BIN_ARGS ?= -m 755
INSTALL_LIB_ARGS ?= -m 644
INSTALL_DOC_ARGS ?= -m 644
M4 ?= m4
......@@ -98,6 +99,26 @@ ifndef TARGET_ARCH
TARGET_ARCH := $(subst i686,x86,$(TARGET_ARCH))
endif
ifeq ($(TARGET_ARCH),x86)
CFLAGS += -DNV_X86 -DNV_ARCH_BITS=32
endif
ifeq ($(TARGET_ARCH),x86_64)
CFLAGS += -DNV_X86_64 -DNV_ARCH_BITS=64
endif
ifeq ($(TARGET_ARCH),armv7l)
CFLAGS += -DNV_ARMV7 -DNV_ARCH_BITS=32
endif
ifeq ($(TARGET_ARCH),aarch64)
CFLAGS += -DNV_AARCH64 -DNV_ARCH_BITS=64
endif
ifeq ($(TARGET_ARCH),ppc64le)
CFLAGS += -DNV_PPC64LE -DNV_ARCH_BITS=64
endif
ifeq ($(TARGET_OS),Linux)
LIBDL_LIBS = -ldl
else
......@@ -113,6 +134,14 @@ ifeq ($(TARGET_ARCH),armv7l)
endif
TARGET_ARCH_ABI ?=
ifeq ($(TARGET_ARCH_ABI),gnueabi)
CFLAGS += -DNV_GNUEABI
endif
ifeq ($(TARGET_ARCH_ABI),gnueabihf)
CFLAGS += -DNV_GNUEABIHF
endif
OUTPUTDIR ?= _out/$(TARGET_OS)_$(TARGET_ARCH)
OUTPUTDIR_ABSOLUTE ?= $(CURDIR)/$(OUTPUTDIR)
......@@ -143,6 +172,7 @@ endif
PREFIX ?= /usr/local
BINDIR = $(DESTDIR)$(PREFIX)/bin
LIBDIR = $(DESTDIR)$(PREFIX)/lib
MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1
......@@ -230,7 +260,7 @@ NV_MODULE_LOGGING_NAME ?=
ifeq ($(NV_VERBOSE),0)
quiet_cmd = @$(PRINTF) \
" $(if $(NV_MODULE_LOGGING_NAME),[ %-17.17s ],%s) $(quiet_$(1))\n" \
" $(if $(NV_MODULE_LOGGING_NAME),[ %-17.17s ],%s) $(quiet_$(1))\n" \
"$(NV_MODULE_LOGGING_NAME)" && $($(1))
else
quiet_cmd = $($(1))
......@@ -262,32 +292,49 @@ quiet_STRIP_CMD = $(call define_quiet_cmd,STRIP ,$@)
##############################################################################
# function to generate a list of object files from their corresponding
# source files; example usage:
# source files using the specified path. The _WITH_DIR variant takes an
# output path as the second argument while the BUILD_OBJECT_LIST defaults
# to using the value of OUTPUTDIR as the output path. example usage:
#
# OBJS = $(call BUILD_OBJECT_LIST,$(SRC))
# OBJS = $(call BUILD_OBJECT_LIST_WITH_DIR,$(SRC),$(DIR))
##############################################################################
BUILD_OBJECT_LIST_WITH_DIR = \
$(addprefix $(2)/,$(notdir $(addsuffix .o,$(basename $(1)))))
BUILD_OBJECT_LIST = \
$(addprefix $(OUTPUTDIR)/,$(notdir $(addsuffix .o,$(basename $(1)))))
$(call BUILD_OBJECT_LIST_WITH_DIR,$(1),$(OUTPUTDIR))
##############################################################################
# function to generate a list of dependency files from their
# corresponding source files; example usage:
# corresponding source files using the specified path. The _WITH_DIR
# variant takes an output path as the second argument while the
# BUILD_DEPENDENCY_LIST default to using the value of OUTPUTDIR as the
# output path. example usage:
#
# DEPS = $(call BUILD_DEPENDENCY_LIST,$(SRC))
# DEPS = $(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(SRC),$(DIR))
##############################################################################
BUILD_DEPENDENCY_LIST_WITH_DIR = \
$(addprefix $(2)/,$(notdir $(addsuffix .d,$(basename $(1)))))
BUILD_DEPENDENCY_LIST = \
$(addprefix $(OUTPUTDIR)/,$(notdir $(addsuffix .d,$(basename $(1)))))
$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(1),$(OUTPUTDIR))
##############################################################################
# functions to define a rule to build an object file; the first
# argument whether the rule is for the target or host platform ("HOST"
# or "TARGET"), the second argument is the source file to compile, and
# the third argument (_WITH_OBJECT_NAME-only) is the object filename
# to produce. Example usage:
# argument for all functions is whether the rule is for the target or
# host platform ("HOST" or "TARGET"), the second argument for all
# functions is the source file to compile.
#
# The _WITH_OBJECT_NAME and _WITH_DIR function name suffixes describe
# the third and possibly fourth arguments based on order. The
# _WITH_OBJECT_NAME argument is the object filename to produce while
# the _WITH_DIR argument is the destination path for the object file.
#
# Example usage:
#
# $(eval $(call DEFINE_OBJECT_RULE,TARGET,foo.c))
#
......@@ -299,26 +346,35 @@ BUILD_DEPENDENCY_LIST = \
# from the source file name (this is normally what you want).
##############################################################################
define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME
define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR
$(3): $(2)
@$(MKDIR) $(OUTPUTDIR)
@$(MKDIR) $(4)
$$(call quiet_cmd,$(call host_target_cc,$(1))) \
$$($(call host_target_cflags,$(1))) -c $$< -o $$@ \
$(call AUTO_DEP_CMD,$(1),$(2),$(3))
-include $$(call BUILD_DEPENDENCY_LIST,$(3))
-include $$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4))
# declare empty rule for generating dependency file; we generate the
# dependency files implicitly when compiling the source file (see
# AUTO_DEP_CMD above), so we don't want gmake to spend time searching
# for an explicit rule to generate the dependency file
$$(call BUILD_DEPENDENCY_LIST,$(3)): ;
$$(call BUILD_DEPENDENCY_LIST_WITH_DIR,$(3),$(4)): ;
endef
define DEFINE_OBJECT_RULE_WITH_OBJECT_NAME
$$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\
$(3),$(OUTPUTDIR)))
endef
define DEFINE_OBJECT_RULE_WITH_DIR
$$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME_WITH_DIR,$(1),$(2),\
$$(call BUILD_OBJECT_LIST_WITH_DIR,$(2),$(3)),$(3)))
endef
define DEFINE_OBJECT_RULE
$$(eval $$(call DEFINE_OBJECT_RULE_WITH_OBJECT_NAME,$(1),$(2),\
$$(call BUILD_OBJECT_LIST,$(2))))
$$(eval $$(call DEFINE_OBJECT_RULE_WITH_DIR,$(1),$(2),$(OUTPUTDIR)))
endef
......
NVIDIA_VERSION = 343.22
NVIDIA_VERSION = 346.16
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment