diff options
Diffstat (limited to 'make.c')
-rw-r--r-- | make.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -1,11 +1,21 @@ #define _XOPEN_SOURCE 700 #include <libgen.h> +#include <limits.h> #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include "maje.h" +#ifndef PATH_MAX +#ifdef _XOPEN_PATH_MAX +#define PATH_MAX _XOPEN_PATH_MAX +#else +#define PATH_MAX _POSIX_PATH_MAX +#endif +#endif + static void make_header(FILE *makefile, const char *target, struct majeflag *flags, int lib) { fprintf(makefile, ".POSIX:\n\n"); @@ -91,6 +101,16 @@ static void add_object(FILE *makefile, const struct majefile *src, const char *t free(fullobj); } +static char *cwd_basename(void) +{ + static char path[PATH_MAX]; + if (getcwd(path, sizeof(path)) == NULL) { + return NULL; + } + + return basename(path); +} + void make_makefile(const char *makepath, struct majefile *sources, const char *target) { FILE *makefile = fopen(makepath, "w"); @@ -119,8 +139,11 @@ void make_makefile(const char *makepath, struct majefile *sources, const char *t } if (lib == 1 && target == NULL) { - fprintf(stderr, "maje: couldn't determine binary or library name\n"); - exit(1); + target = cwd_basename(); + if (target == NULL) { + fprintf(stderr, "maje: couldn't determine binary or library name\n"); + exit(1); + } } make_header(makefile, target, flags, lib); |