Ask a Question related to UNIX Programming, Design and Development.
-
Suzanne Baker #1
A basic Makefile question
Hi,
I have read through the GNU Make website on the internet, but I am
still unsure of how to create the Makefile for multiple .c files(150
..c files to be exact)
The following is my Makefile for a 3 .c files and one .h file into one
single .exe file:
CFLAGS=
TGT=tt
OBJ=file1.o file2.o file3.o
$(TGT): $(OBJ)
cc $(CFLAGS) $(OBJ) -o $(TGT);
file1.o: file1.c testheader.h
cc -c file1.c;
file2.o: file2.c
cc -c file2.c;
file3.o: file3.c testheader.h
cc -c file3.c;
clean:
rm -f *.o;
The above Makefile is for 3 .c files only. If I want to compile a
total of 150 different .c files, what should I do? Do I really have to
type out the following part for every single .c file?
file1.o: file1.c testheader.h
cc -c file1.c;
I would greatly appreciate it if anyone can tell me a shorter and more
efficient method of compiling and linking all the 150 .c files into
one single .exe file.
Thanks alot in advance for your kind help.
Regards,
Suzanne
Suzanne Baker Guest
-
A Very Basic Question
Yikes! I read a lot of the online discussion and went through all the help documents, but I couldn't find an answer to this very basic question. ... -
very basic question
Hi, I'm still a student and a beginner to Macromedia products. The animations excite me. For me as a beginner, both Director and Flash can do... -
Help with this basic question??
Hello I had a problem, I want to manage some parts of a movie with the F12 function key, but I don?t know how I used this code to other keys but... -
question about installation of GD::Text on cygwin (could be a Makefile q)
Hi For background: I am trying to install a few modules with an environment of Cygwin w/ windows 2000. The module I am stuck on is GD::Text. ... -
basic ASP, ADO question
I am trying to build a simple page in classic ASP code that queries a SQL table based on user input. I have sample code, but it isn't quite what I... -
Eric #2
Re: A basic Makefile question
On 1 Jul 2003 01:16:02 -0700, [email]suz__1@hotmail.com[/email] (Suzanne Baker)
wrote:
Hi Suzanne,>I would greatly appreciate it if anyone can tell me a shorter and more
>efficient method of compiling and linking all the 150 .c files into
>one single .exe file.
The following is a makefile that you might find useful. It has
overhead in that it computes the dependencies at build time using a
few smart tricks. All you have to do is replace the name of the
executable, flags, and libs on the first 3 lines. Place the makefile
in the same directory as your source code and you should be in
business.
I got this makefile from a friend a while back so I'm not sure where
it is from. It was originally for .cpp files but I have replaced
g++/.cpp with gcc/.c in the makefile below (hope it still works!).
Hope it helps,
Eric.
---
EXECUTABLE = program
CPPFLAGS = -ggdb3 -Wall
LIBS = -lpthread
#################################################
CC = gcc
SRCS := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SRCS))
DEPS := $(patsubst %.c,%.d,$(SRCS))
#################################################
all: $(EXECUTABLE)
$(EXECUTABLE): $(DEPS) $(OBJS)
$(CC) -o $(EXECUTABLE) $(OBJS) $(LIBS)
%.d: %.cpp
$(CC) -MM $(CPPFLAGS) $< > $@
$(CC) -MM $(CPPFLAGS) $< | sed s/\\.o/.d/ >> $@
%.d: %.h
$(CC) -MM $(CPPFLAGS) $< > $@
$(CC) -MM $(CPPFLAGS) $< | sed s/\\.o/.d/ >> $@
clean:
-rm $(OBJS) $(EXECUTABLE) $(DEPS) *~
explain:
@echo "--------Some Info--------"
@echo "Executable name: $(EXECUTABLE)"
@echo "Source files: $(SRCS)"
@echo "Object files: $(OBJS)"
@echo "Dependency files: $(DEPS)"
depends: $(DEPS)
@echo "Dependencies updated"
-include $(DEPS)
run: all
./$(EXECUTABLE)
debug: all
gdb $(EXECUTABLE)
clean-emacs:
rm *~
---
Eric Guest



Reply With Quote

