How to make Makefile?

This commit is contained in:
2024-02-04 20:19:52 +05:30
parent ebafca3461
commit dee48d5d1b
8 changed files with 257 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
TARGET: exemath
exemath: main.o libcalc.a
gcc main.o -o exemath -L . libcalc.a -lm
libcalc.a: trig_math/trig_math.o common_math/common_math.o complex_math/complex_math.o
ar rs libcalc.a common_math/common_math.o complex_math/complex_math.o trig_math/trig_math.o
common_math.o: common_math/common_math.c
gcc -c -I common_math common_math/common_math.c -o common_math/common_math.o
complex_math.o: complex_math/complex_math.c
gcc -c -I complex_math complex_math/complex_math.c -o complex_math/complex_math.o
trig_math.o: trig_math/trig_math.c
gcc -c -I trig_math trig_math/trig_math.c -o trig_math/trig_math.o
main.o: main.c
gcc -c -I common_math -I complex_math -I trig_math main.c -o main.o
clean:
rm common_math/common_math.o
rm complex_math/complex_math.o
rm trig_math/trig_math.o
rm main.o
rm libcalc.a
rm exemath

View File

@@ -0,0 +1,44 @@
/*
* =====================================================================================
*
* Filename: common_math.c
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:32:41 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "common_math.h"
#include <stdio.h>
double add (double a, double b){return b + a;}
double sub (double a, double b){return a - b;}
double mul (double a, double b){return a * b;}
double div (double a, double b){
if (b == 0){
printf("divide by zero not allowed\n");
return 0;
}
return a / b;
}
double max (double a, double b){
if(a > b)
return a;
return b;
}
double min (double a, double b){
if(a > b)
return b ;
return a;
}

View File

@@ -0,0 +1,30 @@
/*
* =====================================================================================
*
* Filename: common_math.h
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:33:21 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#ifndef __COMMON_MATH__
#define __COMMON_MATH__
double add (double a, double b);
double sub (double a, double b);
double mul (double a, double b);
double div (double a, double b);
double max (double a, double b);
double min (double a, double b);
#endif /* __COMMON_MATH__ */

View File

@@ -0,0 +1,34 @@
/*
* =====================================================================================
*
* Filename: complex_math.c
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:36:03 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "complex_math.h"
complex_n_t cadd(complex_n_t a, complex_n_t b){
complex_n_t res;
res.re = a.re + b.re;
res.imag = a.imag + b.imag;
return res;
}
complex_n_t csub(complex_n_t a, complex_n_t b){
complex_n_t res;
res.re = a.re - b.re;
res.imag = a.imag - b.imag;
return res;
}

View File

@@ -0,0 +1,30 @@
/*
* =====================================================================================
*
* Filename: complex_math.h
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:36:29 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#ifndef __COMPLEX_MATH__
#define __COMPLEX_MATH__
typedef struct{
double re;
double imag;
} complex_n_t;
complex_n_t cadd(complex_n_t a, complex_n_t b);
complex_n_t csub(complex_n_t a, complex_n_t b);
#endif

View File

@@ -0,0 +1,37 @@
/*
* =====================================================================================
*
* Filename: main.c
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:38:54 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "common_math/common_math.h"
#include "complex_math/complex_math.h"
#include "trig_math/trig_math.h"
#include <stdio.h>
int main(int argc, char **argv){
double res, a = 45.0, b = 90.0;
complex_n_t cres, ca,cb;
res = a + b;
printf("two numbers added = %f\n", res);
printf("sine of %f = %f\n", a, sine(a));
ca.re = 1.0, ca.imag = 2.0;
cb.re = 2.0, cb.imag = 3.0;
cres = cadd(ca, cb);
printf("adding two complex numbers : %f + %f\n", cres.re, cres.imag);
return 0;
}

View File

@@ -0,0 +1,29 @@
/*
* =====================================================================================
*
* Filename: trig_math.c
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:37:35 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include "trig_math.h"
#include <math.h>
double sine(double x){
return sin(x*(PI/180));
}
double cosine(double x){
return cos(x*(PI/180));
}

View File

@@ -0,0 +1,27 @@
/*
* =====================================================================================
*
* Filename: trig_math.h
*
* Description:
*
* Version: 1.0
* Created: 04/02/24 07:37:55 PM IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#ifndef __TRIG_MATH__
#define __TRIG_MATH__
#define PI 3.142
double sine(double x);
double cosine(double x);
#endif