From b07b9dc2fb85d1ab27e6b29028e9e161ed4cee78 Mon Sep 17 00:00:00 2001 From: androiddrew Date: Mon, 18 Feb 2019 12:42:51 -0500 Subject: [PATCH] Initial Commit --- Makefile | 2 ++ Makefile-2 | 16 ++++++++++++++++ Makefile-3 | 23 +++++++++++++++++++++++ README.md | 5 +++++ factorial.cpp | 9 +++++++++ functions.h | 2 ++ hello.cpp | 6 ++++++ main.cpp | 9 +++++++++ 8 files changed, 72 insertions(+) create mode 100644 Makefile create mode 100644 Makefile-2 create mode 100644 Makefile-3 create mode 100644 README.md create mode 100644 factorial.cpp create mode 100644 functions.h create mode 100644 hello.cpp create mode 100644 main.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f540821 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + clang++ -std=c++11 main.cpp factorial.cpp hello.cpp -o hello diff --git a/Makefile-2 b/Makefile-2 new file mode 100644 index 0000000..cab36c2 --- /dev/null +++ b/Makefile-2 @@ -0,0 +1,16 @@ +all: hello + +hello: main.o factorial.o hello.o + clang++ main.o factorial.o hello.o -o hello + +main.o: main.cpp + clang++ -c main.cpp + +factorial.o: factorial.cpp + clang++ -c factorial.cpp + +hello.o: hello.cpp + clang++ -c hello.cpp + +clean: + rm *o hello diff --git a/Makefile-3 b/Makefile-3 new file mode 100644 index 0000000..667107e --- /dev/null +++ b/Makefile-3 @@ -0,0 +1,23 @@ +# I am a comment, and I want to stay that the variable CC will be the compiler to use +CC=clang++ + +# Hey CFLAGS will be the options I'll pass to the compiler +CFLAGS=-c -Wall + +all: hello + +hello: main.o factorial.o hello.o + $(CC) main.o factorial.o hello.o -o hello + +main.o: main.cpp + $(CC) $(CFLAGS) main.cpp + +factorial.o: factorial.cpp + $(CC) $(CFLAGS) factorial.cpp + +hello.o: hello.cpp + $(CC) $(CFLAGS) hello.cpp + +clean: + rm *o + rm hello diff --git a/README.md b/README.md new file mode 100644 index 0000000..7850e88 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Make Tutorial + +Just a simple 3 example tutorial on how to use Make files. + +Source: https://opensource.com/article/18/8/what-how-makefile \ No newline at end of file diff --git a/factorial.cpp b/factorial.cpp new file mode 100644 index 0000000..d57fb7b --- /dev/null +++ b/factorial.cpp @@ -0,0 +1,9 @@ +#include "functions.h" + + +int factorial(int n){ + if(n!=1){ + return(n * factorial(n-1)); + } + else return 1; +} \ No newline at end of file diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..1839154 --- /dev/null +++ b/functions.h @@ -0,0 +1,2 @@ +void print_hello(); +int factorial(int n); \ No newline at end of file diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 0000000..6506d3b --- /dev/null +++ b/hello.cpp @@ -0,0 +1,6 @@ +#include +#include "functions.h" + +void print_hello(){ + std::cout << "hello World"; +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bf94869 --- /dev/null +++ b/main.cpp @@ -0,0 +1,9 @@ +#include +#include "functions.h" + +int main(){ + print_hello(); + std::cout << std::endl; + std::cout << "The factorial of 5 is " << factorial(5) << std::endl; + return 0; +}