0% found this document useful (0 votes)
1 views

Weekly Report 13

The weekly report details practice in shell scripting, including examples like a tax calculator and a prime factorization script. It also covers the concept of Makefile, which automates the building of programs by managing dependencies and simplifying the compilation process. The report explains the rules and directives used in Makefile to efficiently handle complex projects.

Uploaded by

Shah Henisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Weekly Report 13

The weekly report details practice in shell scripting, including examples like a tax calculator and a prime factorization script. It also covers the concept of Makefile, which automates the building of programs by managing dependencies and simplifying the compilation process. The report explains the rules and directives used in Makefile to efficiently handle complex projects.

Uploaded by

Shah Henisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Weekly Report 13 (eInfochips-ASIC)

Shah Henisha
Task 1: We did practice of shell scripting.

Examples:

Tax Calculator

#!/bin/bash

echo -n "enter cost:"

read cost

echo -n "enter tax rate in %:"

read tax

tax=$(echo "$cost*$tax/100"|bc)

total=$(echo "$cost+$tax"|bc)

echo "tax: $tax"

echo "total cost with tax: $total"

Prime Factorization – Have the user enter a number and find all Prime Factors (if there
are any) and display them

#!/bin/bash

# Function to calculate the prime factors of a number


prime_factors() {
n=$1
factor=2

echo "Prime factors of $n: "

# Check for factors starting from 2


while [ $factor -le $n ]; do
while [ $(($n % $factor)) -eq 0 ]; do
echo -n "$factor "
n=$(($n / $factor))
done
((factor++))
done

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.

How Dependencies Work?

A Makefile rule follows this structure:

target: dependencies

command to build target

• Target → The file that needs to be created or updated.

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

Why Dependencies Matter?


• Avoids unnecessary recompilation → Only modified files are recompiled.

• Saves time → No need to compile everything every time.

• Manages complex projects efficiently → Ensures correct build order.


Rules for Makefile:

1. Explicit Rules

You manually specify how to build each file.

2. Implicit Rules
Make automatically know how to compile files into .o files.

3. Phony Rules

Used for commands like cleaning temporary files.

Suffix Rules in Makefile:

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.

Syntax of a Suffix Rule

.SUFFIXES: .c .o # Declares the suffixes used in rules

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

You might also like