There is a small C library consisting of three files:
- lib.h - code
- test.c - tests
- debug.h - additional code for tests.
I want to write a Makefile to:
- Compile all
makefiles. They should appear in theoutdirectory. It is not necessary to create it, it is always there, it contains a.gitkeepfile and is itself added to.gitignore. - Run tests by
make test→.out/test -v. - Clean up the results of the last two actions on
make clean→git clean -fdx out.
Here's what happened so far:
.PHONY: all test out/lib: lib.h gcc -o out/lib lib.h out/test: test.c lib.h debug.h gcc -o out/test test.c all: out/lib out/test test: out/test ./out/test -v clean: git clean -fdx out Problem 1: the make command only creates out/lib . However, make test works for it: first compiles out/test , then runs it.
UPD: fixed by setting the target all: ... before out/lib and out/test . Now both are going. However, for test: ... this is not required, the goal described earlier is fully recognized. I still do not understand the logic.
Problem 2: the development environment (CLion with the Makefile plugin) underscores the red details for out/lib and out/test with the message "Unresolved prerequisite" and suggests making "Create Rule". I don’t understand why files from the disk should be declared as targets, but I won’t do make lib.c
What am I doing wrong? I met make a couple of hours ago, do not hesitate to explain the most basic things.