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
lmfsetup(8)						      System Manager's Manual						       lmfsetup(8)

Name
       lmfsetup - License Management Facility PAK registration script

Syntax
       /etc/lmfsetup [ template ]

Description
       The  script allows you to register data supplied by a Product Authorization Key (PAK).  The script prompts you for the data associated with
       each of the fields on a PAK.  When all the data has been entered, the License Management Facility (LMF) ensures there are  entries  against
       all  the mandatory fields, and that the Checksum validates all the license data.  If the data has been entered correctly, the PAK is regis-
       tered in the License Database.  If the data has been entered incorrectly, the appropriate error message is displayed and you are given  the
       opportunity to re-enter the data.

       The template option allows you to register license data from templates in A template containing a partially complete PAK is created by some
       products as part of their installation process.	The script only prompts you for data on the fields that are empty in the template.  If the
       script cannot find the specified template in it searches the current directory.

       The  script  is	provided as an alternative to the command.  This displays a template, which includes the fields on the PAK, and invokes an
       editor so that you can add the license data to the appropriate field.  The command also allows errors to be corrected without having to re-
       enter all the data.

See Also
       lmf(8)
       Guide to Software Licensing

																       lmfsetup(8)
All times are GMT -4. The time now is 05:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy