Skip to content

Commit a8b1f17

Browse files
authored
Linux (#4)
* Added Linux make files and CI job
1 parent b0ef381 commit a8b1f17

File tree

4 files changed

+163
-16
lines changed

4 files changed

+163
-16
lines changed

.gitlab-ci.yml

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ variables:
44
stages:
55
- download
66
- build
7+
- ZipUp
78

89
#
910
# Download CBACnet Stack libaries
1011
# -----------------------------------------------------------------------------
1112
# How to download artifacts from jobs in Gitlab CI https://docs.gitlab.com/ee/api/jobs.html#download-the-artifacts-archive
1213
# Note: the SETTING_PRIVATE_TOKEN parameter is a enviment variable, generated by Steven's user.
1314
#
14-
Download BACnet Stack Libaries Windows:
15+
Download BACnet Stack Libaries:
1516
stage: download
1617
tags:
1718
- docker
@@ -25,11 +26,15 @@ Download BACnet Stack Libaries Windows:
2526
- "apk --no-cache add unzip curl"
2627
- 'curl --location --output CASBACnetStackLibs.zip --header "PRIVATE-TOKEN: $SETTING_PRIVATE_TOKEN" "https://gitlab.com/api/v4/projects/7281208/jobs/artifacts/master/download?job=Windows%20Release%20Win32%20CASBACnetStack%20LIB&job_token=$CI_JOB_TOKEN"'
2728
- unzip CASBACnetStackLibs.zip && rm -f CASBACnetStackLibs.zip
29+
- 'curl --location --output CASBACnetStackLibs.zip --header "PRIVATE-TOKEN: $SETTING_PRIVATE_TOKEN" "https://gitlab.com/api/v4/projects/7281208/jobs/artifacts/master/download?job=Linux-Ubuntu%20Release%20x64%20CASBACnetStack&job_token=$CI_JOB_TOKEN"'
30+
- unzip CASBACnetStackLibs.zip && rm -f CASBACnetStackLibs.zip
2831
- ls -ls bin/
2932
artifacts:
33+
expire_in: 1 days
3034
paths:
3135
- bin/*.lib
32-
36+
- bin/*.a
37+
3338
# Build the windows version
3439
Windows Win32 Release:
3540
stage: build
@@ -40,10 +45,8 @@ Windows Win32 Release:
4045
# Add MSBuild.exe to path
4146
- set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
4247
# Update the CIBuildVersion.cs
43-
- cd BACnetServerExample
44-
- "echo const int CIBUILDNUMBER = %CI_PIPELINE_IID%; > CIBuildVersion.h"
45-
- type CIBuildVersion.h
46-
- cd ..
48+
- "echo const int CI_PIPELINE_IID = %CI_PIPELINE_IID% >BACnetServerExample/CIBuildSettings.h"
49+
- type BACnetServerExample\CIBuildVersion.h
4750
script:
4851
# Create the bin directory if it does not exist
4952
- cd BACnetServerExample
@@ -52,7 +55,54 @@ Windows Win32 Release:
5255
- cd ..\bin
5356
- dir
5457
artifacts:
58+
expire_in: 1 days
59+
paths:
60+
- bin/BACnetServerExample_Win32_Release.exe
61+
dependencies:
62+
- Download BACnet Stack Libaries
63+
64+
# Build the linux 64bit version
65+
Linux 64Bit Release:
66+
stage: build
67+
tags:
68+
- docker
69+
image: ssmethurst/ubuntudev-18_04:latest
70+
before_script:
71+
# Update the CIBuildVersion.cs
72+
- echo -e "const int CI_PIPELINE_IID = $CI_PIPELINE_IID\n" >BACnetServerExample/CIBuildSettings.h
73+
# debug info
74+
- "gcc -v"
75+
script:
76+
- "make"
77+
- "make install"
78+
artifacts:
79+
expire_in: 1 days
5580
paths:
56-
- bin\BACnetServerExample_Win32_Release.exe
81+
- bin/BACnetServerExampleCPP_linux_x64_Release
5782
dependencies:
58-
- Download BACnet Stack Libaries Windows
83+
- Download BACnet Stack Libaries
84+
85+
86+
# CreateZip
87+
Create Zip:
88+
stage: ZipUp
89+
tags:
90+
- docker
91+
image: alpine:latest
92+
variables:
93+
GIT_SUBMODULE_STRATEGY: none
94+
only:
95+
- master
96+
dependencies:
97+
- Linux 64Bit Release
98+
- Windows Win32 Release
99+
script:
100+
# Install Zip
101+
- "apk --no-cache add zip"
102+
# Remove the old zip if it exists for some reason
103+
- "rm -f BACnetServerExampleCPP_build$CIPIPELINE_IID.zip"
104+
# Add all the compiled libaries from other jobs.
105+
- "zip BACnetServerExampleCPP_build$CI_PIPELINE_IID.zip -r9 bin/BACnetServerExampleCPP_linux_x64_Release bin/BACnetServerExample_Win32_Release.exe"
106+
artifacts:
107+
paths:
108+
- BACnetServerExampleCPP_build$CI_PIPELINE_IID.zip

BACnetServerExample/BACnetServerExample.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// BACnetServerExample.cpp : This file contains the 'main' function. Program execution begins and ends there.
22
//
33

4-
#include <iostream>
5-
6-
#ifndef __GNUC__ // Windows
7-
#include <conio.h> // _kbhit
8-
#endif // __GNUC__
9-
104
#include "CASBACnetStackAdapter.h"
115
#include "CASBACnetStackExampleConstants.h"
126
#include "CASBACnetStackExampleDatabase.h"
@@ -18,14 +12,33 @@
1812
#include "ChipkinConvert.h"
1913
#include "ChipkinUtilities.h"
2014

15+
#include <iostream>
16+
#ifndef __GNUC__ // Windows
17+
#include <conio.h> // _kbhit
18+
#else // Linux
19+
#include <sys/ioctl.h>
20+
#include <termios.h>
21+
bool _kbhit() {
22+
termios term;
23+
tcgetattr(0, &term);
24+
termios term2 = term;
25+
term2.c_lflag &= ~ICANON;
26+
tcsetattr(0, TCSANOW, &term2);
27+
int byteswaiting;
28+
ioctl(0, FIONREAD, &byteswaiting);
29+
tcsetattr(0, TCSANOW, &term);
30+
return byteswaiting > 0;
31+
}
32+
#endif // __GNUC__
33+
2134
// Globals
2235
// =======================================
2336
CSimpleUDP g_udp; // UDP resource
2437
ExampleDatabase g_database; // The example database that stores current values.
2538

2639
// Constants
2740
// =======================================
28-
const std::string APPLICATION_VERSION = "0.0.2";
41+
const std::string APPLICATION_VERSION = "0.0.3"; // See CHANGELOG.md for a full list of changes.
2942
const uint32_t MAX_XML_RENDER_BUFFER_LENGTH = 1024 * 20;
3043

3144

@@ -488,7 +501,11 @@ int main()
488501
g_database.Loop();
489502

490503
// Call Sleep to give some time back to the system
491-
Sleep(0);
504+
#ifdef _WIN32
505+
Sleep(0); // Windows
506+
#else
507+
sleep(0); // Linux
508+
#endif
492509
}
493510

494511
// All done.

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Change Log
2+
3+
## Version 0.0.x
4+
5+
### 0.0.3.x (2020-Feb-12)
6+
7+
- Added Linux make files and linux CI job.
8+
9+
### 0.0.2.x (2020-Feb-11)
10+
11+
- Added CI build for Windows release
12+
13+
### 0.0.1.x (2019-Aug-22)
14+
15+
- Inital release.

makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# The Compiler: gcc for C, g++ for C++
2+
CC := g++
3+
NAME := BACnetServerExampleCPP_linux_x64_Release
4+
5+
# Compiler flags:
6+
# -m32 for 32bit, -m64 for 64bit
7+
# -Wall turns on most, but not all, compiler warnings
8+
#
9+
CFLAGS := -m64 -Wall
10+
11+
DEBUGFLAGS = -O0 -g3 -DCAS_BACNET_STACK_LIB_TYPE_LIB
12+
RELEASEFLAGS = -O3 -DCAS_BACNET_STACK_LIB_TYPE_LIB
13+
OBJECTFLAGS = -c -fmessage-length=0 -fPIC -MMD -MP
14+
LDFLAGS = -static
15+
16+
SOURCES = $(wildcard BACnetServerExample/*.cpp) $(wildcard submodules/cas-bacnet-stack/adapters/cpp/*.cpp) $(wildcard submodules/cas-bacnet-stack/submodules/cas-common/source/*.cpp)
17+
OBJECTS = $(addprefix obj/,$(notdir $(SOURCES:.cpp=.o)))
18+
INCLUDES = -IBACnetServerExample -Isubmodules/cas-bacnet-stack/adapters/cpp -Isubmodules/cas-bacnet-stack/source -Isubmodules/cas-bacnet-stack/submodules/cas-common/source
19+
LIBPATH = -Lbin
20+
LIB = -ldl -lCASBACnetStack_x64_Release
21+
22+
# Build Target
23+
TARGET = $(NAME)
24+
25+
all: $(NAME)
26+
27+
$(NAME): $(OBJECTS)
28+
@echo 'Building target: $@'
29+
$(CC) $(CFLAGS) $(LDFLAGS) -o $(NAME) $(OBJECTS) $(LIBPATH) $(LIB)
30+
@echo 'Finished building target: $@'
31+
@echo ' '
32+
33+
obj/%.o: BACnetServerExample/%.cpp
34+
@mkdir -p obj
35+
@echo 'Building file: $<'
36+
@echo 'Invoking: GCC C++ Compiler'
37+
$(CC) $(RELEASEFLAGS) $(CFLAGS) $(OBJECTFLAGS) $(INCLUDES) $(LIBPATH) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o $@ $<
38+
@echo 'Finished building: $<'
39+
@echo ' '
40+
41+
obj/%.o: submodules/cas-bacnet-stack/adapters/cpp/%.cpp
42+
@mkdir -p obj
43+
@echo 'Building file: $<'
44+
@echo 'Invoking: GCC C++ Compiler'
45+
$(CC) $(RELEASEFLAGS) $(CFLAGS) $(OBJECTFLAGS) $(INCLUDES) $(LIBPATH) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o $@ $<
46+
@echo 'Finished building: $<'
47+
@echo ' '
48+
49+
obj/%.o: submodules/cas-bacnet-stack/submodules/cas-common/source/%.cpp
50+
@mkdir -p obj
51+
@echo 'Building file: $<'
52+
@echo 'Invoking: GCC C++ Compiler'
53+
$(CC) $(RELEASEFLAGS) $(CFLAGS) $(OBJECTFLAGS) $(INCLUDES) $(LIBPATH) -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o $@ $<
54+
@echo 'Finished building: $<'
55+
@echo ' '
56+
57+
install:
58+
install -D $(NAME) bin/$(NAME)
59+
$(RM) $(NAME)
60+
61+
# make clean
62+
# Removes target file and any .o object files,
63+
# .d dependency files, or ~ backup files
64+
clean:
65+
$(RM) $(NAME) obj/* *~

0 commit comments

Comments
 (0)