diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | make.c | 27 |
2 files changed, 27 insertions, 3 deletions
@@ -12,7 +12,8 @@ There are a few restrictions: - Only one target per source tree: a binary (identified by the source file containing main(), which will have the same basename without .c), or a - library (identified by the MAJE_LIB flag (see below). + library (identified by the MAJE_LIB flag (see below), or the current + directory name if MAJE_LIB is not specified). Usage ===== @@ -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); |