summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2019-08-25 23:04:24 -0400
committerB Stack <bgstack15@gmail.com>2019-08-25 23:04:24 -0400
commitda08171e0c65e278feeb8393b5a8f7e79ea491c9 (patch)
tree728fd5de284626349bc9e9f5f48f30a83e0efc10
parentinitial commit (diff)
downloadcpp-da08171e0c65e278feeb8393b5a8f7e79ea491c9.tar.gz
cpp-da08171e0c65e278feeb8393b5a8f7e79ea491c9.tar.bz2
cpp-da08171e0c65e278feeb8393b5a8f7e79ea491c9.zip
at page 3.6HEADmaster
Improved the makefile for multifile project, including header files.
-rw-r--r--.gitignore2
-rw-r--r--Makefile12
-rw-r--r--helloworld.cpp12
-rw-r--r--main.cpp8
-rw-r--r--math.cpp17
-rw-r--r--math.h6
6 files changed, 41 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 4c61283..721d950 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
*/*.o
+*.o
helloworld
+mine
diff --git a/Makefile b/Makefile
index 8a2f666..15de4d0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+# references:
+# BUILD_DIR and per-.cpp file https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
awkbin :=$(shell which awk)
cpbin :=$(shell which cp)
echobin :=$(shell which echo)
@@ -20,13 +22,15 @@ LDFLAGS = -g
src = $(wildcard *.cpp)
obj = $(src:.cpp=.o)
-OUTEXE = helloworld
+BUILD_DIR ?= .
+
+OUTEXE = mine
all: $(OUTEXE)
-# compile
-$(obj): $(src)
- $(CXX) -c $(CXXFLAGS) $<
+# compile, which is not actually used?
+$(BUILD_DIR)%.o: %.cpp
+ $(CXX) -c $(CXXFLAGS) $+
# link
$(OUTEXE): $(obj)
diff --git a/helloworld.cpp b/helloworld.cpp
deleted file mode 100644
index 8474a1e..0000000
--- a/helloworld.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <iostream>
-
-int return5()
-{
- return 5 ;
-}
-
-int main() {
- //int x { }, y { } ;
- std::cout << return5() << '\n' ;
- return 0 ;
-}
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..735cd75
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,8 @@
+#include <iostream>
+#include "math.h"
+
+int main()
+{
+ std::cout << doubleNumber(getNumberFromUser()) << '\n' ;
+ return 0 ;
+}
diff --git a/math.cpp b/math.cpp
new file mode 100644
index 0000000..5aeebfd
--- /dev/null
+++ b/math.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include "math.h"
+
+int getNumberFromUser()
+{
+ std::cout << "Enter an integer: " ;
+ int x ;
+ std::cin >> x ;
+ return x ;
+}
+
+int doubleNumber(int x)
+{
+ //int z { 3 } ;
+ //z = z * 2 ;
+ return x * 2 ;
+}
diff --git a/math.h b/math.h
new file mode 100644
index 0000000..dfa8d0f
--- /dev/null
+++ b/math.h
@@ -0,0 +1,6 @@
+#ifndef MATH9385
+#define MATH9385
+int getNumberFromUser() ;
+int doubleNumber(int x) ;
+
+#endif
bgstack15