summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-25 20:27:40 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-25 20:27:40 -0400
commitb976d797b09e9f9ff212da91c2c6b552596542bc (patch)
treec704eb6ac9a484a4bf568dace3d355b265357c0b
parentb56ccbec6f7ba64a7d2d7770123e8d4127789004 (diff)
use the current directory name for libraries if none is specifiedmaje
-rw-r--r--README.md3
-rw-r--r--make.c27
2 files changed, 27 insertions, 3 deletions
diff --git a/README.md b/README.md
index b9e9f4f..36c12ec 100644
--- a/README.md
+++ b/README.md
@@ -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
=====
diff --git a/make.c b/make.c
index 80c2eba..9a2e61e 100644
--- a/make.c
+++ b/make.c
@@ -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);