-
-
Save riking/9a1dff3f1c1b36e6dbfce53e52a325ff to your computer and use it in GitHub Desktop.
Makefile making mysterious rm command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILENAMES += ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c | |
FILENAMES += ft_toupper.c ft_tolower.c | |
TESTS += char_is | |
# Remark: I have a file named test_char_is.c that contains a main() | |
FILENAMES += # ... more ... | |
TESTS += # ... more ... | |
NAME = libft.a | |
CC = gcc | |
CFLAGS += -Wall -Wextra -Werror | |
LDFLAGS += -Wall -Wextra -Werror | |
ifeq ($(DEBUG), 1) | |
CFLAGS += -fsanitize=address | |
LDFLAGS += -fsanitize=address | |
else | |
#CFLAGS += -O3 -fomit-frame-pointer -DNDEBUG -flto | |
#LDFLAGS += -O3 -fomit-frame-pointer -DNDEBUG -flto | |
endif | |
SRCS = $(FILENAMES) | |
OBJS = $(addprefix build/, $(FILENAMES:.c=.o)) | |
TESTTARGETS = $(addprefix test-, $(TESTS)) | |
TESTBINS = $(addprefix build/, $(TESTTARGETS)) | |
.PHONY: all clean fclean re test $(TESTTARGETS) | |
all: $(NAME) | |
re: fclean all | |
clean: | |
rm -rf build/ | |
rm -f $(TESTBINS) | |
fclean: clean | |
rm -f $(NAME) | |
build: | |
mkdir build/ | |
$(NAME): $(OBJS) | |
ar rcs $@ $^ | |
build/%.o: %.c libft.h | build | |
$(CC) $(CFLAGS) -c $< -o $@ | |
test: $(TESTBINS) | |
for bin in $(TESTBINS); do \ | |
echo $$bin ; \ | |
$$bin ; \ | |
echo ; \ | |
done | |
build/test-%: build/test_%.o libft.a | build | |
$(CC) $(LDFLAGS) -o $@ $^ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment