Skip to content

Commit 8928bd8

Browse files
committed
Reworked build system
1 parent f2a977f commit 8928bd8

File tree

13 files changed

+173
-170
lines changed

13 files changed

+173
-170
lines changed

Makefile

Lines changed: 2 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,3 @@
1-
#################################################################
2-
# Makefile to build tiny protocol library
3-
#
4-
# Accept the following variables
5-
# CROSS_COMPILE
6-
# CC
7-
# CXX
8-
# STRIP
9-
# AR
1+
ARCH ?= linux
102

11-
default: all
12-
SDK_BASEDIR ?=
13-
CROSS_COMPILE ?=
14-
OS ?= os/linux
15-
DESTDIR ?=
16-
BLD ?= bld
17-
TINYCONF ?= normal
18-
19-
VERSION=0.7.0
20-
21-
ifeq ($(TINYCONF), nano)
22-
CONFIG_ENABLE_FCS32 ?= n
23-
CONFIG_ENABLE_FCS16 ?= n
24-
CONFIG_ENABLE_CHECKSUM ?= n
25-
CONFIG_ENABLE_STATS ?= n
26-
else ifeq ($(TINYCONF), normal)
27-
CONFIG_ENABLE_FCS32 ?= n
28-
CONFIG_ENABLE_FCS16 ?= y
29-
CONFIG_ENABLE_CHECKSUM ?= y
30-
CONFIG_ENABLE_STATS ?= n
31-
else
32-
CONFIG_ENABLE_FCS32 ?= y
33-
CONFIG_ENABLE_FCS16 ?= y
34-
CONFIG_ENABLE_CHECKSUM ?= y
35-
CONFIG_ENABLE_STATS ?= y
36-
endif
37-
38-
.SUFFIXES: .c .cpp
39-
40-
$(BLD)/%.o: %.c
41-
mkdir -p $(dir $@)
42-
$(CC) $(CCFLAGS) -c $< -o $@
43-
44-
$(BLD)/%.o: %.cpp
45-
mkdir -p $(dir $@)
46-
$(CXX) -std=c++11 $(CCFLAGS) -c $< -o $@
47-
48-
# ************* Common defines ********************
49-
50-
INCLUDES += \
51-
-I./src \
52-
-I./tools/serial \
53-
54-
CCFLAGS += -fPIC -g $(INCLUDES) -Wall -Werror
55-
56-
ifeq ($(CONFIG_ENABLE_FCS32),y)
57-
CCFLAGS += -DCONFIG_ENABLE_FCS32
58-
endif
59-
60-
ifeq ($(CONFIG_ENABLE_FCS16),y)
61-
CCFLAGS += -DCONFIG_ENABLE_FCS16
62-
endif
63-
64-
ifeq ($(CONFIG_ENABLE_CHECKSUM),y)
65-
CCFLAGS += -DCONFIG_ENABLE_CHECKSUM
66-
endif
67-
68-
ifeq ($(CONFIG_ENABLE_STATS),y)
69-
CCFLAGS += -DCONFIG_ENABLE_STATS
70-
endif
71-
72-
.PHONY: clean library all install install-lib docs \
73-
arduino-pkg unittest check release
74-
75-
TARGET_UART = testuart
76-
77-
SRC_UNIT_TEST = \
78-
unittest/helpers/fake_wire.cpp \
79-
unittest/helpers/fake_channel.cpp \
80-
unittest/helpers/tiny_helper.cpp \
81-
unittest/helpers/tiny_hdlc_helper.cpp \
82-
unittest/helpers/tiny_light_helper.cpp \
83-
unittest/helpers/tiny_hd_helper.cpp \
84-
unittest/main.cpp \
85-
unittest/basic_tests.cpp \
86-
unittest/hdlc_tests.cpp \
87-
unittest/light_tests.cpp \
88-
unittest/hd_tests.cpp
89-
90-
OBJ_UNIT_TEST = $(addprefix $(BLD)/, $(addsuffix .o, $(basename $(SRC_UNIT_TEST))))
91-
92-
SRC_SPERF = \
93-
tools/sperf/sperf.c
94-
95-
OBJ_SPERF = $(addprefix $(BLD)/, $(addsuffix .o, $(basename $(SRC_SPERF))))
96-
97-
####################### Compiling library #########################
98-
99-
LIBS_TINY += -L. -lm
100-
101-
LDFLAGS_TINY = -shared
102-
103-
TARGET_TINY = libtinyp.a
104-
105-
SRC_TINY = \
106-
src/proto/crc/crc.c \
107-
src/proto/_old/tiny_layer2.c \
108-
src/proto/light/tiny_light.c \
109-
src/proto/hdlc/tiny_hdlc.c \
110-
src/proto/half_duplex/tiny_hd.c \
111-
src/proto/hal/tiny_list.c \
112-
src/proto/hal/arduino/hal.c \
113-
src/proto/hal/avr/hal.c \
114-
src/proto/hal/esp32/hal.c \
115-
src/proto/hal/linux/hal.c \
116-
src/proto/half_duplex/tiny_rq_pool.c \
117-
tools/serial/serial_linux.c
118-
119-
OBJ_TINY = $(addprefix $(BLD)/, $(addsuffix .o, $(basename $(SRC_TINY))))
120-
121-
library: $(OBJ_TINY)
122-
@echo SDK_BASEDIR: $(SDK_BASEDIR)
123-
@echo CROSS_COMPILE: $(CROSS_COMPILE)
124-
@echo OS: $(OS)
125-
$(AR) rcs $(BLD)/$(TARGET_TINY) $(OBJ_TINY)
126-
# $(STRIP) $(BLD)/$(TARGET_TINY)
127-
# $(CC) $(CCFLAGS) -fPIC -o $(BLD)/$(TARGET_TINY).so $(OBJ_TINY) $(LIBS_TINY) $(LDFLAGS_TINY)
128-
129-
install-lib:
130-
cp -r $(BLD)/libtinyp.a $(DESTDIR)/usr/lib/
131-
cp -rf ./include/*.h $(DESTDIR)/usr/include/
132-
cp -rf ./include/$(OS)/*.h $(DESTDIR)/usr/include/
133-
134-
####################### all ###################################
135-
136-
docs:
137-
doxygen doxygen.cfg
138-
139-
all: library sperf
140-
141-
install: install-lib
142-
$(STRIP) $(DESTDIR)/$@
143-
144-
clean:
145-
rm -rf $(BLD)
146-
147-
unittest: $(OBJ_UNIT_TEST) library
148-
$(CXX) $(CCFLAGS) -o $(BLD)/unit_test $(OBJ_UNIT_TEST) -L. -L$(BLD) -lm -pthread -ltinyp -lCppUTest -lCppUTestExt
149-
150-
sperf: $(OBJ_SPERF) library
151-
$(CC) $(CCFLAGS) -o $(BLD)/sperf $(OBJ_SPERF) -L. -L$(BLD) -lm -pthread -ltinyp
152-
153-
check: unittest
154-
$(BLD)/unit_test
155-
156-
release: docs
3+
include Makefile.$(ARCH)

Makefile.avr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CC=avr-gcc
2+
CXX=avr-gcc
3+
4+
MCU ?= atmega328p
5+
FREQ ?= 16000000
6+
CONFIG_ENABLE_FCS32 ?= n
7+
CONFIG_ENABLE_FCS16 ?= n
8+
CONFIG_ENABLE_CHECKSUM ?= y
9+
CONFIG_ENABLE_STATS ?= n
10+
11+
CPPFLAGS += -mmcu=$(MCU) -DF_CPU=$(FREQ)
12+
13+
include Makefile.common
14+

Makefile.common

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
default: all
2+
DESTDIR ?=
3+
BLD ?= bld
4+
CONFIG_ENABLE_FCS32 ?= y
5+
CONFIG_ENABLE_FCS16 ?= y
6+
CONFIG_ENABLE_CHECKSUM ?= y
7+
8+
VERSION=0.7.0
9+
10+
CPPFLAGS += -I./src
11+
12+
CPPFLAGS += -g -Os -Wall -Werror -ffunction-sections -fdata-sections \
13+
-fno-exceptions
14+
15+
ifeq ($(CONFIG_ENABLE_FCS32),y)
16+
CPPFLAGS += -DCONFIG_ENABLE_FCS32
17+
endif
18+
19+
ifeq ($(CONFIG_ENABLE_FCS16),y)
20+
CPPFLAGS += -DCONFIG_ENABLE_FCS16
21+
endif
22+
23+
ifeq ($(CONFIG_ENABLE_CHECKSUM),y)
24+
CPPFLAGS += -DCONFIG_ENABLE_CHECKSUM
25+
endif
26+
27+
ifeq ($(CONFIG_ENABLE_STATS),y)
28+
CPPFLAGS += -DCONFIG_ENABLE_STATS
29+
endif
30+
31+
.PHONY: clean library all install docs release
32+
33+
####################### Compiling library #########################
34+
35+
TARGET_LIB = libtinyprotocol.a
36+
37+
OBJ_LIB = \
38+
src/proto/crc/crc.o \
39+
src/proto/_old/tiny_layer2.o \
40+
src/proto/light/tiny_light.o \
41+
src/proto/hdlc/tiny_hdlc.o \
42+
src/proto/half_duplex/tiny_hd.o \
43+
src/proto/hal/tiny_list.o \
44+
src/proto/hal/arduino/hal.o \
45+
src/proto/hal/avr/hal.o \
46+
src/proto/hal/esp32/hal.o \
47+
src/proto/hal/linux/hal.o \
48+
src/proto/half_duplex/tiny_rq_pool.o \
49+
tools/serial/serial_linux.o
50+
51+
library: $(OBJ_LIB)
52+
mkdir -p $(BLD)
53+
$(AR) rcs $(BLD)/$(TARGET_LIB) $^
54+
55+
install:
56+
cp -r $(BLD)/$(TARGET_LIB) $(DESTDIR)/usr/lib/
57+
cp -rf ./include/*.h $(DESTDIR)/usr/include/
58+
59+
docs:
60+
doxygen doxygen.cfg
61+
62+
all: library
63+
64+
clean:
65+
rm -rf $(BLD)
66+
rm -rf $(OBJ_LIB)
67+
68+
#clean:
69+
# rm -rf $(BLD)
70+

Makefile.cpputest

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.PHONY: unit_test check clean_unittest
2+
3+
all: unittest
4+
5+
OBJ_UNIT_TEST = \
6+
unittest/helpers/fake_wire.o \
7+
unittest/helpers/fake_channel.o \
8+
unittest/helpers/tiny_helper.o \
9+
unittest/helpers/tiny_hdlc_helper.o \
10+
unittest/helpers/tiny_light_helper.o \
11+
unittest/helpers/tiny_hd_helper.o \
12+
unittest/main.o \
13+
unittest/basic_tests.o \
14+
unittest/hdlc_tests.o \
15+
unittest/light_tests.o \
16+
unittest/hd_tests.o
17+
18+
unittest: $(OBJ_UNIT_TEST) library
19+
$(CXX) $(CPPFLAGS) -o $(BLD)/unit_test $(OBJ_UNIT_TEST) -L$(BLD) -lm -pthread -ltinyprotocol -lCppUTest -lCppUTestExt
20+
21+
check: unittest
22+
$(BLD)/unit_test
23+
24+
clean: clean_unittest
25+
26+
clean_unittest:
27+
rm -rf $(OBJ_UNIT_TEST)

Makefile.esp32

Whitespace-only changes.

Makefile.linux

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.PHONY: sperf clean_sperf
2+
3+
CONFIG_ENABLE_FCS32 ?= y
4+
CONFIG_ENABLE_FCS16 ?= y
5+
CONFIG_ENABLE_CHECKSUM ?= y
6+
CONFIG_ENABLE_STATS ?=y
7+
# ************* Common defines ********************
8+
CPPFLAGS += -I./tools/serial
9+
CPPFLAGS += -fPIC
10+
CFLAGS += -g
11+
LDFLAGS += -L. -lm -shared
12+
13+
include Makefile.common
14+
include Makefile.cpputest
15+
16+
OBJ_SPERF = tools/sperf/sperf.o
17+
18+
all: sperf
19+
20+
sperf: $(OBJ_SPERF) library
21+
$(CC) $(CPPFLAGS) -o $(BLD)/sperf $(OBJ_SPERF) -L$(BLD) -lm -pthread -ltinyprotocol
22+
23+
clean: clean_sperf
24+
25+
clean_sperf:
26+
rm -rf $(OBJ_SPERF)

src/proto/hal/arduino/tiny_defines.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
*/
2929

3030

31-
typedef uint8_t tiny_mutex_t
32-
typedef uint8_t tiny_events_t
31+
typedef uint8_t tiny_mutex_t;
32+
33+
typedef uint8_t tiny_events_t;
3334

3435

3536

src/proto/hal/avr/hal.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
#if defined(__AVR__)
2121

22+
// TODO: <util/atomic.h>
23+
2224
#include "proto/hal/tiny_types.h"
25+
#include <avr/interrupt.h>
26+
#include <util/delay.h>
2327

2428
void tiny_mutex_create(tiny_mutex_t *mutex)
2529
{
@@ -38,7 +42,7 @@ void tiny_mutex_lock(tiny_mutex_t *mutex)
3842
cli();
3943
locked = !*mutex;
4044
*mutex = 1;
41-
sti();
45+
sei();
4246
}
4347
while (!locked);
4448
}
@@ -49,15 +53,15 @@ uint8_t tiny_mutex_try_lock(tiny_mutex_t *mutex)
4953
cli();
5054
locked = !*mutex;
5155
*mutex = 1;
52-
sti();
56+
sei();
5357
return locked;
5458
}
5559

5660
void tiny_mutex_unlock(tiny_mutex_t *mutex)
5761
{
5862
cli();
5963
*mutex = 0;
60-
sti();
64+
sei();
6165
}
6266

6367
void tiny_events_create(tiny_events_t *events)
@@ -77,7 +81,7 @@ uint8_t tiny_events_wait_and_clear(tiny_events_t *events, uint8_t bits)
7781
cli();
7882
locked = *events;
7983
*events &= ~bits;
80-
sti();
84+
sei();
8185
}
8286
while (!(locked & bits));
8387
return locked;
@@ -90,7 +94,7 @@ uint8_t tiny_events_wait(tiny_events_t *events, uint8_t bits)
9094
{
9195
cli();
9296
locked = *events;
93-
sti();
97+
sei();
9498
}
9599
while (!(locked & bits));
96100
return locked;
@@ -100,14 +104,14 @@ void tiny_events_set(tiny_events_t *events, uint8_t bits)
100104
{
101105
cli();
102106
*events |= bits;
103-
sti();
107+
sei();
104108
}
105109

106110
void tiny_events_clear(tiny_events_t *events, uint8_t bits)
107111
{
108112
cli();
109113
*events &= ~bits;
110-
sti();
114+
sei();
111115
}
112116

113117
void tiny_sleep(uint32_t ms)

gen_arduino_release.bat renamed to tools/scripts/gen_arduino_release.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@echo off
22

3+
chdir ..\..
34
rmdir /S /Q releases
45
mkdir releases\arduino\TinyProto\src
56

0 commit comments

Comments
 (0)