On Fri, Mar 15, 2002 at 12:31:11AM -0600, mcolivier wrote:
> hello.
> I'm attempting to work with MySQL, and I'm reading stuff about C API or DBI 
> (I forget the acronyms). Anyway, there's a section on my reading about 
> creating a makefile to build programs. It looks more complicated than just 
> typing out 'gcc' in front of the source file name.

florin at bear:/usr/local/src/linux-2.4-xfs$ find . -name "*.c" | wc -l
   4716
florin at bear:/usr/local/src/linux-2.4-xfs$ find . -name "*.o" | wc -l
    641

Guess what? When you type make in the linux directory, it goes about and
compiles the 641 out of 4716 .c files. Do you think you can "simply" do
that with gcc $sourcefile?

>                                                    The example given is as 
> follows: 
> =====================================
> # excerpt from book MySQL, by Paul DuBois, (2000) page 224
> CC=gcc
> INCLUDES = -I/usr/local/include/mysql  #-I is capital i
> LIBS = L/usr/local/lib/myql -lmysqlclient
> 
> all: myclient
> 
> main.o: main.c myclient.h
> 	$(CC) -c $(INCLUDES) main.c
> aux.o: aux.c myclient.h
> 	$(CC) -c $(INCLUDES) aux.c
> 
> myclient: main.o aux.o
> 	$(CC) -o myclient main.o aux.o $(LIBS)
> 
> clean:
> 	rm -f myclient main.o aux.o
> =======================================
> My question is, I don't know what the author is saying. Where did main.o and 
> aux.o come from? What is CC=gcc, and why is it shown like this? Finally, what 
> is make, what is makefile, and what's the difference between the two? I have 
> a commercial C/C++ package (Watcom) which does the make stuff via a button. 
> If I do a makefile on this (which runs on a Windows platform) will resulting 
> program work on a Linux platform? 

When you "simply" compile a source file you get an object file (or some
errors). The convention is to replace the extension with ".o" unless
told otherwise.

CC=gcc it's just a variable assignment. If you move this to a different
platform, you can say CC=wcc and compile it with... Watcom.

"make" is an expert system that maintains groups of files described by
rules written in files called makefiles. The rules are of form:
   A: B C D
      prepare_A_from_B_C_D
The rules are invoked whenever the dependents are older than the objects
they are dependent on (as observed by comparing timestamps).



Now the only way to answer all those questions in a coherent and complete 
manner is to go to a bookstore and purchase a book about software development
on UNIX/Linux.

Also note that Watcom compilers come with wmake which does the same
thing as make.

Cheers,
florin

-- 

"If it's not broken, let's fix it till it is."

41A9 2BDE 8E11 F1C5 87A6  03EE 34B3 E075 3B90 DFE4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://shadowknight.real-time.com/pipermail/tclug-list/attachments/20020315/c0f03168/attachment.pgp