Sponsored Content
Full Discussion: Using the Make command
Homework and Emergencies Homework & Coursework Questions Using the Make command Post 302566413 by galanom on Thursday 20th of October 2011 10:14:10 AM
Old 10-20-2011
Due to strict policies regarding cheating, I can't tell you exactly, but I'll give an example with the undergrad project I made for a course about data structures.

I had the files
Code:
binsearch.c  
bubble.c  
csbubble.c  
heap.c  
hybrid.c  
intsearch.c  
main.c  
Makefile  
quick.c  
sel.c

All .c files but main.c were sorting and finding algorithms. The main.c was obviously the main program which took the measurements and the Makefile is the, well, makefile.

I wrote this:
Code:
CC    = gcc
DEBUG    = NO_DEBUG
CFLAGS    = -ggdb -std=c99 -pedantic -Wall -W -Wshadow -Wpointer-arith -Wconversion -D$(DEBUG)
OBJ    = bubble.o csbubble.o quick.o heap.o hybrid.o binsearch.o intsearch.o sel.o

all:    $(OBJ)
    $(CC) $(CFLAGS)  -lm -o main main.c $(OBJ)

clean:
    rm -f        \
    Makefile~    \
    bubble.c~    \
    bubble.o    \
    csbubble.c~    \
    csbubble.o    \
    quick.c~    \
    quick.o        \
    heap.c~        \
    heap.o        \
    hybrid.c~    \
    hybrid.o    \
    binsearch.c~    \
    binsearch.o    \
    intsearch.c~    \
    intsearch.o    \
    sel.c~        \
    sel.o        \
    main.c~        \
    main        \
    core

The CC variable is the compiler name. Set it to cc or gcc.
The DEBUG will set a define flag, forget it
the CFLAGS are the options to the compiler. You will have your own. The most common ones are -W or -Wall, -ggdb if you want debug symbols, --std=c99 sets the language dialect (forget it), -pedantic rejects extensions (like gnu89), the -D(DEBUG) passes the aforementioned DEBUG symbol which you won't use, and the other -Wx flags just forget them.
OBJ variable containes ALL the object code binaries that the main program needs, ie all intermediary files of compilations of bubble.c, csbubble.c etc. ATTENTION: If you forget to include even a single object file, your make will fail! Include all your .c files but main.c with the .o extension, as I did.

Let's focus at the rest lines:
The first field is the target. It's called "all", followed by a colon. If you type "make all", this target will be activated. After a TAB, there is the list of all dependencies. There you will put ANY object file your program will need, that is the $OBJ (either type $OBJ or $(OBJ) doesn't matter).

After these dependencies are satisfied, the next lines will execute, up until the next target.
Make will find no bubble.o So it will compile bubble.c with $CFLAGS to get bubble.o. Then will find no csbubble.o, and it will compile csbubble.c, etc. There is NO NEED to put a target for each .c file, as many students do. Make knows how to invoke gcc.

When Make finishes, it will proceed with the next line.
There it calls the compiler ($CC) with $CFLAGS to compile main.c and link it against the object files ($OBJ) and the math library (-lm, you won't need that). The -o main means "the output will be called main. If you don't specify it, it defaults to a.out (assembler output, for the history).

Next will find the clean: target and stop.

If you invoke make as "make clean", then this target will be fired.
Here I delete all backup files (*~) all object files (*.o), the main executable and core dump (forget this).
You could just put "rm -f *.o helloworld"

That's all folks!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

make command

Dear Guys , Kindly note that i have sun solaries 8 intel machine . i installed apache and it is working fine . i am installing perl5 , MD5 and CGI . but whenever i execute the commands , make , make test and make install i get error message : not found # make make: not found also i... (2 Replies)
Discussion started by: tamemi
2 Replies

2. UNIX for Dummies Questions & Answers

make command

hi i tried to search for the "make" command but to no avail. this is what happens: when i try to type the "make" command, it prompt me the error " csh:make:not found ***error code 1 make:Fatal error: command fail for target 'all' " i have just freshly install solaris 9 on my server.... (8 Replies)
Discussion started by: legato
8 Replies

3. Solaris

C compiler and make command

Hey Guys.... I installed Solaris 10 (10/08) on _X86 platform, I need install any software of load balance. I find the pen-0.18.0-sol10-x86-local software. I cant finish the install process , i dont find the make command, I think this command is associated to the C compiler process. But... (2 Replies)
Discussion started by: aggadtech08
2 Replies

4. Solaris

make command failure

Hi After downloading and compiling new ntp source for Solaris 10 I used the make command on the ntp directory. I received the following output: bash-3.00# make (bk version) >/dev/null 2>&1 && \ cd . && \ x=`bk -R prs -hr+ -nd:I: ChangeSet` && \ y=`cat version... (2 Replies)
Discussion started by: shaife720
2 Replies

5. UNIX for Advanced & Expert Users

problem with make command

hi guys would u clarify me how to use make command , how to write rules of make command and to execute . (1 Reply)
Discussion started by: chinakampalli p
1 Replies

6. Solaris

make command problem

hi, I'was trying to compile a simple game , just for testing the system, but the make command gave me problems, so I read that it was best to have a gnu make package installed so I made pkgrm SUNWgmake and installed the gnu make from sunfreesoftware, the problem is that now when I run make... (9 Replies)
Discussion started by: freeware
9 Replies

7. Solaris

how to make all of this in one command

dears what i need to make is cp -irp file_name filename tar cvf filename.tar filename gzip filename.tar in one commane using exec it that prossible and how can i do that (4 Replies)
Discussion started by: xxmasrawy
4 Replies

8. Homework & Coursework Questions

Utilizing the Make Command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Compile cpp2html.c to produce cpp2html.o. ( Important: the source code in these files is C, not C++, and so... (8 Replies)
Discussion started by: lamentofking
8 Replies

9. Homework & Coursework Questions

Utilizing the Make Command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: ]Compile cpp2html.c to produce cpp2html.o. ( Important: the source code in these files is C, not C++, and so... (1 Reply)
Discussion started by: bgnaranjo1
1 Replies

10. UNIX for Beginners Questions & Answers

How to make df command?

in RHEL 6.10, how can we make the the df -k return the output without wrapping. And wihout using the df -Pk option. After we patched a Linux server from 6.5 to 6.10: The df -k on RHAT 6.10 it wraps the line for ex: 6.10: /dev/mapper/vgapp01-vendor ... (2 Replies)
Discussion started by: mrn6430
2 Replies
ccmakedep(1)						      General Commands Manual						      ccmakedep(1)

NAME
ccmakedep - create dependencies in makefiles using a C compiler SYNOPSIS
ccmakedep [ cpp-flags ] [ -wwidth ] [ -smagic-string ] [ -fmakefile ] [ -oobject-suffix ] [ -v ] [ -a ] [ -cccompiler ] [ -- options -- ] sourcefile ... DESCRIPTION
The ccmakedep program calls a C compiler to preprocess each sourcefile, and uses the output to construct makefile rules describing their dependencies. These rules instruct make(1) on which object files must be recompiled when a dependency has changed. By default, ccmakedep places its output in the file named makefile if it exists, otherwise Makefile. An alternate makefile may be speci- fied with the -f option. It first searches the makefile for a line beginning with # DO NOT DELETE or one provided with the -s option, as a delimiter for the dependency output. If it finds it, it will delete everything following this up to the end of the makefile and put the output after this line. If it doesn't find it, the program will append the string to the makefile and place the output after that. EXAMPLE
Normally, ccmakedep will be used in a makefile target so that typing 'make depend' will bring the dependencies up to date for the makefile. For example, SRCS = file1.c file2.c ... CFLAGS = -O -DHACK -I../foobar -xyz depend: ccmakedep -- $(CFLAGS) -- $(SRCS) OPTIONS
The program will ignore any option that it does not understand, so you may use the same arguments that you would for cc(1), including -D and -U options to define and undefine symbols and -I to set the include path. -a Append the dependencies to the file instead of replacing existing dependencies. -cccompiler Use this compiler to generate dependencies. -fmakefile Filename. This allows you to specify an alternate makefile in which ccmakedep can place its output. Specifying "-" as the file name (that is, -f-) sends the output to standard output instead of modifying an existing file. -sstring Starting string delimiter. This option permits you to specify a different string for ccmakedep to look for in the makefile. The default is "# DO NOT DELETE". -v Be verbose: display the C compiler command before running it. -- options -- If ccmakedep encounters a double hyphen (--) in the argument list, then any unrecognized arguments following it will be silently ignored. A second double hyphen terminates this special treatment. In this way, ccmakedep can be made to safely ignore esoteric compiler arguments that might normally be found in a CFLAGS make macro (see the EXAMPLE section above). -D, -I, and -U options appearing between the pair of double hyphens are still processed normally. SEE ALSO
cc(1), make(1), makedepend(1), ccmakedep(1). AUTHOR
ccmakedep was written by the X Consortium. Colin Watson wrote this manual page, originally for the Debian Project, based partly on the manual page for makedepend(1). X Version 11 imake 1.0.2 ccmakedep(1)
All times are GMT -4. The time now is 05:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy