commit: e130be699a76758f5642efc2659bb6e0c7ebc099
parent: b117e65252d79f88e68087d2d5e4480b3d86c432
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 6 May 2020 07:55:58 +0200
Move from mkfile to Makefile
Diffstat:
13 files changed, 61 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,8 @@
+all:
+ cd bin ; $(MAKE)
+
+clean:
+ cd bin ; $(MAKE) clean
+
+install:
+ cd bin ; $(MAKE) install
diff --git a/Makefile.common b/Makefile.common
@@ -0,0 +1,35 @@
+# POSIX-ish Makefile with extensions common to *BSD and GNU such as:
+# - Usage of backticks for shell evaluation
+# - Usage of ?= for defining variables when not already defined
+# - Usage of += for appending to a variable
+
+PREFIX ?= /usr/local
+BINDIR = $(PREFIX)/bin
+MANDIR = $(PREFIX)/share/man
+DOCDIR = $(PREFIX)/share/doc/lanodan-utils
+DATADIR = $(PREFIX)/share/lanodan-utils
+APPSDIR = $(PREFIX)/share/applications
+
+CC ?= cc
+CFLAGS ?= -g -Wall -Wextra -Wconversion -Wsign-conversion -O2
+LDFLAGS ?= -Wl,--as-needed
+MSGFMT ?= msgfmt
+
+all: $(EXE)
+
+.PHONY: Makefile.config
+Makefile.config:
+ ../gen-Makefile.config > Makefile.config
+
+.PHONY: test
+test: $(EXE_test)
+
+.c:
+ $(CC) -std=c11 $(CFLAGS) $(LDFLAGS) -o $@ $< -lm
+
+.c.o:
+ $(CC) -std=c11 $(CFLAGS) -c -o $@ $<
+
+.PHONY: clean
+clean:
+ rm -fr $(OBJS) $(OBJS_test) $(EXE) $(EXE_test)
diff --git a/bin/Makefile b/bin/Makefile
@@ -0,0 +1,7 @@
+# POSIX-ish Makefile with extensions common to *BSD and GNU such as:
+# - Usage of backticks for shell evaluation
+# - Usage of ?= for defining variables when not already defined
+# - Usage of += for appending to a variable
+
+include Makefile.config
+include ../Makefile.common
diff --git a/bin/args.c b/bin/args.c
@@ -1,5 +1,6 @@
// Copyright CC-BY-SA-4.0 2017- Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+#define _POSIX_C_SOURCE 200809L
// printf()
#include <stdio.h>
diff --git a/bin/date.c b/bin/date.c
@@ -1,4 +1,5 @@
/* Copyright CC-BY-SA-4.0 2017-2020 Haelwenn (lanodan) Monnier <contact@hacktivis.me> */
+#define _POSIX_C_SOURCE 200809L
#include <locale.h> /* setlocale() */
#include <stdio.h> /* BUFSIZ, perror(), puts() */
#include <stdlib.h> /* exit() */
@@ -11,7 +12,7 @@ int main(int argc, char *argv[])
struct tm *tm;
time_t now = time(NULL);
char *format = "%c";
- int uflag = 0, dflag = 0;
+ int uflag = 0;
int c;
setlocale(LC_ALL, "");
diff --git a/bin/echo.c b/bin/echo.c
@@ -1,6 +1,7 @@
// Copyright 2020 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// Distributed under the terms of the CC-BY-SA-4.0 license
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h> /* printf(), putchar() */
// Note: maybe consider buffering to write(2) only once like in Plan9
diff --git a/bin/lolcat.c b/bin/lolcat.c
@@ -1,6 +1,7 @@
// Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// Distributed under the terms of the CC-BY-SA-4.0 license
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h> /* getchar(), putchar(), snprintf(), printf() */
#include <math.h> /* sin() */
diff --git a/bin/pwd.c b/bin/pwd.c
@@ -1,6 +1,7 @@
// Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// Distributed under the terms of the CC-BY-SA-4.0 license
+#define _POSIX_C_SOURCE 200809L
#include <errno.h> /* errno */
#include <stdio.h> /* puts, perror, printf */
#include <stdlib.h> /* exit */
diff --git a/bin/range.c b/bin/range.c
@@ -1,5 +1,6 @@
// Copyright CC-BY-SA-4.0 2017- Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
diff --git a/bin/sizeof.c b/bin/sizeof.c
@@ -1,3 +1,4 @@
+#define _POSIX_C_SOURCE 200809L
#if __OpenBSD__
#include <stdlib.h>
#else
diff --git a/bin/xcd.c b/bin/xcd.c
@@ -1,6 +1,7 @@
// Copyright 2018-2020 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// Distributed under the terms of the CC-BY-SA-4.0 license
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h> /* printf(), fread() */
#include <math.h> /* sin() */
#include <stdint.h> /* uint8_t */
diff --git a/gen-Makefile.config b/gen-Makefile.config
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo 'EXE = '$(ls -d *.c | sed 's;\b\.c\b;;g')
diff --git a/mkfile b/mkfile
@@ -1,32 +0,0 @@
-MKSHELL=/bin/sh
-CC=cc
-CDEFS="-D_POSIX_C_SOURCE=200809L -D_C99_SOURCE"
-CFLAGS="-Wpedantic -Wall -Wextra -Wformat -O2 -std=c99 -Wno-unused -Werror=date-time -D_POSIX_C_SOURCE=200809L"
-PREFIX="/usr/local"
-BINDIR=$PREFIX"/bin"
-DOCDIR=$PREFIX"/share/doc/lanodan-utils"
-MANDIR=$PREFIX"/share/man"
-
-bins=`ls -d *bin/*.c | sed 's;\.c$;;'`
-
-all:V: $bins
-
-install:V: all
- mkdir -p $DESTDIR$BINDIR/
- for bin in $bins; do cp $bin $DESTDIR$BINDIR/; done
- mkdir -p $DESTDIR$DOCDIR/
- for doc in doc/*; do cp $doc $DESTDIR$DOCDIR/; done
- mkdir -p $DESTDIR$MANDIR/
- for man in *bin/*.[1-9]; do cp $man $DESTDIR$MANDIR/man${man: -1}/; done
-
-clean:V:
- rm -f $bins
-
-bin/&: bin/&.c
- $CC $CDEFS $CFLAGS bin/$stem.c -o bin/$stem
-
-bin/lolcat: bin/lolcat.c
- $CC $CDEFS $CFLAGS -lm bin/lolcat.c -o bin/lolcat
-
-bin/xcd: bin/xcd.c
- $CC $CDEFS $CFLAGS -lm bin/xcd.c -o bin/xcd