commit b2ce67c0b5d5c2e1d336858b6c18cdffa746045b
parent 09f76348c7262c0af259ea58f2cf14ab97473c20
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Mon, 5 Dec 2022 17:53:31 +0000
Add support for building with tup
For more info: https://gittup.org/tup/
Diffstat:
M | .gitignore | | | 45 | ++++++++++++++++++++++++++++++++++++++++----- |
A | Tupfile | | | 15 | +++++++++++++++ |
A | Tupfile.ini | | | 0 | |
D | src/aio.cpp | | | 80 | ------------------------------------------------------------------------------- |
4 files changed, 55 insertions(+), 85 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,5 +1,40 @@
-*
-
-!*.*
-!*/
-!makefile
+##### TUP GITIGNORE #####
+##### Lines below automatically generated by Tup.
+##### Do not edit.
+.tup
+/.gitignore
+/aio
+/alsa-simple
+/atexit
+/bit_cast
+/cat
+/cie-1931
+/clock-test
+/cobs
+/coro-round-robin
+/coro-timer-dispatch
+/coro-unconditional-dispatch
+/crc-table
+/crc7
+/dsp
+/elastic-tabstops
+/enviro
+/epoll
+/flat-set
+/gl-asteroids
+/glob
+/guess-number
+/hush
+/io_uring
+/mmallocator
+/model
+/morse
+/mutex_container
+/pulse-async-client
+/pulse-simple-client
+/regex
+/sorts
+/sudoku
+/token-threaded-forth
+/triple-buf
+/whichtty
diff --git a/Tupfile b/Tupfile
@@ -0,0 +1,15 @@
+WFLAGS = -Wall -Wextra -Werror
+CFLAGS = $(WFLAGS) -fdiagnostics-color=always
+CXXFLAGS = -std=c++20 $(WFLAGS) -fdiagnostics-color=always
+
+LDLIBS_aio = -lrt
+LDLIBS_gl-asteroids = -lglfw -lGL -lm -lasound
+LDLIBS_io_uring = -luring
+LDLIBS_pulse-async-client = -lpulse
+LDLIBS_pulse-simple-client = -lpulse-simple -lm
+LDLIBS_alsa-simple = -lasound
+
+: foreach src/*.c |> cc $(CFLAGS) -o %o %f $(LDLIBS_%B) |> %B
+: foreach src/*.cpp |> c++ $(CXXFLAGS) -o %o %f $(LDLIBS_%B) |> %B
+
+.gitignore
diff --git a/Tupfile.ini b/Tupfile.ini
diff --git a/src/aio.cpp b/src/aio.cpp
@@ -1,80 +0,0 @@
-#include <iostream>
-#include <vector>
-#include <iomanip>
-
-#include <aio.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-struct x
-{
- struct aiocb a;
- dirent e;
- char buf[];
-};
-
-int main(int argc, char* argv[])
-{
- DIR* d = opendir(".");
- int dfd = dirfd(d);
-
- std::vector<struct aiocb*> liop;
-
- while (auto e = readdir(d))
- {
- if (DT_REG != e->d_type)
- continue;
-
- int f = openat(dfd, e->d_name, O_RDONLY);
-
- struct stat s;
- fstat(f, &s);
-
- struct x* buf = (struct x*)malloc(sizeof(struct x) + s.st_size);
- buf->a = {f, LIO_READ, 0, &buf->buf, (size_t)s.st_size, {SIGEV_NONE}, 0};
- buf->e = *e;
-
- liop.push_back(&buf->a);
- }
-
- lio_listio(LIO_NOWAIT, liop.data(), liop.size(), NULL);
-
- int outstanding = liop.size();
- int cycles = 0;
-
- while (outstanding)
- {
- ++cycles;
- aio_suspend(liop.data(), liop.size(), NULL);
- for (auto& iop : liop)
- {
- if (!iop)
- continue;
-
- size_t b = iop->aio_nbytes;
- char* s = (char*)const_cast<void*>(iop->aio_buf), *end = s + b;
- struct x* x = (struct x*)(s - offsetof(struct x, buf));
- unsigned n = 0;
-
- if (int err = aio_error(iop); err == EINPROGRESS)
- continue;
- else if (err)
- exit(1);
-
- iop = nullptr;
- --outstanding;
- while (s < end)
- if (*s++ == '\n')
- ++n;
-
- using std::cout, std::setw;
-
- cout << setw(20) << x->e.d_name << ": " << setw(6) << b << " bytes, " << setw(4) << n << " lines, cycle " << cycles << '\n';
- }
- }
-
- std::cout << "Read after " << cycles << " cycles\n";
- return 0;
-}
-