Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ExperimentOnboarding/README.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions ExperimentOnboarding/day_1/README.md
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions ExperimentOnboarding/day_1/helloworld.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
Binary file added ExperimentOnboarding/day_1/mac_setup_guide.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 67 additions & 0 deletions ExperimentOnboarding/day_2/README.md
Original file line number Diff line number Diff line change
@@ -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?)
9 changes: 9 additions & 0 deletions ExperimentOnboarding/day_2/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// hello.cpp file
//REMOVE WHEN READY// #include "helloWorld.h"
#include <iostream>
int main()
{
std::cout << "Hello Geek\n";
//REMOVE WHEN READY// helloWorld();
return 0;
}
Binary file added ExperimentOnboarding/day_2/hello.o
Binary file not shown.
6 changes: 6 additions & 0 deletions ExperimentOnboarding/day_2/helloWorld.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// helloWorld.cpp file
#include <iostream>
void helloWorld()
{
std::cout << "Hello World\n";
}
2 changes: 2 additions & 0 deletions ExperimentOnboarding/day_2/helloWorld.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// helloWorld.h file
void helloWorld();
Binary file added ExperimentOnboarding/day_3/Makefile_Tutorial.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions ExperimentOnboarding/day_3/README.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions ExperimentOnboarding/day_3/step_1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello:
echo "Hello, World"
echo "This line will print if the file hello does not exist."
14 changes: 14 additions & 0 deletions ExperimentOnboarding/day_3/step_10/Makefile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions ExperimentOnboarding/day_3/step_10/all.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// all.c
int main() { return 0; }
17 changes: 17 additions & 0 deletions ExperimentOnboarding/day_3/step_11/Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions ExperimentOnboarding/day_3/step_11/all.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// all.c
int main() { return 0; }
18 changes: 18 additions & 0 deletions ExperimentOnboarding/day_3/step_12/Makefile
Original file line number Diff line number Diff line change
@@ -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.*
5 changes: 5 additions & 0 deletions ExperimentOnboarding/day_3/step_12/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("success...");
return 0;
}
15 changes: 15 additions & 0 deletions ExperimentOnboarding/day_3/step_13/Makefile
Original file line number Diff line number Diff line change
@@ -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`
50 changes: 50 additions & 0 deletions ExperimentOnboarding/day_3/step_14/Makefile
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions ExperimentOnboarding/day_3/step_2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## fill out incomplete recipes 'blah' and 'blah.o'
blah: blah.o


blah.o: blah.c


2 changes: 2 additions & 0 deletions ExperimentOnboarding/day_3/step_2/blah.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// blah.c
int main() { return 0; }
9 changes: 9 additions & 0 deletions ExperimentOnboarding/day_3/step_3/Makefile
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions ExperimentOnboarding/day_3/step_4/Makefile
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions ExperimentOnboarding/day_3/step_5/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all: one two three

one:
touch one
two:
touch two
three:
touch three

clean:
rm -f one two three
9 changes: 9 additions & 0 deletions ExperimentOnboarding/day_3/step_6/Makefile
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions ExperimentOnboarding/day_3/step_7/Makefile
Original file line number Diff line number Diff line change
@@ -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)
Loading