Help with Simple Multi-Level Makefile (Extremely New at Makefile)

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with Simple Multi-Level Makefile (Extremely New at Makefile)
# 1  
Old 03-09-2011
Help with Simple Multi-Level Makefile (Extremely New at Makefile)

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:

Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code provided compiles and do not need to be checked so I won't put them here. I'm just having trouble with the makefiles themselves.

=====

The directory tree you will be working with has the following root:

makefile_assignment/: <== You are here.

The directory "makefile_assignment/" contains the following four
subdirectories:

bin/ c/ cpp/ java/

Except for "makefile_assignment/bin/", each subdirectory above
represents a subtask. Be aware that there are further subtasks in
"C and SPARC assembly subtask" and "C++ and archiving subtask"! These subtasks
will be described before the rest of "Makefile task", because "Makefile task"
depends on all of them as subtasks.

=====
BEGIN: C subtask
=====

The directory "makefile_assignment/c/" contains a C header file, "functions.h",
and a single C file, "main.c", in addition to one subdirectory:

cfiles/

=====
BEGIN: C dependencies subtask
=====

The directory "makefile_assignment/c/cfiles/" contains the following C source
files:

factorial.c fibonacci.c hanoi.c print_string.c sum_4_nums.c summation.c

For this subtask ("C subtask"), you must write a Makefile to do the following:

default target:

1. Compile all source files into object code files.

2. Copy all object code files into the parent directory.

clean target:

1. Delete all object code files.

2. Delete all core dumps.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: C dependencies subtask
=====

For this subtask ("C subtask"), you must write a Makefile to
do the following:

default target:

1. "make" the "cfiles/" directory contents.

2. Compile the source file in this directory, "main.c", into an object
code file.

3. Link all object code files into a executable named "c.exe".
Remember that the "C dependencies subtask" creates object files on which
"main.c" depends.

4. Copy "c.exe" into the directory "makefile_assignment/bin/".

clean target:

1. Clean the "cfiles/" directory.

2. Delete all object code files in this directory.

3. Delete all core dumps in this directory.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: C subtask
=====

=====
BEGIN: C++ and archiving subtask
=====

The directory "makefile_assignment/cpp/" contains a C++ header file, "main.h",
and a single C++ file, "main.cpp", in addition to a lone subdirectory:

lib/

=====
BEGIN: Archiving subtask
=====

The directory "makefile_assignment/cpp/lib/" contains the following C++ source
and header files:

factorial.h sum_4_numbers.h summation.h
factorial.cpp sum_4_numbers.cpp summation.cpp

For this subtask ("Archiving subtask"), you must write a Makefile to do the
following:

default target:

1. Compile all source files into object code files.

2. Using the archiver "ar", archive the object code files into an
archive named "libFunctions.a".

clean target:

1. Delete the archive "libFunctions.a".

2. Delete all object code files.

3. Delete all core dumps.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: Archiving subtask
=====

For this subtask ("C++ subtask"), you must write a Makefile to do
the following:

default target:

1. "make" the "lib/" directory contents.

2. Compile the source file in this directory, "main.cpp", into an
object code file.

3. Link all object code files into a executable named "cpp.exe".
Remember that the "Archiving subtask" creates an archive on which
"main.cpp" depends.

4. Copy "cpp.exe" into the directory "makefile_assignment/bin/".

clean target:

1. Clean the "lib" directory.

2. Delete the object code files in this directory.

3. Delete all core dumps in this directory.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: C++ and archiving subtask
=====

=====
BEGIN: Java subtask
=====

The directory "makefile_assignment/java/" contains a single Java source file,
"Main.java", and no subdirectories.

For this subtask ("Java subtask"), you must write a Makefile to do the
following:

default target:

1. Compile the Java source file in this directory, "Main.java", into a
Java class file.

2. Copy "Main.class" into the directory "makefile_assignment/bin/".

clean target:

1. Delete the Java class files in this directory.

2. Delete all core dumps in this directory.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: Java subtask
=====

This is the rest of "Makefile task", which has you producing yet another
Makefile to tie all the subtasks together. This Makefile must be capable of
carrying out the following:

default target:

1. "make" the targets "c", "cpp", and "java".

c target:

1. "make" the contents of the directory "makefile_assignment/c/".

cpp target:

1. "make" the contents of the directory "makefile_assignment/cpp/".

java target:

1. "make" the contents of the directory "makefile_assignment/java/".

clean target:

1. Clean the "c/" directory.

2. Clean the "cpp/" directory.

3. Clean the "java/" directory.

4. Delete all executables in the "bin/" directory.

5. Delete all core dumps in the "bin/" directory.

new target:

1. "make" the "clean" target.

2. "make" the "default" target.

=====
END: Makefile task
=====


2. Relevant commands, code, scripts, algorithms:

Won't be providing the .c, .cpp, .java files as they all compile just fine.

3. The attempts at a solution (include all code and scripts):

makefile for /cfiles
Code:
OBJS = factorial.o fibonacci.o hanoi.o print_string.o sum_4_nums.o summation .o

default: C_Subtask.o
cp factorial.o ..
cp fibonacci.o ..
cp hanoi.o ..
cp print_string.o ..
cp sum_4_nums.o ..
cp summation.o ..

C_Subtask.o: $(OBJS)
gcc -o C_Subtask.o -c $(OBJS)

factorial.o: factorial.c
gcc -c factorial.c

fibonacci.o: fibonacci.c
gcc -c fibonacci.c

hanoi.o: hanoi.c
gcc -c hanoi.c

print_string.o: print_string.c
gcc -c print_string.c

sum_4_nums.o: sum_4_nums.c
gcc -c sum_4_nums.c

summation.o: summation.c
gcc -c summation.c

clean:
rm *.o core

new:
make default
make clean


makefile for /c
Code:
default: c.exe
cp c.exe makefile_assignment/bin/

c.exe: C_Subtask.o main.o
gcc -c main.o

C_Subtask.o:
cd ./cfiles ; make C_Subtask.o

main.o: main.c functions.h
gcc -c main.c

clean:
rm *.o core
cd ./cfiles ; make clean

new:
make clean
make default

makefile for /lib
Code:
OBJS=factorial.o sum_4_numbers.o summation.o

default: Archiving_subtask.o

Archiving_subtask.o: $(OBJS)
g++ -c $(OBJS)
ar rcs libFuntions.a $(OBJS)

factorial.o: factorial.cpp factorial.h
g++ -c factorial.cpp

sum_4_numbers.o: sum_4_numbers.cpp sum_4_numbers.h
g++ -c sum_4_numbers.cpp

summation.o: summation.cpp summation.h
g++ -c summation.cpp

clean:
rm *.o core libFunctions.a

new:
make default
make clean

makefile for /cpp
Code:
default: cpp
cp cpp ~/makefile_assignment/bin/

cpp: Archiving_subtask.o main.o
g++ -c main.o

Archiving_subtask.o:
cd ./lib ; make Archiving_subtask.o

main.o: main.cpp main.h
g++ -c main.cpp

clean:
rm *.o core
cd ./lib ; make clean

new:
make default
make clean

makefile for /java
Code:
default: java
cp Main.class makefile_assignment/bin

java: Main.class

Main.class: Main.java
javac Main.java

clean:
rm *.class core

new:
make default
make clean

makefile for /makefile_assignment
Code:
TYPES=c.exe cpp.exe java.exe

default: $(TYPES)

c.exe:
make -C c

cpp.exe:
make -C cpp

java.exe:
make -C java

clean:
rm -f *.o *~ *.exe core
cd ./c ; make clean
cd ./cpp ; make clean
cd ./java ; make clean

new:
make default
make clean

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

University of San Diego, California (UCSD)
La Jolla, San Diego
USA
Professor Gary Gillespie
CSE80
ieng6.ucsd.edu/~cs80w/UCSD_CSE_80_-_WI_2011/Welcome.html

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 Neo; 03-09-2011 at 05:47 AM..
# 2  
Old 03-09-2011
Moderator's Comments:
Mod Comment Thread Closed by Request of OP
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Makefile help

I am creating a make file, but i keep getting an error when i try to run it with the following code: make foo . make $(EXE) i get EXE: command not found make: `foo' is up to date. make: Nothing to be done for `.'. make: *** No rule to make target `make'. Stop. Here is my... (6 Replies)
Discussion started by: football12345
6 Replies

2. Shell Programming and Scripting

Simple Makefile for LaTeX

I create figures using Gnuplot, but I use terminal epslatex, which produces a .tex file as output. I then latex this .tex file which creates are .dvi file, which I then convert to .ps and finally to an .eps file. Anyway here's what I'm doing in steps gnuplot plot.gplt (this writes out... (2 Replies)
Discussion started by: lost.identity
2 Replies

3. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

4. Programming

[Makefile] nothing to be done for 'all'

hello, I have a firts makefile who call others makefile. for this i use: $ make -f linux.mak and output his: $ make -f linux.mak all make -C DerelictAL all PLATFORM=linux make: Entering directory `/home/builder/rpmbuild/SOURCES/derelict2-20100407/DerelictAL' make: Nothing to be done for... (2 Replies)
Discussion started by: bioinfornatics
2 Replies

5. Programming

makefile help

Hi all, I'm new to make files . I'm writing a make file to compile and create .so files. i've 20 .cpp files. I want to compile one file at a time and then i've to create 1 .so for each file that i compiled. for eg: list.mk is having all the 20 .spp files. name = a.cpp name =+... (2 Replies)
Discussion started by: vij_krr
2 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. Programming

Simple Makefile Problem (with a dependency)

Hi all, I have 4 '.cpp' files and 1 header files: Tools.cpp Code1.cpp Code2.cpp Code3.cpp and Tools.hh Now all Code1.cpp, Code2.cpp, Code3.cpp use functions stored in Tools.cpp. Currently, what I do to compile all of them is using this simple shell script: (1 Reply)
Discussion started by: monkfan
1 Replies

8. Programming

Makefile very simple question.

Hi I tried many times and I dont know what the he... is going on. Problem: I hava in /home/marcin/c1_menu/ this file: menu_item_data.c I want to compile this file. so I tried something like this CC=gcc LIBS=-lmenu -lncurses RM=rm BINS=menu_item_data %: %.o ${CC} -o $@... (1 Reply)
Discussion started by: marcintom
1 Replies

9. Shell Programming and Scripting

Is there any way to set env variable in top level Makefile and unset when done

Hello I have compilation directory structure the top level Makefile is the one that contains all the sub directories I want to set in this Makefile env variable say : setenv OPTIMIZATION_LEVEL "1" and when all the sub directories done compiling it will set this variable to different lavel... (0 Replies)
Discussion started by: umen
0 Replies

10. Shell Programming and Scripting

makefile help

i'd like to execute a particular command if i'm running gcc version 3.2 for instance. my approach is as follows: GCC_VERSION := `gcc --version | head -1` suppose the result of `gcc --version | head -1` was gcc 3.2 then i'd like to perform the following: ifeq ($(GCC_VERSION), "gcc 3.2")... (1 Reply)
Discussion started by: pieter023
1 Replies
Login or Register to Ask a Question