diff options
| author | EuAndreh <eu@euandre.org> | 2023-11-15 10:50:30 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2023-11-15 16:16:30 -0300 |
| commit | af5e7495f3993c52573432cadde12169d5c05e62 (patch) | |
| tree | 002fc20e6f12eac71c21c6eccc48bf59e7180274 /Makefile | |
| parent | src/napi-sqlite.c: Add Node-API PoC (diff) | |
| download | papod-af5e7495f3993c52573432cadde12169d5c05e62.tar.gz papod-af5e7495f3993c52573432cadde12169d5c05e62.tar.xz | |
Add support for multi-file C project
- have dynamic discovered dependencies via `mkdeps.hs`, and also move
the listing of JavaScript files to it.
- copy over stub C files for setting up the project skeleton.
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 145 |
1 files changed, 116 insertions, 29 deletions
@@ -15,15 +15,22 @@ SRCDIR = $(PREFIX)/src/$(NAME) SHAREDIR = $(PREFIX)/share LOCALEDIR = $(SHAREDIR)/locale MANDIR = $(SHAREDIR)/man +CFLAGS.a = $(CFLAGS) CFLAGS.so = $(CFLAGS) -fPIC +LDFLAGS.a = $(LDFLAGS) LDFLAGS.so = $(LDFLAGS) -shared +LDLIBS.a = $(LDLIBS) +LDLIBS.so = $(LDLIBS) +EXT.so = .so +EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = +LDLIBS = .SUFFIXES: -.SUFFIXES: .in .c .lo .msg .cat +.SUFFIXES: .in .c .o .lo .to .ta .t .msg .cat .in: sed \ @@ -35,11 +42,23 @@ DESTDIR = < $< > $@ if [ -x $< ]; then chmod +x $@; fi +.c.o: + $(CC) $(CFLAGS.a) -o $@ -c $< + .c.lo: - $(CC) $(CFLAGS.so) -o $@ -c $< + $(CC) $(CFLAGS.so) -o $@ -c $< + +.c.to: + $(CC) $(CFLAGS.a) -DTEST -o $@ -c $< + +.ta.t: + $(CC) $(LDFLAGS.a) -o $@ $< $(LDLIBS.a) +all: +include deps.mk + manpages.en.in = \ doc/$(NAME).README.en.7.in \ doc/$(NAME).CHANGELOG.en.7.in \ @@ -52,25 +71,38 @@ manpages.en.in = \ manpages.in = $(manpages.en.in) manpages = $(manpages.in:.in=) -sources.js = \ - src/api.js \ - src/cli.js \ - src/ircd.js \ - src/utils.js \ - src/web.js \ - -tests.js = \ - tests/js/ircd.js \ - tests/js/utils.js \ - tests/js/web.js \ +catalogs.en.msg = src/$(NAME).en.msg +catalogs.msg = $(catalogs.en.msg) +catalogs.cat = $(catalogs.msg:.msg=.cat) +sources.o = $(sources.c:.c=.o) +sources.lo = $(sources.c:.c=.lo) +sources.to = $(sources.c:.c=.to) +sources.ta = $(sources.c:.c=.ta) +sources.t = $(sources.c:.c=.t) sources = \ - $(sources.js) \ + $(sources.c) \ + $(sources.c:.c=.h) \ + src/config.h.in \ + src/config.h \ + $(catalogs.msg) \ + $(sources.js) \ derived-assets = \ + $(NAME).bin \ + lib$(NAME)$(EXT.so) \ + src/config.h \ $(manpages) \ + $(catalogs.cat) \ + $(sources.o) \ + $(sources.lo) \ + $(sources.to) \ + $(sources.ta) \ + $(sources.t) \ + tests/tests-lib.o \ + tests/slurp.o \ src/index.js \ node_modules/dir.sentinel \ node_modules/ \ @@ -79,8 +111,10 @@ derived-assets = \ src/napi-sqlite.node \ side-assets = \ - ircd.sock \ - web.sock \ + src/logerr.c.txt \ + src/catalog.c.txt \ + ircd.sock \ + web.sock \ @@ -89,10 +123,14 @@ side-assets = \ all: $(derived-assets) -$(manpages) src/napi-sqlite.lo: Makefile +$(NAME).bin: + ln -fs src/cli $@ -src/napi-sqlite.node: src/napi-sqlite.lo - $(CC) $(LDFLAGS.so) -o $@ src/napi-sqlite.lo +$(manpages) src/config.h: Makefile deps.mk +$(sources.o) $(sources.lo) $(sources.to): src/config.h Makefile deps.mk +tests/tests-lib.o: tests/tests-lib.h src/config.h Makefile deps.mk +$(sources.to): tests/tests-lib.h +$(sources.ta): tests/tests-lib.o src/index.js: ln -fs api.js $@ @@ -108,6 +146,22 @@ node_modules/$(NAME): node_modules/dir.sentinel node_modules/: node_modules/dir.sentinel node_modules/$(NAME) +src/napi-sqlite.node: lib$(NAME)$(EXT.so) + ln -f lib$(NAME)$(EXT.so) $@ + +lib$(NAME)$(EXT.so): $(sources.lo) src/napi-sqlite.lo + $(CC) $(LDFLAGS.so) -o $@ $(sources.lo) src/napi-sqlite.lo $(LDLIBS.so) + +$(sources.ta): + $(AR) $(ARFLAGS) $@ $? + +src/$(NAME).en.cat: src/i18n.t + env DUMP_TRANSLATABLE_STRINGS=1 $(EXEC)src/i18n.t > $*.msg.new + cmp -s $*.msg.new $*.msg || mv $*.msg.new $*.msg + rm -f $*.msg.new + gencat $@ $*.msg + touch $@ + .SUFFIXES: .js .js-t @@ -115,7 +169,34 @@ tests.js-t = $(tests.js:.js=.js-t) $(tests.js-t): node $*.js -check-t: $(tests.js-t) +check-js-t: $(tests.js-t) + +.SUFFIXES: .t-run +sources.t-run = $(sources.c:.c=.t-run) +$(sources.t-run): + $(EXEC)$*.t + +check-t-run: $(sources.t-run) + +check-t: check-js-t check-t-run + + + +.SUFFIXES: .c-lint +sources.c-lint = $(sources.c:.c=.c-lint) +$(sources.c-lint): + sh tests/c-lint.sh $*.c + +check-lint: $(sources.c-lint) + + +integration-tests = \ + tests/cli-opts.sh \ + +$(integration-tests): $(NAME).bin ALWAYS + sh $@ $(EXEC)$(NAME).bin + +check-integration: $(integration-tests) tests/assert-clean.sh tests/assert-install.sh tests/assert-uninstall.sh: all @@ -134,7 +215,7 @@ check-asserts: $(assert-tests) ## Run all tests. Each test suite is isolated, so that a parallel ## build can run tests at the same time. The required artifacts ## are created if missing. -check: check-t check-asserts +check: check-t check-lint check-integration check-asserts ## Remove *all* derived artifacts produced during the build. @@ -149,38 +230,44 @@ install: all mkdir -p \ '$(DESTDIR)$(BINDIR)' \ '$(DESTDIR)$(JSLIBDIR)' - cp src/*.js '$(DESTDIR)$(JSLIBDIR)' + cp -P src/*.js '$(DESTDIR)$(JSLIBDIR)' ln -fs '$(DESTDIR)$(JSLIBDIR)'/cli.js '$(DESTDIR)$(BINDIR)'/$(NAME) for f in $(sources); do \ dir='$(DESTDIR)$(SRCDIR)'/"`dirname "$${f#src/}"`"; \ mkdir -p "$$dir"; \ cp -P "$$f" "$$dir"; \ done + for l in en $(TRANSLATIONS); do \ + dir='$(DESTDIR)$(LOCALEDIR)'/"$$l"/LC_MESSAGES; \ + mkdir -p "$$dir"; \ + cp src/$(NAME)."$$l".cat "$$dir"/$(NAME).cat; \ + done sh tools/manpages.sh -ip '$(DESTDIR)$(MANDIR)' $(manpages) ## Uninstalls from $(DESTDIR)$(PREFIX). This is a perfect mirror ## of the "install" target, and removes *all* that was installed. ## A dedicated test asserts that this is always true. uninstall: - rm -f \ - '$(DESTDIR)$(BINDIR)'/$(NAME) + rm -rf \ + '$(DESTDIR)$(BINDIR)'/$(NAME) \ + '$(DESTDIR)$(SRCDIR)' rm -rf '$(DESTDIR)$(JSLIBDIR)' - for f in $(sources); do \ - rm -f '$(DESTDIR)$(SRCDIR)'/$${f#src/}; \ + for l in en $(TRANSLATIONS); do \ + rm -f '$(DESTDIR)$(LOCALEDIR)'/"$$l"/LC_MESSAGES/$(NAME).cat; \ done sh tools/manpages.sh -up '$(DESTDIR)$(MANDIR)' $(manpages) -run-ircd: +run-ircd: all rm -f ircd.sock ./src/cli.js ircd ircd.sock -run-web: +run-web: all rm -f web.sock ./src/cli.js web web.sock ## Run the web and IRC server locally. -run: node_modules/$(NAME) src/index.js +run: all $(MAKE) run-ircd & $(MAKE) run-web & wait |
