Weekly Report 13
Weekly Report 13
Shah Henisha
Task 1: We did practice of shell scripting.
Examples:
Tax Calculator
#!/bin/bash
read cost
read tax
tax=$(echo "$cost*$tax/100"|bc)
total=$(echo "$cost+$tax"|bc)
Prime Factorization – Have the user enter a number and find all Prime Factors (if there
are any) and display them
#!/bin/bash
echo ""
}
# Main script
echo "Enter a number to find its prime factors: "
read num
if [ $num -le 1 ]; then
echo "Please enter a number greater than 1."
else
prime_factors $num
fi
Task 2: We were told to study about makefile.
Makefile
Makefile is a tool that helps with automatically building programs, mainly on Unix and Linux
systems. If a program has multiple parts (called modules), compiling them manually can be
tedious. Makefile simplifies this process by specifying how and when different parts should be
compiled or updated.
Why makefile?
Compiling the source code files can be tiring, especially when you must include several source
files and type the compiling command every time you need to compile. Makefiles are the solution
to simplify this task.
The make command allows you to manage large programs or groups of programs.
Dependencies in Makefile:
In Makefile, dependencies define the relationship between files to determine which files need to
be recompiled when changes occur. Dependencies help make decide which parts of the program
should be updated.
target: dependencies
• Dependencies → The files required to create the target. If any of these change, make will
rebuild the target.
• Command → The command to execute when the target is out-of-date.
1. Explicit Rules
2. Implicit Rules
Make automatically know how to compile files into .o files.
3. Phony Rules
Suffix rules in Makefile allow defining general patterns for building files. These rules
automatically tell make how to convert one file type into another without explicitly writing
commands for each file.
.c.o:
gcc -c $< -o $@
Makefile – Directives:
Directives in a Makefile are special instructions that control how make processes the file. They are
different from rules because they define behavior, set variables, and include other files rather than
specifying how to build targets.