1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # WARNING: This is not the same as HW08. I am illustrating concepts, not doing HW08.
# There may be some similarities. Some names will be changed deliberately.
NAME=print_twos
TEST_NAME=test_$(NAME)
C_FILENAME=$(NAME).c
TEST_C_FILENAME=$(TEST_NAME).c
# Rule 'test_print_twos' builds the (executable) file test_print_twos.
$(TEST_NAME): $(TEST_NAME).o $(NAME).o
# test_print_twos
gcc $(TEST_NAME).o $(NAME).o -o $(TEST_NAME)
# Rule 'test_print_twos.o' builds the (object file) file test_print_twos.o.
$(TEST_NAME).o: $(TEST_C_FILENAME)
# test_print_twos.o.
gcc -c $(TEST_C_FILENAME)
# Rule 'print_twos.o' builds the (object file) file print_twos.o.
$(NAME).o: $(C_FILENAME)
# print_twos.o.
gcc -c $(C_FILENAME)
run: $(TEST_NAME)
./$(TEST_NAME)
clean:
rm -f $(TEST_NAME) *.o
.PHONY: run
# Every rule that does not create a file by the name of that rule's target (e.g., "run")
# is a "phony rule" and must be listed after .PHONY: ▒ Yes, this is bizarre.
#
# If you just type
# $ make
# in bash, you will run the first rule in the Makefile. Customarily, that should
# build the executable.
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.