![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 11
| Simple GNU Makefile Code: CFLAGS = -Wall
CC = gcc
TESTS := $(wildcard encryption/*.c)
tests: $(TESTS)
echo "TESTS are compiled under tests/"
echo "TODO: run the testunit"
# echo $?
$(TESTS):
echo $@
# echo $(CC) $(CFLAGS) -DTEST -o tests/$@ $@.c
What am I missing? |
| OriginalCopy is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Think about what $(TESTS) expands to. For instance, say you have encryption/a.c and encryption/b.c. Then the rule will expand: encryption/a.c encryption/b.c: some commands... There are no dependencies listed. The files exist. Nothing needs to be done, so make does nothing. |
| brewbuck is offline | |
| | #3 |
| Registered User Join Date: May 2008
Posts: 11
| Oh I am so dumb. How could I make such that it replaces each .c by "tests/<filename>" and create a target for it automagically, instead of me having to Code: encryption/a.c:
$(CC) ...
|
| OriginalCopy is offline | |
| | #4 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Try something like this: Code: CFLAGS = -Wall
CC = gcc
TEST_SRCS = $(wildcard encryption/*.c)
TESTS = $(TEST_SRCS:.c=)
.PHONY: tests
tests:
$(MAKE) CFLAGS="$(CFLAGS) -DTEST" $(TESTS)
|
| brewbuck is offline | |
| | #6 |
| Registered User Join Date: May 2008
Posts: 11
| Never mind, it is in 4.14 Generating Prerequisites Automatically |
| OriginalCopy is offline | |
![]() |
| Tags |
| gnu make |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problems with makefile | bartleby84 | C Programming | 4 | 02-16-2009 09:02 AM |
| build GNU GCC 4.3.1 | MarkZWEERS | Tech Board | 8 | 08-10-2008 10:43 AM |
| Gnu Makefile help | tjrkz | Linux Programming | 1 | 05-19-2005 01:56 AM |
| Binary Search Trees Part III | Prelude | A Brief History of Cprogramming.com | 16 | 10-02-2004 03:00 PM |
| Simple makefile Problem | kishorepalle | Tech Board | 5 | 07-28-2004 04:12 PM |