a question on makefile
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > a question on makefile




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    a question on makefile  
Liang


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-20-04 07:47 AM

Hi,

I'm not sure if this is the right place for discussing makefile. If it's not
correct, would u let me know the right news group? thanks.

I'm facing headache when I try to write a gnu style makefile for a project.
Due to the existing source directory structure of the project, the makefiles
have to be saved away from the source files, and the interim files and
output files need to be saved in a sub-dir of the makefile. The project
source file directory structure looks like:

/pjt_root/
/part1/
/file1.c
/file1.h
/part2/
/file2.c
/file2.h
/config/
/makefile
/debug/
/file1.o
/file2.o
/a.out
/release/
/file1.o
/file2.o
/a.out

If the target is for debug purpose, all .o and .out will be in 'debug'
purpose. The same rule applies to 'release'.

The makefile looks like:

SRC= part1/file1.c part2/file2.c
$OBJECTS:= $(foreach src, $(SRC),  $(basename $(notdir $(src))).o)

ALL_Debug: debug/a.out
OBJECTS_Debug:=$(foreach obj, $(OBJECTS), debug/$(obj))
debug/a.out: $(OBJECTS_Debug)
$(CC) $(CFLAGS) -o $@ $<

%.o:%.c
$(CC) $(CFLAGS) -c $<

But the problem comes. 'make' does NOT know how to make debug/file1.o
debug/file2.o.

Do I need to change the suffix rule as "$(target_folder)/%.o:%.c", and
specify VPATH= $(foreach src, $(SRC), $(dir $(src))) for c files at the same
time? But this approach not only looks awkward, but also error-prone. And
the rule doesn't work well.

May u kindly point out a better solution for this scenario? Thanks.

Regards,
Liang







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:10 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register