In: Computer Science
in unix(bash)
Write a Makefile with a recipe which can be used to compile myprog.c into myprog. Be sure to indicate that "myprog" depends on myprog.c!
SOLUTION:
The following solution has been implemented in such a way that the Makefile specifies that the Output "myprog" depends on the file to be compiled being "myprog.c".
Makefile
# Select the Compiler
COMPILER = gcc
# Select the flags
FLAGS = -g -Wall
# Select the File
FILE = myprog
# Describe the Target Functionality
all: $(FILE)
$(FILE): $(FILE).c
$(COMPILER) $(FLAGS) -o $(FILE) $(FILE).c
clean:
$(RM) $(FILE)
*** Target "clean" is not mangatory***
SCREENSHOT:
Note:
The Makefile has 2 targets, i) all ii) clean
Since all comes first it will be executed first by default, unless a target for execution is specified.
You can either issue the command "make" or "make all".
The "clean" target can be executed using the command "make clean".
Hope this helps..!