summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-04-21 23:05:26 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-04-21 23:05:26 +0200
commite2fcea07eca10bf925e450dc1c2ce60735da16c2 (patch)
treea32fd0fafc1d2c7863cfcbb43ef8e044f5a0b6f2
downloadbetriebssysteme-e2fcea07eca10bf925e450dc1c2ce60735da16c2.tar.gz
betriebssysteme-e2fcea07eca10bf925e450dc1c2ce60735da16c2.zip
initial - basic makefile and main.c
-rw-r--r--.gitignore3
-rw-r--r--Makefile53
-rw-r--r--main.c21
3 files changed, 77 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7623090
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.idea
+*.o
+*_exe
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..647ebcd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,53 @@
+# if $CC is not set, use gcc as a sensible default
+CC ?= gcc
+RM ?= rm -fv
+
+# if $CFLAGS is not set, be very pedantic and compile
+# as C11, that should catch some common errors, also
+# fortify the source, which is a must for security.
+CFLAGS ?= -Wall \
+ -D_FORTIFY_SOURCE=2 \
+ -Wextra -Wcast-align -Wcast-qual -Wpointer-arith \
+ -Waggregate-return -Wunreachable-code -Wfloat-equal \
+ -Wformat=2 -Wredundant-decls -Wundef \
+ -Wdisabled-optimization -Wshadow -Wmissing-braces \
+ -Wstrict-aliasing=2 -Wstrict-overflow=5 -Wconversion \
+ -Wno-unused-parameter \
+ -pedantic -std=c11
+
+CFLAGS_DEBUG := -g3 \
+ -O \
+ -DDEBUG
+
+CFLAGS_RELEASE := -O2 \
+ -DNDEBUG \
+ -march=native \
+ -mtune=native \
+ -ftree-vectorize
+
+# the default target is debug
+all: debug
+
+# clean target, removing all .o and the executable
+clean:
+ $(RM) *o bs_exe
+
+# when the target is debug,
+# add CFLAGS_DEBUG to CFLAGS
+debug: CFLAGS += $(CFLAGS_DEBUG)
+debug: clean bs_exe
+
+# when the target is release,
+# add CFLAGS_RELEASE to CFLAGS
+release: CFLAGS += $(CFLAGS_RELEASE)
+release: clean bs_exe
+
+bs_exe: main.o
+ $(CC) $^ -o $@ $(CFLAGS)
+
+# when looking for something that ends in .o, look
+# for the same thing ending in .c and run gcc on it
+%.o: %.c
+ $(CC) -c $< $(CFLAGS)
+
+.PHONY: debug release clean \ No newline at end of file
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..4f4e1a9
--- /dev/null
+++ b/main.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+#if !defined(NDEBUG)
+ #define TRACE(MSG) \
+ fprintf(stderr, "%s\n", #MSG)
+#else
+ #define TRACE(MSG)
+#endif
+
+int main(int argc, char *argv[]) {
+ TRACE(pre assembly);
+ __asm__(""
+ :
+ :
+ :
+ );
+ TRACE(post assembly);
+ return 0;
+}
+
+/* https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html */ \ No newline at end of file