From 60c6c6b8c4ff1889d6b721ec42789a0150a40fbe Mon Sep 17 00:00:00 2001 From: grimhilt Date: Mon, 13 Nov 2023 13:06:47 +0100 Subject: [PATCH] use static library instead of object --- .gitignore | 16 ++++++++++++++++ Makefile | 13 ++++++++----- README.md | 10 +++++++--- src/default_student.c | 3 +-- src/student.c | 3 +-- 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb5855f --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +* +!/**/ +!*.* +!Makefile + +*~ +*.swp +*.swo +*.o +*.a +*.so +*.class +*.log +*.core +*.gcno +*.tar* diff --git a/Makefile b/Makefile index 41683d8..86f4793 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,24 @@ CC = gcc CFLAGS := -std=c99 -Wall -Wextra -Werror -pedantic -Wvla -OBJ_RUN := src/student.c src/main.o src/pin_handler.o +OBJ_RUN := src/student.c all: run +%.o: %.c + @$(CC) $(LFLAGS) $(CFLAGS) -c -o $@ $< + +prepare: CFLAGS += -shared prepare: src/main.o src/pin_handler.o + ar crs src/pin_handler.a $^ + tar czf student.tar.gz src/pin_handler.a src/student.c src/default_student.c Makefile student.ino src/parser.c parser: src/parser.o student.ino @$(CC) $(CFLAGS) -o $@ src/parser.o @./parser ./student.ino run: parser $(OBJ_RUN) student.ino - @$(CC) -o main $(OBJ_RUN) + @$(CC) -o main $(OBJ_RUN) src/pin_handler.a @./main -%.o: %.c - @$(CC) $(LFLAGS) $(CFLAGS) -c -o $@ $< - clean: $(RM) src/*.o main parser diff --git a/README.md b/README.md index 2b84c9f..c171968 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,10 @@ *Note that the passcode must end with a '#'* 2. Run the command ``make prepare`` -3. Give this repository to your student but make sure not to give the ``src/pin_handler.h`` file or to change the passcode you compiled with -4. To test the ``student.ino`` just run ``make run`` + +*This will create a ``student.tar.gz`` that will contain the static library used to run the student code and the parser code* + +3. To test the ``student.ino`` just run ``make run`` ## Warning @@ -18,4 +20,6 @@ This is a very very basic parser, and so it will not work with a certain number * if you don't use the variable for the pin numbers * if you write 'digitalWrite()' on several lines * if you move the loop() opening bracket on the next line -* ... \ No newline at end of file +* if the main loop() call others functions +* if you use arduino or c++ specific functions +* ... diff --git a/src/default_student.c b/src/default_student.c index 66ae601..34e648a 100644 --- a/src/default_student.c +++ b/src/default_student.c @@ -1,4 +1,3 @@ -#include "pin_handler.h" #include #define L1 1 @@ -10,7 +9,7 @@ #define C3 7 #define C4 8 - +void set_pin(int id, short state, size_t *row, size_t *col, char *sequence, size_t *pointer); void student(char *sequence, size_t *pointer) { diff --git a/src/student.c b/src/student.c index 12aca27..c6329a4 100644 --- a/src/student.c +++ b/src/student.c @@ -1,4 +1,3 @@ -#include "pin_handler.h" #include #define L1 1 @@ -10,7 +9,7 @@ #define C3 7 #define C4 8 - +void set_pin(int id, short state, size_t *row, size_t *col, char *sequence, size_t *pointer); void student(char *sequence, size_t *pointer) {