<commit_before>
##############################
### VARIABLES
##############################

DEPS_DIR ?= deps

LIBBASE ?= $(DEPS_DIR)/libbase

CPPFLAGS += -I$(DEPS_DIR)

CFLAGS ?= -std=c11 -g \
          -Wall -Wextra -pedantic \
          -Wcomments -Wformat=2 -Wlogical-op -Wmissing-include-dirs \
          -Wnested-externs -Wold-style-definition -Wredundant-decls \
          -Wshadow -Wstrict-prototypes -Wunused-macros -Wvla -Wwrite-strings \
          -Wno-missing-field-initializers -Wno-override-init \
          -Wno-unused-parameter

TPLRENDER ?= $(DEPS_DIR)/tplrender/tplrender


test_libmaybe_types := ulong intmax ptr-ptr-char
test_libbase_types := $(test_libmaybe_types)

ulong_type           := ulong
ulong_options        := --typeclasses BOUNDED EQ ORD ENUM NUM \
                        --extra num_type=unsigned

intmax_type          := intmax_t
intmax_options       := --typeclasses BOUNDED EQ ORD ENUM NUM \
                        --extra num_type=signed

ptr_ptr_char_type    := char const * const *
ptr_ptr_char_options := --typeclasses EQ ORD

test_libbase_sources := $(foreach t,$(test_libbase_types),$(LIBBASE)/$t.c)
test_libbase_headers := $(test_libbase_sources:.c=.h)
test_libbase_objects := $(test_libbase_sources:.c=.o)

test_libmaybe_sources := $(foreach t,$(test_libmaybe_types),maybe_$t.c)
test_libmaybe_headers := $(test_libmaybe_sources:.c=.h)
test_libmaybe_defs    := $(addprefix def/,$(test_libmaybe_headers))
test_libmaybe_objects := $(test_libmaybe_sources:.c=.o)

test_gen_objects := $(test_libbase_objects) \
                    $(test_libmaybe_objects)

test_gen := $(test_libbase_sources) \
            $(test_libbase_headers) \
            $(test_libmaybe_sources) \
            $(test_libmaybe_headers) \
            $(test_libmaybe_defs) \
            $(test_gen_objects)

test_binaries := $(basename $(wildcard tests/*.c))

mkdeps := $(test_gen_objects:.o=.dep.mk)



##############################
### BUILDING
##############################

.PHONY: all
all: tests

.PHONY: tests
tests: $(test_binaries)

.PHONY: test
test: tests
	./tests/test

.PHONY: clean
clean:
	rm -rf $(test_gen) $(test_binaries) $(mkdeps)


%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF "$(@:.o=.dep.mk)" -c $< -o $@


tests/test: $(test_gen_objects)

name_from_path = $(subst -,_,$1)

$(test_libbase_headers): $(LIBBASE)/%.h: $(LIBBASE)/header.h.jinja
	$(eval n := $(call name_from_path,$*))
	$(TPLRENDER) $< "$($(n)_type)" $($(n)_options) -o $@

$(test_libbase_sources): $(LIBBASE)/%.c: $(LIBBASE)/source.c.jinja
	$(eval n := $(call name_from_path,$*))
	$(TPLRENDER) $< "$($(n)_type)" $($(n)_options) -o $@

$(test_libbase_objects): $(LIBBASE)/%.o: $(LIBBASE)/%.h

$(test_libmaybe_defs): def/maybe_%.h: def.h.jinja
	$(eval n := $(call name_from_path,$*))
	$(TPLRENDER) $< "$($(n)_type)" $($(n)_options) -o $@

$(test_libmaybe_headers): maybe_%.h: header.h.jinja
	$(eval n := $(call name_from_path,$*))
	$(TPLRENDER) $< "$($(n)_type)" $($(n)_options) -o $@

$(test_libmaybe_sources): maybe_%.c: source.c.jinja
	$(eval n := $(call name_from_path,$*))
	$(TPLRENDER) $< "$($(n)_type)" $($(n)_options) --sys-headers "libbase/$*.h" -o $@

$(test_libmaybe_objects): maybe_%.o: maybe_%.h def/maybe_%.h $(LIBBASE)/%.h


-include $(mkdeps)

<commit_msg>Simplify Makefile and improve build compatibility<commit_after>
##############################
### VARIABLES
##############################

DEPS_DIR ?= deps

LIBBASE ?= $(DEPS_DIR)/libbase

CPPFLAGS += -I$(DEPS_DIR)

CFLAGS ?= -std=c11 -g \
          -Wall -Wextra -pedantic \
          -Wcomments -Wformat=2 -Wlogical-op -Wmissing-include-dirs \
          -Wnested-externs -Wold-style-definition -Wredundant-decls \
          -Wshadow -Wstrict-prototypes -Wunused-macros -Wvla -Wwrite-strings \
          -Wno-missing-field-initializers -Wno-override-init \
          -Wno-type-limits -Wno-unused-parameter

TPLRENDER ?= $(DEPS_DIR)/tplrender/tplrender


libmaybe_types := ulong intmax ptr_ptr_char
libbase_types := $(libmaybe_types)

ulong_type           := ulong
ulong_options        := --typeclasses BOUNDED EQ ORD ENUM NUM \
                        --extra num_type=unsigned

intmax_type          := intmax_t
intmax_options       := --typeclasses BOUNDED EQ ORD ENUM NUM \
                        --extra num_type=signed

ptr_ptr_char_type    := char const * const *
ptr_ptr_char_options := --typeclasses EQ ORD

libbase_sources := $(foreach t,$(libbase_types),$(LIBBASE)/$t.c)
libbase_headers := $(libbase_sources:.c=.h)
libbase_objects := $(libbase_sources:.c=.o)

libmaybe_sources := $(foreach t,$(libmaybe_types),maybe_$t.c)
libmaybe_headers := $(libmaybe_sources:.c=.h)
libmaybe_defs    := $(addprefix def/,$(libmaybe_headers))
libmaybe_objects := $(libmaybe_sources:.c=.o)

gen_objects := $(libbase_objects) \
               $(libmaybe_objects)

gen := $(libbase_sources) \
       $(libbase_headers) \
       $(libmaybe_sources) \
       $(libmaybe_headers) \
       $(libmaybe_defs) \
       $(gen_objects)

test_binaries := $(basename $(wildcard tests/*.c))

mkdeps := $(gen_objects:.o=.dep.mk)



##############################
### BUILDING
##############################

.PHONY: all
all: tests

.PHONY: tests
tests: $(test_binaries)

.PHONY: test
test: tests
	./tests/test

.PHONY: clean
clean:
	rm -rf $(gen) $(test_binaries) $(mkdeps)


%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF "$(@:.o=.dep.mk)" -c $< -o $@


tests/test: $(gen_objects)


$(libbase_headers): $(LIBBASE)/%.h: $(LIBBASE)/header.h.jinja
	$(TPLRENDER) $< "$($(*)_type)" $($(*)_options) -o $@

$(libbase_sources): $(LIBBASE)/%.c: $(LIBBASE)/source.c.jinja
	$(TPLRENDER) $< "$($(*)_type)" $($(*)_options) -o $@

$(libbase_objects): $(LIBBASE)/%.o: $(LIBBASE)/%.h

$(libmaybe_defs): def/maybe_%.h: def.h.jinja
	$(TPLRENDER) $< "$($(*)_type)" $($(*)_options) -o $@

$(libmaybe_headers): maybe_%.h: header.h.jinja
	$(TPLRENDER) $< "$($(*)_type)" $($(*)_options) -o $@

$(libmaybe_sources): maybe_%.c: source.c.jinja
	$(TPLRENDER) $< "$($(*)_type)" $($(*)_options) --sys-headers "libbase/$*.h" -o $@

$(libmaybe_objects): maybe_%.o: maybe_%.h def/maybe_%.h $(LIBBASE)/%.h


-include $(mkdeps)


{'fraction_non_alphanumeric': 0.22319830811778102, 'fraction_numerical': 0.001138766878151944, 'mean_word_length': 3.6540499621498865, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '688750', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2284, 'n_words': 391}