From 3c0c88d31d9acf01bd5d33a913bfa2464fd97ffb Mon Sep 17 00:00:00 2001
From: Orestis <orestis.malaspinas@pm.me>
Date: Tue, 9 Mar 2021 09:45:08 +0100
Subject: [PATCH] playground for makefiles

---
 exemples/make/.gitignore |  2 ++
 exemples/make/Makefile   | 31 +++++++++++++++++++++++++++++++
 exemples/make/bar.c      |  6 ++++++
 exemples/make/bar.h      |  6 ++++++
 exemples/make/foo.c      |  5 +++++
 exemples/make/foo.h      |  6 ++++++
 exemples/make/main.c     |  6 ++++++
 7 files changed, 62 insertions(+)
 create mode 100644 exemples/make/.gitignore
 create mode 100644 exemples/make/Makefile
 create mode 100644 exemples/make/bar.c
 create mode 100644 exemples/make/bar.h
 create mode 100644 exemples/make/foo.c
 create mode 100644 exemples/make/foo.h
 create mode 100644 exemples/make/main.c

diff --git a/exemples/make/.gitignore b/exemples/make/.gitignore
new file mode 100644
index 0000000..f0c9b81
--- /dev/null
+++ b/exemples/make/.gitignore
@@ -0,0 +1,2 @@
+*.o
+main
diff --git a/exemples/make/Makefile b/exemples/make/Makefile
new file mode 100644
index 0000000..4389dc8
--- /dev/null
+++ b/exemples/make/Makefile
@@ -0,0 +1,31 @@
+CC = gcc
+CFLAGS = -g -Wall -O0 -std=c11
+LDFLAGS = -lm
+
+# SOURCES = main.c foo.c bar.c
+# means *.c
+SOURCES = $(wildcard *.c)
+# OBJECTS contient SOURCES avec .c -> .o
+OBJECTS = $(SOURCES:.c=.o)
+
+# OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
+
+# galaxy sera l'exécutable (galaxy.c contient le main)
+TARGET = main
+$(TARGET) : $(OBJECTS)
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+# main: main.o foo.o bar.o
+# 	cc -o $@ $^ $(CFLAGS) $(LDFLAGS)
+# 
+# foo.o: foo.h
+# bar.o: bar.h
+# main.o: foo.h
+
+.PHONY: clean
+
+clean:
+	rm -f $(TARGET) $(OBJECTS)
+
+# clean:
+# 	rm -f *.o main
\ No newline at end of file
diff --git a/exemples/make/bar.c b/exemples/make/bar.c
new file mode 100644
index 0000000..bc147f6
--- /dev/null
+++ b/exemples/make/bar.c
@@ -0,0 +1,6 @@
+#include "bar.h"
+#include "foo.h"
+
+void bar() {
+    foo();
+}
\ No newline at end of file
diff --git a/exemples/make/bar.h b/exemples/make/bar.h
new file mode 100644
index 0000000..eb8355c
--- /dev/null
+++ b/exemples/make/bar.h
@@ -0,0 +1,6 @@
+#ifndef _BAR_H_
+#define _BAR_H_
+
+void bar();
+
+#endif
diff --git a/exemples/make/foo.c b/exemples/make/foo.c
new file mode 100644
index 0000000..acfc6b0
--- /dev/null
+++ b/exemples/make/foo.c
@@ -0,0 +1,5 @@
+#include "foo.h"
+
+void foo() {
+
+}
\ No newline at end of file
diff --git a/exemples/make/foo.h b/exemples/make/foo.h
new file mode 100644
index 0000000..9da89d6
--- /dev/null
+++ b/exemples/make/foo.h
@@ -0,0 +1,6 @@
+#ifndef _FOO_H_
+#define _FOO_H_
+
+void foo();
+
+#endif
diff --git a/exemples/make/main.c b/exemples/make/main.c
new file mode 100644
index 0000000..c0c1b2f
--- /dev/null
+++ b/exemples/make/main.c
@@ -0,0 +1,6 @@
+#include "foo.h"
+
+int main() {
+    foo();
+    return 0;
+}
\ No newline at end of file
-- 
GitLab