This feature is apparently assumed by MSBUILD.
Contributed (with minor modifications) by: Brian Gladman
svn path=/trunk/yasm/; revision=2287
# Checks for header files.
#
AC_HEADER_STDC
-AC_CHECK_HEADERS([strings.h libgen.h unistd.h direct.h])
+AC_CHECK_HEADERS([strings.h libgen.h unistd.h direct.h sys/stat.h])
# REQUIRE standard C headers
if test "$ac_cv_header_stdc" != yes; then
#include "license.c"
/*@null@*/ /*@only@*/ static char *objdir_pathname = NULL;
-/*@null@*/ /*@only@*/ static char *global_prefix = NULL, *global_suffix = NULL;
+/*@null@*/ /*@only@*/ static char *global_prefix = NULL, *global_suffix =
+NULL;
/*@null@*/ /*@only@*/ static char *listdir_pathname = NULL;
/*@null@*/ /*@only@*/ static char *mapdir_pathname = NULL;
/*@null@*/ /*@only@*/ static char *machine_name = NULL;
/* If not already specified, output to the current directory. */
if (!objdir_pathname)
objdir_pathname = yasm__xstrdup("./");
+ else if((i = yasm__createpath(objdir_pathname)) > 0) {
+ objdir_pathname[i] = '/';
+ objdir_pathname[i+1] = '\0';
+ }
+
+ /* Create other output directories if necessary */
+ if (listdir_pathname && (i = yasm__createpath(listdir_pathname)) > 0) {
+ listdir_pathname[i] = '/';
+ listdir_pathname[i+1] = '\0';
+ }
+ if (mapdir_pathname && (i = yasm__createpath(mapdir_pathname)) > 0) {
+ mapdir_pathname[i] = '/';
+ mapdir_pathname[i+1] = '\0';
+ }
/* Assemble each input file. Terminate on first error. */
STAILQ_FOREACH(infile, &input_files, link)
assert(param != NULL);
listdir_pathname = yasm_xmalloc(strlen(param)+2);
strcpy(listdir_pathname, param);
- strcat(listdir_pathname, "/");
return 0;
}
assert(param != NULL);
objdir_pathname = yasm_xmalloc(strlen(param)+2);
strcpy(objdir_pathname, param);
- strcat(objdir_pathname, "/");
return 0;
}
assert(param != NULL);
mapdir_pathname = yasm_xmalloc(strlen(param)+2);
strcpy(mapdir_pathname, param);
- strcat(mapdir_pathname, "/");
return 0;
}
#include <direct.h>
#endif
+#ifdef _WIN32
+#include <io.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
#include <ctype.h>
#include <errno.h>
return out;
}
+size_t
+yasm__createpath_common(const char *path, int win)
+{
+ const char *pp = path, *pe;
+ char *ts, *tp;
+ size_t len, lth;
+
+ lth = len = strlen(path);
+ ts = tp = (char *) malloc(len + 1);
+ pe = pp + len;
+ while (pe > pp) {
+ if ((win && *pe == '\\') || *pe == '/')
+ break;
+ --pe;
+ --lth;
+ }
+
+ while (pp <= pe) {
+ if (pp == pe || (win && *pp == '\\') || *pp == '/') {
+#ifdef _WIN32
+ struct _finddata_t fi;
+ intptr_t h;
+#elif defined(HAVE_SYS_STAT_H)
+ struct stat fi;
+#endif
+ *tp = '\0';
+
+#ifdef _WIN32
+ h = _findfirst(ts, &fi);
+ if (h != -1) {
+ if (fi.attrib != _A_SUBDIR) {
+ _findclose(h);
+ break;
+ }
+ } else if (errno == ENOENT) {
+ if (_mkdir(ts) == -1) {
+ _findclose(h);
+ lth = -1;
+ break;
+ }
+ }
+ _findclose(h);
+#elif defined(HAVE_SYS_STAT_H)
+ if (stat(ts, &fi) != -1) {
+ if (!S_ISDIR(fi.st_mode))
+ break;
+ } else if (errno == ENOENT) {
+ if (mkdir(ts, 0755) == -1) {
+ lth = 0;
+ break;
+ }
+ }
+#else
+ break;
+#endif
+ }
+ *tp++ = *pp++;
+ }
+ free(ts);
+ return lth;
+}
+
typedef struct incpath {
STAILQ_ENTRY(incpath) link;
/*@owned@*/ char *path;
# endif
#endif
+/** Recursively create tree of directories needed for pathname.
+ * \internal
+ * \param path pathname
+ * \param win handle windows paths
+ * \return Length of directory portion of pathname.
+ */
+YASM_LIB_DECL
+size_t yasm__createpath_common(const char *path, int win);
+
+/** Recursively create tree of directories needed for pathname.
+ * Unless otherwise defined, defaults to yasm__createpath_unix().
+ * \internal
+ * \param path pathname
+ * \return Length of directory portion of pathname.
+ */
+#ifndef yasm__createpath
+# if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
+ defined (__DJGPP__) || defined (__OS2__)
+# define yasm__createpath(path) yasm__createpath_common(path, 1)
+# else
+# define yasm__createpath(path) yasm__createpath_common(path, 0)
+# endif
+#endif
+
/** Try to find and open an include file, searching through include paths.
* First iname is looked for relative to the directory containing "from", then
* it's looked for relative to each of the include paths.