diff --git a/ExperimentOnboarding/README.md b/ExperimentOnboarding/README.md new file mode 100644 index 00000000..b255eaa6 --- /dev/null +++ b/ExperimentOnboarding/README.md @@ -0,0 +1,14 @@ +### WELCOME TO EXPERIMENTAL ONBOARDING ### +## author : Noah Breit + +# SUMMARY +1. each 'day' is a lesson with a README as a guide. +2. message 'noahbreit' on Slack with any questions + +# DAY 1 -- ENVIRONMENT SETUP + +# DAY 2 -- COMPILERS + +# DAY 3 -- ...tbd + +# DAY 4 -- ...tbd diff --git a/ExperimentOnboarding/day_1/README.md b/ExperimentOnboarding/day_1/README.md new file mode 100644 index 00000000..7c7a5787 --- /dev/null +++ b/ExperimentOnboarding/day_1/README.md @@ -0,0 +1,13 @@ +### DAY ONE ### +## author : Noah Breit + +# NEEDED +1. Install VsCode at following link + - https://code.visualstudio.com/download + +# COMPLETE ENVIRONMENT SETUP +1. Follow instructions specific to your native environment: + - pdf files are provided + - Mac setup; https://code.visualstudio.com/docs/cpp/config-clang-mac + - Windows setup; https://code.visualstudio.com/docs/cpp/config-mingw + \ No newline at end of file diff --git a/ExperimentOnboarding/day_1/helloworld.cpp b/ExperimentOnboarding/day_1/helloworld.cpp new file mode 100644 index 00000000..9ec0f09f --- /dev/null +++ b/ExperimentOnboarding/day_1/helloworld.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +using namespace std; + +int main() +{ + vector msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"}; + + for (const string& word : msg) + { + cout << word << " "; + } + cout << endl; +} diff --git a/ExperimentOnboarding/day_1/mac_setup_guide.pdf b/ExperimentOnboarding/day_1/mac_setup_guide.pdf new file mode 100644 index 00000000..7a3f4048 Binary files /dev/null and b/ExperimentOnboarding/day_1/mac_setup_guide.pdf differ diff --git a/ExperimentOnboarding/day_1/windows_setup_guide.pdf b/ExperimentOnboarding/day_1/windows_setup_guide.pdf new file mode 100644 index 00000000..827e6cd8 Binary files /dev/null and b/ExperimentOnboarding/day_1/windows_setup_guide.pdf differ diff --git a/ExperimentOnboarding/day_2/GeeksforGeeks_Compiling_with_g++.pdf b/ExperimentOnboarding/day_2/GeeksforGeeks_Compiling_with_g++.pdf new file mode 100644 index 00000000..d2e660f4 Binary files /dev/null and b/ExperimentOnboarding/day_2/GeeksforGeeks_Compiling_with_g++.pdf differ diff --git a/ExperimentOnboarding/day_2/GeeksforGeeks_Intro_to_compilers.pdf b/ExperimentOnboarding/day_2/GeeksforGeeks_Intro_to_compilers.pdf new file mode 100644 index 00000000..d54d1eae Binary files /dev/null and b/ExperimentOnboarding/day_2/GeeksforGeeks_Intro_to_compilers.pdf differ diff --git a/ExperimentOnboarding/day_2/OReilly_Programming_Embedded_Systems_Second_edition_ebook.pdf b/ExperimentOnboarding/day_2/OReilly_Programming_Embedded_Systems_Second_edition_ebook.pdf new file mode 100644 index 00000000..642b7887 Binary files /dev/null and b/ExperimentOnboarding/day_2/OReilly_Programming_Embedded_Systems_Second_edition_ebook.pdf differ diff --git a/ExperimentOnboarding/day_2/README.md b/ExperimentOnboarding/day_2/README.md new file mode 100644 index 00000000..c4ea93f9 --- /dev/null +++ b/ExperimentOnboarding/day_2/README.md @@ -0,0 +1,67 @@ +### DAY TWO ### +## author : Noah Breit + +# NEEDED +1. C/C++ Toolchain and VSCode environment setup + - See Day One Folder + +# LEARN TO BUILD +1. OPTIONAL -- Read Text + - pdf is provided + - Embedded Programming Textbook; https://www.bogotobogo.com/cplusplus/files/embed/OReilly_Programming_Embedded_Systems_Second_edition_ebook.pdf + - `read Chapter 4, pages 57-62. this will explain (better than I can) how C, C++, and high level programming languages in general actually 'run' on machines` + - feel free to explore the remainder of Chapter 4 and the textbook. I recommend chapters 1-3. + +2. Summary + - pdf is provided + - `Geeks 4 Geeks G++ Guide; https://www.geeksforgeeks.org/compiling-with-g-plus-plus/` + - Geeks 4 Geeks Quick Compiler Explanation; https://www.geeksforgeeks.org/introduction-to-compilers/ + - note : options described in guide are the same for clang toolchain (mac users) + +3. Using g++ + - `follow Geeks 4 Geeks tutorial and make the following output with g++: assembly output, object output, and an executable` + hello.s (assembly file) + hello.o helloWorld.o (object file) + main.exe (executable) + + - format : [g++|clang] [options] [input] [output] + - example : "g++ hello.o helloWorld.o -o main" --> main + + - note : geeksforgeeks guide writes "g++ -o main hello.o helloWorld.o" + - while this format is accepted by g++, please avoid this. it is best to define the output file last + - note : .exe file extension is the implied default extension on windows devices + - note : if no output file is given, output file will be [input] + new file extension depending on compiler flags + - example : g++ -c hello.cpp --> hello.o + +4. Build Optimizing Fun + - TODO : INSTRUCTIONS BELOW FOR MAC TO INSTALL BINUTILS (mac users) + - binutils libref: https://www.gnu.org/software/binutils/ + - `use "size" "objdump" "file" commands to interact with otherwise difficult object files and executables` + - example : "file hello.o" --> + .\hello.o: Intel amd64 COFF object file, no line number info, not stripped, 9 sections, symbol offset=0x3ca, 33 symbols, + 1st section name ".text" + + - ^ explanation : hello.o is defined this way because my laptop has an intel i7, 64-bit system. so, the compiler recognized + this and defined the obj file to be compatable (Intel amd64 COFF object file). + + - example : "size hello.o" --> + text data bss dec hex filename + 352 8 16 376 178 .\hello.o + + - ^ explanation : hello.o is a COFF object file, one of two common obj file types (other being ELF format). Both formats follow + the similar structure of 'text' 'data' 'bss' sections. 'dec' 'hex' are the total file size (by line) of input + file in decimal and hexadecimal respectively. + 'text' is the program + data to create an executable + 'data' is initialized variables + 'bss' is unititalized variables + + - example: "objdump -S hello.o" --> print original source code (in assembly) to the best of the tool's abilities. + - example: "objdump -i hello.o" --> print data formats found in obj file + - example: "objdump -f hello.o" --> print main header of obj file + - example: "objdump -x hello.o" --> print all headers of obj file + + - note : objdump is a basic disassembler able to translate binaries (obj files and executables) into human-readable assembly. + I included it as a fun tool to play with. We will most likely never use it at solarcar. But, disassemblers are fundamental to cybersecurity, hacking, etc. So if you enjoy it, consider looking into those fields. + + - `try to make the most optimized output (smallest assembly file, objfile and executable) while preserving the output serial text.` + - hint : change original .cpp files and/or manipulate g++|clang options (google g++ optimization flags?) diff --git a/ExperimentOnboarding/day_2/hello.cpp b/ExperimentOnboarding/day_2/hello.cpp new file mode 100644 index 00000000..a210ebea --- /dev/null +++ b/ExperimentOnboarding/day_2/hello.cpp @@ -0,0 +1,9 @@ +// hello.cpp file +//REMOVE WHEN READY// #include "helloWorld.h" +#include +int main() +{ + std::cout << "Hello Geek\n"; + //REMOVE WHEN READY// helloWorld(); + return 0; +} diff --git a/ExperimentOnboarding/day_2/hello.o b/ExperimentOnboarding/day_2/hello.o new file mode 100644 index 00000000..9d3d68c1 Binary files /dev/null and b/ExperimentOnboarding/day_2/hello.o differ diff --git a/ExperimentOnboarding/day_2/helloWorld.cpp b/ExperimentOnboarding/day_2/helloWorld.cpp new file mode 100644 index 00000000..71f083e0 --- /dev/null +++ b/ExperimentOnboarding/day_2/helloWorld.cpp @@ -0,0 +1,6 @@ +// helloWorld.cpp file +#include +void helloWorld() +{ + std::cout << "Hello World\n"; +} diff --git a/ExperimentOnboarding/day_2/helloWorld.h b/ExperimentOnboarding/day_2/helloWorld.h new file mode 100644 index 00000000..926e342a --- /dev/null +++ b/ExperimentOnboarding/day_2/helloWorld.h @@ -0,0 +1,2 @@ +// helloWorld.h file +void helloWorld(); diff --git a/ExperimentOnboarding/day_3/Makefile_Tutorial.pdf b/ExperimentOnboarding/day_3/Makefile_Tutorial.pdf new file mode 100644 index 00000000..53dae1fb Binary files /dev/null and b/ExperimentOnboarding/day_3/Makefile_Tutorial.pdf differ diff --git a/ExperimentOnboarding/day_3/README.md b/ExperimentOnboarding/day_3/README.md new file mode 100644 index 00000000..4623717b --- /dev/null +++ b/ExperimentOnboarding/day_3/README.md @@ -0,0 +1,20 @@ +### DAY THREE ### +## author : Noah Breit + +# NEEDED +1. Understand compiling basics + - see day two + +# LEARN and USE MAKEFILES +1. Follow Makefile tutorial: https://makefiletutorial.com/ + - files mentioned in tutorial are provided in "step" folders + - provided files will stop at "Commands and execution" section of tutorial. + - you are more than welcome to continue the tutorial. but know that these examples are beyond the scope of solarcar. + +2. Follow Blink LED tutorial: https://www.tderflinger.com/en/arduino-blinking-led-pure-c + - link to source: https://github.com/tderflinger/arduino-blink-purec + - link to arduino 32-bit gnu toolchain: https://www.microchip.com/en-us/tools-resources/develop/microchip-studio/gcc-compilers + +3. Flash to Arduino !! + - link to arduino bootloader: https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-Windows-using-Visual-Studio + - If available. flash arduino project (using the provided makefile) onto an Arduino Uno. diff --git a/ExperimentOnboarding/day_3/step_1/Makefile b/ExperimentOnboarding/day_3/step_1/Makefile new file mode 100644 index 00000000..188f02fe --- /dev/null +++ b/ExperimentOnboarding/day_3/step_1/Makefile @@ -0,0 +1,3 @@ +hello: + echo "Hello, World" + echo "This line will print if the file hello does not exist." diff --git a/ExperimentOnboarding/day_3/step_10/Makefile b/ExperimentOnboarding/day_3/step_10/Makefile new file mode 100644 index 00000000..1d771ed2 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_10/Makefile @@ -0,0 +1,14 @@ +objects = foo.o bar.o all.o +all: $(objects) + +# These files compile via implicit rules +foo.o: foo.c +bar.o: bar.c +all.o: all.c + +%.c: + touch $@ + +clean: + rm -f *.c *.o all + \ No newline at end of file diff --git a/ExperimentOnboarding/day_3/step_10/all.c b/ExperimentOnboarding/day_3/step_10/all.c new file mode 100644 index 00000000..b84c913f --- /dev/null +++ b/ExperimentOnboarding/day_3/step_10/all.c @@ -0,0 +1,2 @@ +// all.c +int main() { return 0; } diff --git a/ExperimentOnboarding/day_3/step_11/Makefile b/ExperimentOnboarding/day_3/step_11/Makefile new file mode 100644 index 00000000..8d055a46 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_11/Makefile @@ -0,0 +1,17 @@ +objects = foo.o bar.o all.o +all: $(objects) + +# These files compile via implicit rules +# Syntax - targets ...: target-pattern: prereq-patterns ... +# In the case of the first target, foo.o, the target-pattern matches foo.o and sets the "stem" to be "foo". +# It then replaces the '%' in prereq-patterns with that stem +$(objects): %.o: %.c + +all.c: + echo "int main() { return 0; }" > all.c + +%.c: + touch $@ + +clean: + rm -f *.c *.o all diff --git a/ExperimentOnboarding/day_3/step_11/all.c b/ExperimentOnboarding/day_3/step_11/all.c new file mode 100644 index 00000000..b84c913f --- /dev/null +++ b/ExperimentOnboarding/day_3/step_11/all.c @@ -0,0 +1,2 @@ +// all.c +int main() { return 0; } diff --git a/ExperimentOnboarding/day_3/step_12/Makefile b/ExperimentOnboarding/day_3/step_12/Makefile new file mode 100644 index 00000000..248e6a0a --- /dev/null +++ b/ExperimentOnboarding/day_3/step_12/Makefile @@ -0,0 +1,18 @@ +# Define a pattern rule that compiles every .c file into a .o file +%.o : %.c + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +# Define a pattern rule that has no pattern in the prerequisites. +# This just creates empty .c files when needed. +%.c: + touch $@ + echo "int main() { return 0; }" > $@ + +test: + +nothing: + +empty.c: + +clean: + rm -f test nothing.* empty.* diff --git a/ExperimentOnboarding/day_3/step_12/test.c b/ExperimentOnboarding/day_3/step_12/test.c new file mode 100644 index 00000000..6ca704bd --- /dev/null +++ b/ExperimentOnboarding/day_3/step_12/test.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("success..."); + return 0; +} diff --git a/ExperimentOnboarding/day_3/step_13/Makefile b/ExperimentOnboarding/day_3/step_13/Makefile new file mode 100644 index 00000000..aac74b4f --- /dev/null +++ b/ExperimentOnboarding/day_3/step_13/Makefile @@ -0,0 +1,15 @@ +test_silence: + @echo "This make line will not be printed" + echo "But this will" + +test_order: + cd .. + # The cd above does not affect this line, because each command is effectively run in a new shell + echo `pwd` + + # This cd command affects the next because they are on the same line + cd ..;echo `pwd` + + # Same as above + cd ..; \ + echo `pwd` diff --git a/ExperimentOnboarding/day_3/step_14/Makefile b/ExperimentOnboarding/day_3/step_14/Makefile new file mode 100644 index 00000000..bb3ee133 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_14/Makefile @@ -0,0 +1,50 @@ +# Thanks to Job Vranish (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/) +TARGET_EXEC := final_program + +BUILD_DIR := ./build +SRC_DIRS := ./src + +# Find all the C and C++ files we want to compile +# Note the single quotes around the * expressions. The shell will incorrectly expand these otherwise, but we want to send the * directly to the find command. +SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s') + +# Prepends BUILD_DIR and appends .o to every src file +# As an example, ./your_dir/hello.cpp turns into ./build/./your_dir/hello.cpp.o +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) + +# String substitution (suffix version without %). +# As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d +DEPS := $(OBJS:.o=.d) + +# Every folder in ./src will need to be passed to GCC so that it can find header files +INC_DIRS := $(shell find $(SRC_DIRS) -type d) +# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +# The -MMD and -MP flags together generate Makefiles for us! +# These files will have .d instead of .o as the output. +CPPFLAGS := $(INC_FLAGS) -MMD -MP + +# The final build step. +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + $(CXX) $(OBJS) -o $@ $(LDFLAGS) + +# Build step for C source +$(BUILD_DIR)/%.c.o: %.c + mkdir -p $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +# Build step for C++ source +$(BUILD_DIR)/%.cpp.o: %.cpp + mkdir -p $(dir $@) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ + + +.PHONY: clean +clean: + rm -r $(BUILD_DIR) + +# Include the .d makefiles. The - at the front suppresses the errors of missing +# Makefiles. Initially, all the .d files will be missing, and we don't want those +# errors to show up. +-include $(DEPS) \ No newline at end of file diff --git a/ExperimentOnboarding/day_3/step_2/Makefile b/ExperimentOnboarding/day_3/step_2/Makefile new file mode 100644 index 00000000..d75ab020 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_2/Makefile @@ -0,0 +1,7 @@ +## fill out incomplete recipes 'blah' and 'blah.o' +blah: blah.o + + +blah.o: blah.c + + diff --git a/ExperimentOnboarding/day_3/step_2/blah.c b/ExperimentOnboarding/day_3/step_2/blah.c new file mode 100644 index 00000000..f11d367b --- /dev/null +++ b/ExperimentOnboarding/day_3/step_2/blah.c @@ -0,0 +1,2 @@ +// blah.c +int main() { return 0; } diff --git a/ExperimentOnboarding/day_3/step_3/Makefile b/ExperimentOnboarding/day_3/step_3/Makefile new file mode 100644 index 00000000..d68cc989 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_3/Makefile @@ -0,0 +1,9 @@ +some_file: other_file + echo "This will always run, and runs second" + touch some_file + +other_file: + echo "This will always run, and runs first" + +clean: + rm -f some_file diff --git a/ExperimentOnboarding/day_3/step_4/Makefile b/ExperimentOnboarding/day_3/step_4/Makefile new file mode 100644 index 00000000..4e3b44c8 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_4/Makefile @@ -0,0 +1,22 @@ +files := file1 file2 +some_file: $(files) + echo "Look at this variable: " $(files) + touch some_file + +file1: + touch file1 +file2: + touch file2 + +clean: + rm -f file1 file2 some_file + +## experiment with printing variables. notice target name +argo := ... +brizo := ... +calypso := ... + +print: + echo $(argo) + echo $(brizo) + echo $(calypso) \ No newline at end of file diff --git a/ExperimentOnboarding/day_3/step_5/Makefile b/ExperimentOnboarding/day_3/step_5/Makefile new file mode 100644 index 00000000..74c2bf27 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_5/Makefile @@ -0,0 +1,11 @@ +all: one two three + +one: + touch one +two: + touch two +three: + touch three + +clean: + rm -f one two three diff --git a/ExperimentOnboarding/day_3/step_6/Makefile b/ExperimentOnboarding/day_3/step_6/Makefile new file mode 100644 index 00000000..3536aecd --- /dev/null +++ b/ExperimentOnboarding/day_3/step_6/Makefile @@ -0,0 +1,9 @@ +all: f1.o f2.o + +f1.o f2.o: + echo $@ +# Equivalent to: +# f1.o: +# echo f1.o +# f2.o: +# echo f2.o diff --git a/ExperimentOnboarding/day_3/step_7/Makefile b/ExperimentOnboarding/day_3/step_7/Makefile new file mode 100644 index 00000000..2754094c --- /dev/null +++ b/ExperimentOnboarding/day_3/step_7/Makefile @@ -0,0 +1,22 @@ +# Print out file information about every .c file +print: $(wildcard *.c) + ls -la $? + + + +thing_wrong := *.o # Don't do this! '*' will not get expanded +thing_right := $(wildcard *.o) + +all: one two three four + +# Fails, because $(thing_wrong) is the string "*.o" +one: $(thing_wrong) + +# Stays as *.o if there are no files that match this pattern :( +two: *.o + +# Works as you would expect! In this case, it does nothing. +three: $(thing_right) + +# Same as rule three +four: $(wildcard *.o) \ No newline at end of file diff --git a/ExperimentOnboarding/day_3/step_8/Makefile b/ExperimentOnboarding/day_3/step_8/Makefile new file mode 100644 index 00000000..63fab774 --- /dev/null +++ b/ExperimentOnboarding/day_3/step_8/Makefile @@ -0,0 +1,20 @@ +hey: one two + # Outputs "hey", since this is the target name + echo $@ + + # Outputs all prerequisites newer than the target + echo $? + + # Outputs all prerequisites + echo $^ + + touch hey + +one: + touch one + +two: + touch two + +clean: + rm -f hey one diff --git a/ExperimentOnboarding/day_3/step_9/Makefile b/ExperimentOnboarding/day_3/step_9/Makefile new file mode 100644 index 00000000..aa1acf8e --- /dev/null +++ b/ExperimentOnboarding/day_3/step_9/Makefile @@ -0,0 +1,9 @@ +CC = gcc # Flag for implicit rules +CFLAGS = -g # Flag for implicit rules. Turn on debug info + +# Implicit rule #1: blah is built via the C linker implicit rule +# Implicit rule #2: blah.o is built via the C compilation implicit rule, because blah.c exists +blah: blah.o + +clean: + rm -f blah* \ No newline at end of file diff --git a/ExperimentOnboarding/day_3/step_9/blah.c b/ExperimentOnboarding/day_3/step_9/blah.c new file mode 100644 index 00000000..f11d367b --- /dev/null +++ b/ExperimentOnboarding/day_3/step_9/blah.c @@ -0,0 +1,2 @@ +// blah.c +int main() { return 0; }