Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The goal of this problem is to write a Makefile for compiling a C project. The p

ID: 3796140 • Letter: T

Question

The goal of this problem is to write a Makefile for compiling a C project. The project structure is depicted in Figure 1. The source folder contains all the c files (.c files). The object folder contains the object files generated after the compilation (.o files) and the header folder contains all the header files of the project (.h files).

The final program will provide 4 options in a shell to the user for interaction as illustrated in figure 2. Selecting option 1 will compute the greatest common divisor of 2 integers. Option 2 launches the routine to compute the factorial of an integer provided by the user. The third choice gives the greatest number among three integers and the fourth option print all prime numbers smaller than a given integer. Each option calls a subroutine implemented in a different C file. The main C file will includes a header file for each of the subroutines.

Provide a Makefile for automatic compilation of the whole project. The Makefile places the object files in the object folder and the executable in the working directory. The macro all in the Makefile should clear the object directory.

Explanation / Answer

///Command Line Argument for the Compile Target Name:


# compile the hello program with spaces instead of Tabs
# the compiler to use
CC = clang
  
# compiler flags:
# -g adds debugging info to the executable file
# -Wall turns on most, but not all, compiler warnings
  
CFLAGS = -g -Wall
  
#files to link:
LFLAGS = -lcs50
  
# require that an argument be provided at the command line for the target name:
TARGET = $(target)
  
all: $(TARGET)
$(TARGET): $(TARGET).c ; $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c $(LFLAGS)

////Passing Compilation target name as a command Line argument----
  
make TARGET=goodbyeee.c


# Compile an executable named yourProgram from yourProgram.c
  
all: yourProgram.c
<TAB>gcc -g -Wall -o yourProgram yourProgram.c

# compile the hello program with spaces instead of Tabs
  
# the compiler to use
CC = clang
  
# compiler flags:
# -g adds debugging info to the executable file
# -Wall turns on most, but not all, compiler warnings
CFLAGS = -g -Wall
  
#files to link:
LFLAGS = -lcs50
  
# require that an argument be provided at the command line for the target name:
TARGET = hello
  
all: $(TARGET)
$(TARGET): $(TARGET).c ; $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c $(LFLAGS)


////General Purpose Makefile Template:


# the compiler to use
CC = clang

# compiler flags:
# -g adds debugging info to the executable file
# -Wall turns on most, but nt all, compiler warnings
CFLAGS = -g -Wall
  
#files to link:
LFLAGS = -lcs50
  
# the name to use for both the target source file, and the output file:
TARGET = hello
  
all: $(TARGET)
  
$(TARGET): $(TARGET).c
   $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c $(LFLAGS)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote