From dee48d5d1b7fad1998719d2e481771d09891cf43 Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Sun, 4 Feb 2024 20:19:52 +0530 Subject: [PATCH] How to make Makefile? --- Makefile_Assignment/Makefile | 26 +++++++++++ Makefile_Assignment/common_math/common_math.c | 44 +++++++++++++++++++ Makefile_Assignment/common_math/common_math.h | 30 +++++++++++++ .../complex_math/complex_math.c | 34 ++++++++++++++ .../complex_math/complex_math.h | 30 +++++++++++++ Makefile_Assignment/main.c | 37 ++++++++++++++++ Makefile_Assignment/trig_math/trig_math.c | 29 ++++++++++++ Makefile_Assignment/trig_math/trig_math.h | 27 ++++++++++++ 8 files changed, 257 insertions(+) create mode 100644 Makefile_Assignment/Makefile create mode 100644 Makefile_Assignment/common_math/common_math.c create mode 100644 Makefile_Assignment/common_math/common_math.h create mode 100644 Makefile_Assignment/complex_math/complex_math.c create mode 100644 Makefile_Assignment/complex_math/complex_math.h create mode 100644 Makefile_Assignment/main.c create mode 100644 Makefile_Assignment/trig_math/trig_math.c create mode 100644 Makefile_Assignment/trig_math/trig_math.h diff --git a/Makefile_Assignment/Makefile b/Makefile_Assignment/Makefile new file mode 100644 index 0000000..3a2c169 --- /dev/null +++ b/Makefile_Assignment/Makefile @@ -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 diff --git a/Makefile_Assignment/common_math/common_math.c b/Makefile_Assignment/common_math/common_math.c new file mode 100644 index 0000000..1b5ed42 --- /dev/null +++ b/Makefile_Assignment/common_math/common_math.c @@ -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 + +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; +} + diff --git a/Makefile_Assignment/common_math/common_math.h b/Makefile_Assignment/common_math/common_math.h new file mode 100644 index 0000000..36def7b --- /dev/null +++ b/Makefile_Assignment/common_math/common_math.h @@ -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__ */ + diff --git a/Makefile_Assignment/complex_math/complex_math.c b/Makefile_Assignment/complex_math/complex_math.c new file mode 100644 index 0000000..4dcc84d --- /dev/null +++ b/Makefile_Assignment/complex_math/complex_math.c @@ -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; +} + diff --git a/Makefile_Assignment/complex_math/complex_math.h b/Makefile_Assignment/complex_math/complex_math.h new file mode 100644 index 0000000..1ec4479 --- /dev/null +++ b/Makefile_Assignment/complex_math/complex_math.h @@ -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 diff --git a/Makefile_Assignment/main.c b/Makefile_Assignment/main.c new file mode 100644 index 0000000..6bc8eca --- /dev/null +++ b/Makefile_Assignment/main.c @@ -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 + +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; +} diff --git a/Makefile_Assignment/trig_math/trig_math.c b/Makefile_Assignment/trig_math/trig_math.c new file mode 100644 index 0000000..803b215 --- /dev/null +++ b/Makefile_Assignment/trig_math/trig_math.c @@ -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 + +double sine(double x){ + return sin(x*(PI/180)); +} + + +double cosine(double x){ + return cos(x*(PI/180)); +} diff --git a/Makefile_Assignment/trig_math/trig_math.h b/Makefile_Assignment/trig_math/trig_math.h new file mode 100644 index 0000000..f809603 --- /dev/null +++ b/Makefile_Assignment/trig_math/trig_math.h @@ -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