minishell/tests/Makefile
Khaïs COLIN e033909819 makefile: generate depfiles for the correct object files
The depfiles were completely ineffective.

Now this is fixed.

The -MT argument sets the path for the dependenency root. By default it is set
only to a filename, and thus does not include the full path of the file.
2025-04-15 14:41:43 +02:00

60 lines
1.3 KiB
Makefile

# make gets confused if a file with the same name exists in the sources, so some
# file are prefixed with test_
rawtests = \
test_here_doc \
expansion \
test_cmdlist_use_after_free \
test_wordlist_idx \
test_quote_removal \
test_metacharacters \
test_parse_cmdlists \
test_parse_pipelines \
test_parse_simple_cmds \
test_env_manip \
test_word_splitting \
ifeq ($(CFLAGS),)
CFLAGS = -Wall -Wextra -Werror -g
endif
tests = $(addprefix test_,$(rawtests))
run_tests = $(addprefix run_test_,$(rawtests))
test_objs = $(addsuffix .o,$(tests))
objs := $(addprefix ../,$(objs)) \
testutil.o \
parse_cmdlist.o \
parse_pipeline.o \
all_objs = $(objs) $(test_objs)
deps = $(all_objs:.o=.d)
LDLIBS = \
-lreadline \
-lft
LIBFTDIR = ../libft/
LIBFT = $(LIBFTDIR)libft.a
IFLAGS = -I$(LIBFTDIR)
LINCLUDE = -L$(LIBFTDIR)
.PHONY: run fclean run_test_%
.NOTPARALLEL: run
run: $(run_tests)
@echo "Finished running C tests"
-include $(deps)
%.o: %.c
$(CC) -c $(CFLAGS) $(IFLAGS) -o $*.o $*.c
$(CC) -MM $(CFLAGS) $(IFLAGS) -MT $*.o $*.c > $*.d
test_%: %.o $(objs)
$(CC) $(CFLAGS) -rdynamic -o $@ $*.o $(objs) $(LINCLUDE) $(LDLIBS)
run_test_%: test_%
@echo
@echo "====== Now running test: $* ======"
@echo
./test_$*
@echo "====== End of test: $* ======"
fclean:
rm -f $(tests)