diff options
| author | EuAndreh <eu@euandre.org> | 2021-08-22 11:21:07 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2021-08-22 11:42:34 -0300 |
| commit | 3a4b3fa01b6ead1e23434c533302a2a9fddfd89e (patch) | |
| tree | 5a4f5b1e9e5d78e057ed2b49d6d94269dd586a98 /Makefile | |
| parent | src/gistatic.c: Remove .logo bogus color attribute (diff) | |
| download | gistatic-3a4b3fa01b6ead1e23434c533302a2a9fddfd89e.tar.gz gistatic-3a4b3fa01b6ead1e23434c533302a2a9fddfd89e.tar.xz | |
Have a single top-level main for running unit-tests
Instead of each .c file becoming a self-standing .t executable file,
and being run for executing the unit tests local to the file, now each
.c becomes a .to object (akin to a .o object, but one where the -DTEST
flag is given to the compiler). After that, all the .to objects are
linked together in a gistatic-tests executable, in a equivalent way
that all .o files get linked together in a gistatic executable.
This change was necessary in order to allow dependencies between
objects. The next task will be making a tar of a repository tree
checkout, and src/gistatic.{o,to} will start depending on
src/tar.{o,to}. If each file has its own main function when -DTEST is
given, then I wont be able to link them together.
I took the opportunity that I had to change the Makefile, and I
improved the dependency between targets and dependencies greatly. From
what I can tell now, it is correct.
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 64 |
1 files changed, 37 insertions, 27 deletions
@@ -9,13 +9,13 @@ TRANSLATIONS = pt fr eo CONTRIBLANGS = LDLIBS = -lgit2 -.SUFFIXES: .in .t +.SUFFIXES: .in .to .in: sed -e 's:@VERSION@:$(VERSION):g' -e 's:@DATE@:$(DATE):g' < $< > $@ -.c.t: - $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $< src/tests-lib.o $(LDLIBS) +.c.to: + $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ -c $< $(LDLIBS) manpages.en.in = \ @@ -29,50 +29,60 @@ manpages = $(manpages.in:.in=) sources = \ src/tar.c \ src/gistatic.c -objects = $(sources:.c=.o) -tests = $(sources:.c=.t) +lib-objects = $(sources:.c=.o) +all-objects = $(lib-objects) src/main.o +t-objects = $(sources:.c=.to) src/tests-lib.to src/main.to -all: src/config.h src/tests-lib.o src/gistatic libgistatic.a $(manpages) +all: gistatic libgistatic.a $(manpages) +gistatic: $(all-objects) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(all-objects) $(LDLIBS) -src/gistatic: $(objects) src/main.o - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objects) src/main.o $(LDLIBS) +gistatic-tests: $(t-objects) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(t-objects) $(LDLIBS) -libgistatic.a: $(objects) - $(AR) $(ARFLAGS) $@ $(objects) +libgistatic.a: $(lib-objects) + $(AR) $(ARFLAGS) $@ $(lib-objects) src/config.h: - touch $@ printf '#ifndef GISTATIC_CONFIG_H\n' >> $@ printf '#define GISTATIC_CONFIG_H\n\n' >> $@ printf '#define _POSIX_C_SOURCE 200809L\n' >> $@ printf '#define VERSION "$(VERSION)"\n' >> $@ printf '#define DATE "$(DATE)"\n' >> $@ - printf '\n#endif\n' >> $@ + printf '\n' >> $@ + printf '#endif\n' >> $@ -$(objects): src/config.h -$(tests): src/config.h src/tests-lib.h src/tests-lib.o -src/gistatic.o: src/gistatic.h src/tar.o src/tar.h -src/main.o: src/gistatic.h src/gistatic.o +$(all-objects) $(t-objects): src/config.h +src/tests-lib.to: src/tests-lib.h +src/tar.o src/tar.to: src/tar.h +src/gistatic.o src/gistatic.to: src/gistatic.h +src/gistatic.o: src/tar.o +src/gistatic.to: src/tar.to +src/main.o src/main.to: src/tar.h src/gistatic.h +src/main.o: src/tar.o src/gistatic.o +src/main.to: src/tar.to src/gistatic.to +tests/resources/repositories/repo-1/.git \ +tests/resources/repositories/repo-2/.git: + ln -s .gitdir $@ -check: all $(tests) - rm -f tests/resources/repositories/repo-1/.git - rm -f tests/resources/repositories/repo-2/.git - ln -s .gitdir tests/resources/repositories/repo-1/.git - ln -s .gitdir tests/resources/repositories/repo-2/.git +check: all gistatic-tests \ + tests/resources/repositories/repo-1/.git \ + tests/resources/repositories/repo-2/.git sh tests/build-sample.sh - for t in $(tests); do ./$$t; done + ./gistatic-tests sh tests/assert-catgets.sh src/*.c sh tests/integration.sh sh tests/c-lint.sh src/*.c clean: - rm -rf public/ $(manpages) README.*.md CHANGELOG.*.md messages.mo \ - vgcore.* tmp/ src/config.h \ - src/*.o src/*.t src/gistatic libgistatic.a \ - tests/resources/repositories/repo-1/.git \ + rm -rf \ + public/ $(manpages) README.*.md CHANGELOG.*.md messages.mo \ + vgcore.* tmp/ src/config.h src/*.o src/*.to \ + libgistatic.a gistatic gistatic-tests \ + tests/resources/repositories/repo-1/.git \ tests/resources/repositories/repo-2/.git install: all @@ -80,7 +90,7 @@ install: all $(DESTDIR)$(PREFIX)/bin \ $(DESTDIR)$(PREFIX)/lib \ $(DESTDIR)$(PREFIX)/include - cp src/gistatic $(DESTDIR)$(PREFIX)/bin + cp gistatic $(DESTDIR)$(PREFIX)/bin cp libgistatic.a $(DESTDIR)$(PREFIX)/lib cp src/gistatic.h $(DESTDIR)$(PREFIX)/include sh doc/manpages.sh -ip $(DESTDIR)$(MANPREFIX) $(manpages) |
