C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2008, 10:48 AM   #1
Registered User
 
Join Date: May 2008
Posts: 11
Simple GNU Makefile

This is a simple 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
The problem is it won't run the commands of the target $(TESTS).

What am I missing?
OriginalCopy is offline   Reply With Quote
Old 05-14-2008, 10:52 AM   #2
Senior software engineer
 
brewbuck's Avatar
 
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   Reply With Quote
Old 05-14-2008, 11:04 AM   #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   Reply With Quote
Old 05-14-2008, 11:37 AM   #4
Senior software engineer
 
brewbuck's Avatar
 
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   Reply With Quote
Old 05-14-2008, 12:14 PM   #5
Registered User
 
Join Date: May 2008
Posts: 11
Thanks a lot.

What should I look for in the manual, in regards to $(TEST_SRCS:.c=)?
OriginalCopy is offline   Reply With Quote
Old 05-14-2008, 12:17 PM   #6
Registered User
 
Join Date: May 2008
Posts: 11
Never mind, it is in 4.14 Generating Prerequisites Automatically
OriginalCopy is offline   Reply With Quote
Reply

Tags
gnu make

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 02:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22