Using the Make command


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Using the Make command
# 1  
Old 10-11-2011
Using 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:

File hello.h

Code:
#include <stdio.h>

File main.c

Code:
#include "hello.h"
 
main()
{
    printhello();
    credits();
}

File print.c

Code:
#include "hello.h"
 
void printhello()
{
    printf ("Hello world!\n");
}

File credits.c

Code:
#include "hello.h"
 
void credits()
{
    printf ("\n(This ridiculous example of overkill was created for CptS 224.)\n");
}

(6 points) Write a Makefile that will correctly compile subparts "main.o", "print.o", "credits.o" and both "make helloworld" command and "make" commmand will assemble a program called "helloworld" from those parts. The dependencies should be correct so that if any of the 4 files is updated, the correct pieces will get rebuilt.
(1 point) Your Makefile should be written so that "make clean" command will remove program "helloworld", "*.o" and any other executables which were created.


those are the two i need help with the most. It doesnt seem like i am doing it correctly

2. Relevant commands, code, scripts, algorithms:

make make clean ls


3. The attempts at a solution (include all code and scripts):
Code:
9:58pm
aaron@aaron-VirtualBox:~/Desktop$ cc -c hello.h

aaron@aaron-VirtualBox:~/Desktop$ cc -c main.c

aaron@aaron-VirtualBox:~/Desktop$ cc -c print.c

aaron@aaron-VirtualBox:~/Desktop$ cc -c credits.c

aaron@aaron-VirtualBox:~/Desktop$ cc hello.h main.o print.o credits.o -o helloworld

aaron@aaron-VirtualBox:~/Desktop$ ./helloworld

Hello world!



(This ridiculous example of overkill was created for CptS 224.)

aaron@aaron-VirtualBox:~/Desktop$



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Washington State University, Washington, US, Bakken, CS224 CptS 224: Homework 3 - Make

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by pludi; 10-11-2011 at 03:50 AM..
# 2  
Old 10-13-2011
Makefile Tutorial Should be able to help with no problems.
# 3  
Old 10-15-2011
Maybe a short explanation will get you up to speed faster.

The "make" utility is intended for repetitive tasks (like compiling/linking). It works rule-based. In its input file there is a collection of such rules laid out.

Rules consist of target files, source files and actions. When a source file is changed (=has a time stamp younger than the target file) the action is carried out. Usually carrying out the action creates the target file. The big advantage of using a make-file instead of a script with all the compiler/linker commands is that "make" will skip all the files which are already up to date and only execute the rules necessary to update the files which aren't. It will also stop if one of the commands carried out will return a non-zero error level (compilers do that when encountering severe errors).

You should now be able to understand the manual and work out your little makefile.

I hope this helps.

bakunin
# 4  
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!
# 5  
Old 10-24-2011
Welcome to this site, I am a new member since last night. Hope we can share interesting insights as we get along in this forum.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question