aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-05-10 16:30:42 -0300
committerEuAndreh <eu@euandre.org>2025-05-10 16:39:34 -0300
commit2ce4f876734df9adcae7c7d3e558f8bcfd37cb52 (patch)
tree9343323c26afb6169c0ea143d516cb089aba91d9 /Makefile
parentMerge pull request #11 from mvo5/bugfix/fix-tests-on-linux (diff)
downloadgotext-2ce4f876734df9adcae7c7d3e558f8bcfd37cb52.tar.gz
gotext-2ce4f876734df9adcae7c7d3e558f8bcfd37cb52.tar.xz
Setup Go skeleton
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile208
1 files changed, 208 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..bd6143e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,208 @@
+.POSIX:
+DATE = 1970-01-01
+VERSION = 0.1.0
+NAME = gotext
+NAME_UC = $(NAME)
+LANGUAGES = en
+## Installation prefix. Defaults to "/usr".
+PREFIX = /usr
+BINDIR = $(PREFIX)/bin
+LIBDIR = $(PREFIX)/lib
+GOLIBDIR = $(LIBDIR)/go
+INCLUDEDIR = $(PREFIX)/include
+SRCDIR = $(PREFIX)/src/$(NAME)
+SHAREDIR = $(PREFIX)/share
+LOCALEDIR = $(SHAREDIR)/locale
+MANDIR = $(SHAREDIR)/man
+EXEC = ./
+## Where to store the installation. Empty by default.
+DESTDIR =
+LDLIBS = --static
+GOCFLAGS = -I $(GOLIBDIR)
+GOLDFLAGS = -L $(GOLIBDIR)
+
+
+
+.SUFFIXES:
+.SUFFIXES: .go .a .c .o .bin .bin-check
+
+.c.o:
+ $(CC) $(CFLAGS) -o $@ -c $<
+
+.go.a:
+ go tool compile -I $(@D) $(GOCFLAGS) -o $@ -p $(*F) \
+ `find $< $$(if [ $(*F) != main ]; then \
+ echo src/$(NAME).go src/version.go; fi) | uniq`
+
+.a.bin:
+ go tool link -L $(@D) $(GOLDFLAGS) -o $@ --extldflags '$(LDLIBS)' $<
+
+
+
+all:
+include deps.mk
+
+
+libs.a = $(libs.go:.go=.a)
+mains.a = $(mains.go:.go=.a)
+mains.bin = $(mains.go:.go=.bin)
+functional-tests/lib.a = $(functional-tests/lib.go:.go=.a)
+fuzz-targets/lib.a = $(fuzz-targets/lib.go:.go=.a)
+benchmarks/lib.a = $(benchmarks/lib.go:.go=.a)
+
+cgo.go = \
+ src/_cgo_import.go \
+ src/_cgo_gotypes.go \
+ src/$(NAME).cgo1.go \
+
+cgo.c = \
+ src/_cgo_export.c \
+ src/$(NAME).cgo2.c \
+
+cgo.o = $(cgo.c:.c=.o)
+
+objects = \
+ src/_cgo_.o \
+ $(cgo.go) \
+ $(cgo.c) \
+ $(cgo.o) \
+
+sources = \
+ src/$(NAME).go \
+ src/version.go \
+ src/main.go \
+
+
+derived-assets = \
+ src/version.go \
+ $(objects) \
+ $(libs.a) \
+ $(mains.a) \
+ $(mains.bin) \
+ $(NAME).bin \
+
+side-assets = \
+ src/_cgo_export.h \
+ src/_cgo_main.c \
+ tests/fuzz/corpus/ \
+ tests/benchmarks/*/main.txt \
+
+
+
+## Default target. Builds all artifacts required for testing
+## and installation.
+all: $(derived-assets)
+
+
+$(objects): Makefile deps.mk
+$(libs.a): Makefile deps.mk
+$(libs.a): src/$(NAME).go src/version.go
+$(libs.a): $(cgo.go) $(cgo.o)
+
+$(cgo.go) $(cgo.c) $(cgo.o): src/_cgo_.o
+
+
+src/_cgo_.o: src/$(NAME).go
+ go tool cgo --objdir $(@D) src/$(NAME).go
+
+src/_cgo_import.go: src/_cgo_.o
+ go tool cgo --dynpackage $(NAME) --dynimport src/_cgo_.o --dynout $@
+
+src/$(NAME).a tests/$(NAME).a $(functional-tests/lib.a) $(benchmarks/lib.a):
+ go tool compile $(GOCFLAGS) -o $@ -p $(*F) $(cgo.go) src/version.go \
+ `find $*.go | grep -Ev '^src/$(NAME)\.go$$'`
+ go tool pack r $@ $(cgo.o)
+
+$(fuzz-targets/lib.a):
+ go tool compile $(GOCFLAGS) -o $@ -p $(NAME) -d=libfuzzer \
+ $*.go $(cgo.go) src/version.go
+ go tool pack r $@ $(cgo.o)
+
+src/version.go: Makefile
+ echo 'package $(NAME); const Version = "$(VERSION)"' > $@
+
+$(NAME).bin: src/main.bin
+ ln -fs src/main.bin $@
+
+
+
+tests.bin-check = \
+ tests/main.bin-check \
+ $(functional-tests/main.go:.go=.bin-check) \
+
+$(tests.bin-check):
+ $(EXEC)$*.bin
+
+check-unit: $(tests.bin-check)
+
+
+integration-tests = \
+ tests/cli-opts.sh \
+ tests/integration.sh \
+
+.PRECIOUS: $(integration-tests)
+$(integration-tests): $(NAME).bin
+$(integration-tests): ALWAYS
+ sh $@
+
+check-integration: $(integration-tests)
+check-integration: fuzz
+
+
+## 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-unit check-integration
+
+
+
+FUZZSEC=1
+fuzz-targets/main.bin-check = $(fuzz-targets/main.go:.go=.bin-check)
+$(fuzz-targets/main.bin-check):
+ $(EXEC)$*.bin --test.fuzztime=$(FUZZSEC)s \
+ --test.fuzz='.*' --test.fuzzcachedir=tests/fuzz/corpus
+
+fuzz: $(fuzz-targets/main.bin-check)
+
+
+
+benchmarks/main.bin-check = $(benchmarks/main.go:.go=.bin-check)
+$(benchmarks/main.bin-check):
+ printf '%s\n' '$(EXEC)$*.bin' > $*.txt
+ LANG=POSIX.UTF-8 time -p $(EXEC)$*.bin 2>> $*.txt
+ printf '%s\n' '$*.txt'
+
+bench: $(benchmarks/main.bin-check)
+
+
+
+## Remove *all* derived artifacts produced during the build.
+## A dedicated test asserts that this is always true.
+clean:
+ rm -rf $(derived-assets) $(side-assets)
+
+
+## Installs into $(DESTDIR)$(PREFIX). Its dependency target
+## ensures that all installable artifacts are crafted beforehand.
+install: all
+ mkdir -p \
+ '$(DESTDIR)$(BINDIR)' \
+ '$(DESTDIR)$(GOLIBDIR)' \
+ '$(DESTDIR)$(SRCDIR)' \
+
+ cp $(NAME).bin '$(DESTDIR)$(BINDIR)'/$(NAME)
+ cp src/$(NAME).a '$(DESTDIR)$(GOLIBDIR)'
+ cp -P $(sources) '$(DESTDIR)$(SRCDIR)'
+
+## 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 -rf \
+ '$(DESTDIR)$(BINDIR)'/$(NAME) \
+ '$(DESTDIR)$(GOLIBDIR)'/$(NAME).a \
+ '$(DESTDIR)$(SRCDIR)' \
+
+
+
+ALWAYS: