Skip to content

Commit

Permalink
Changed makefile (dub based)
Browse files Browse the repository at this point in the history
  • Loading branch information
o3o committed Jul 19, 2016
1 parent d794efa commit 41f225d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 61 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,7 @@
# Dinodave change log

## [Unreleased]
-

## [0.1.0] - 2014-10-28
- Initial revision
4 changes: 2 additions & 2 deletions dub.json
Expand Up @@ -18,11 +18,11 @@
"name": "unittest",
"targetType": "executable",
"targetName": "test-runner",
"sourcePaths": ["tests"],
"sourcePaths": ["tests", "src"],
"mainSourceFile": "tests/app.d",
"excludedSourceFiles": ["src/app.d"],
"dependencies": {
"unit-threaded": "~>0.4.7"
"unit-threaded": "~>0.6.24"
}
}
]
Expand Down
179 changes: 136 additions & 43 deletions makefile
@@ -1,46 +1,139 @@
#makefile release 0.2.0
NAME = libdinodave.a
VERSION = 0.2.0
PROJECT_VERSION = 0.2.0

ROOT_SOURCE_DIR = src
SRC = $(getSources)

SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/app.d, $(SRC))
SRC_TEST += $(wildcard tests/*.d)

# Compiler flag
# -----------
DCFLAGS += -lib
DCFLAGS += -debug #compile in debug code
#DCFLAGS += -g # add symbolic debug info
#DCFLAGS += -w # warnings as errors (compilation will halt)
DCFLAGS += -wi # warnings as messages (compilation will continue)
DCFLAGS += -m64

DCFLAGS_TEST += -unittest
# DCFLAGS_TEST += -main -quiet

# Linker flag
# -----------
DCFLAGS_LINK =-L-lnodave
#DCFLAGS_LINK +=
#DCFLAGS_LINK += -L-L/usr/lib/

# Version flag
# -----------
# VERSION_FLAG = -version=use_gtk

# Packages
# -----------
PKG = $(wildcard $(BIN)/$(NAME))
PKG_SRC = $(PKG) $(SRC) makefile

# -----------
# Libraries
# -----------

# unit-threaded
# -----------
LIB_TEST += $(D_DIR)/unit-threaded/libunit-threaded.a
DCFLAGS_IMPORT_TEST += -I$(D_DIR)/unit-threaded/source

include common.mk
BIN = bin
SRC = $(getSources)
BASE_NAME = $(basename $(NAME))

#############
# Packages #
#############
ZIP = $(BIN)/$(NAME)
ZIP_SRC = $(ZIP) $(SRC) dub.json README.md CHANGELOG.md makefile $(SRC_TEST)
ZIP_PREFIX = $(BASE_NAME)-$(PROJECT_VERSION)

#############
# Test #
#############
TEST_SOURCE_DIR = tests
SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/App.cs, $(SRC))
SRC_TEST += $(shell find $(TEST_SOURCE_DIR) -name "*.d")

getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d")

#############
## commands #
#############
DUB = dub
DSCAN = $(D_DIR)/Dscanner/bin/dscanner
MKDIR = mkdir -p
RM = -rm -f
UPX = upx --no-progress

## flags
DUBFLAGS = -q --combined

.PHONY: all release force run test pkgall pkg pkgtar pkgsrc tags style syn loc clean clobber

DEFAULT: all

all:
$(DUB) build $(DUBFLAGS)

release:
$(DUB) build -brelease $(DUBFLAGS)

force:
$(DUB) build --force $(DUBFLAGS)

run:
$(DUB) run $(DUBFLAGS)

test:
$(DUB) test $(DUBFLAGS)

upx: $(BIN)/$(NAME)
$(UPX) $@

pkgdir:
@mkdir -p pkg

pkgall: pkg pkgtar pkgsrc

pkg: pkgdir | pkg/$(ZIP_PREFIX).zip

pkg/$(ZIP_PREFIX).zip: $(ZIP)
zip $@ $(ZIP)

pkgtar: pkgdir | pkg/$(ZIP_PREFIX).tar.bz2

pkg/$(ZIP_PREFIX).tar.bz2: $(ZIP)
tar -jcf $@ $^

pkgsrc: pkgdir | pkg/$(ZIP_PREFIX)-src.tar.bz2

pkg/$(ZIP_PREFIX)-src.tar.bz2: $(ZIP_SRC)
tar -jcf $@ $^

tags: $(SRC)
$(DSCAN) --ctags $^ > tags

style: $(SRC)
$(DSCAN) --styleCheck $^

syn: $(SRC)
$(DSCAN) --syntaxCheck $^

loc: $(SRC)
$(DSCAN) --sloc $^

clean:
$(DUB) clean

clobber: clean
$(RM) $(BIN)/$(NAME)

ver:
@echo $(PROJECT_VERSION)

var:
@echo NAME: $(NAME)
@echo PRJ_VER: $(PROJECT_VERSION)
@echo BASE_NAME: $(BASE_NAME)
@echo
@echo ==== dir ===
@echo D_DIR: $(D_DIR)
@echo BIN: $(BIN)
@echo ROOT_SOURCE_DIR: $(ROOT_SOURCE_DIR)
@echo TEST_SOURCE_DIR: $(TEST_SOURCE_DIR)
@echo
@echo ==== zip ===
@echo ZIP: $(ZIP)
@echo ZIP_SRC: $(ZIP_SRC)
@echo ZIP_PREFIX: $(ZIP_PREFIX)
@echo
@echo ==== src ===
@echo SRC: $(SRC)

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... release Compiles in release mode"
@echo "... force Forces a recompilation"
@echo "... test Executes the tests"
@echo "... run Builds and runs"
@echo "... clean Removes intermediate build files"
@echo "... clobber"
@echo "... pkg Zip binary"
@echo "... pkgtar Tar binary"
@echo "... pkgsrc Tar source"
@echo "... pkgall Exewcutes pkg, pkgtar, pkgsrc"
@echo "... tags Generates tag file"
@echo "... style Checks programming style"
@echo "... syn Syntax check"
@echo "... upx Compress using upx"
@echo "... loc Counts lines of code"
@echo "... var Lists all variables"
6 changes: 3 additions & 3 deletions src/dinodave/helper.d
Expand Up @@ -56,12 +56,12 @@ ubyte fromBCD(ubyte i) {
* Get error code description
*
* Params: code = error code
*
*
*
* Returns: description of error
* Generally, positive error codes represent errors reported by the PLC,
* Generally, positive error codes represent errors reported by the PLC,
* while negative ones represent errors detected by LIBNODAVE, e.g. no response from the PLC.
*/
string strerror(int code) {
return to!(string)(daveStrerror(code));
}
}
26 changes: 13 additions & 13 deletions src/dinodave/plc.d
Expand Up @@ -23,10 +23,10 @@ interface IPlc {
* DB = The number of a data block
* start = The address of the first byte in the block.
* length = The number of bytes to read.
*
*
* Returns: The function returns 0 on success.
* Nonzero return codes may be passed to daveStrerror() to get a textual explanation of what happened.
*
* Returns: The function returns 0 on success.
* Nonzero return codes may be passed to daveStrerror() to get a textual explanation of what happened.
* Generally, positive error codes represent errors reported by the PLC, while negative ones represent errors detected by LIBNODAVE, e.g. no response from the PLC.
*/
void readBytes(in int DB, in int start, in int length);
Expand Down Expand Up @@ -73,7 +73,7 @@ class IsoTcp: IPlc {
fds.rfd = sock.handle;
fds.wfd = fds.rfd;

if (fds.rfd > 0) {
if (fds.rfd > 0) {
daveInterface* di = daveNewInterface(fds, "IF1", 0, daveProtoISOTCP, daveSpeed9k);
daveSetTimeout(di, 5_000_000);
enum int MPI = 0;
Expand All @@ -100,18 +100,18 @@ class IsoTcp: IPlc {
/**
* Reads a sequence of bytes from PLC memory.
*
* Params:
* Params:
* DB = The number of a data block
* start = The address of the first byte in the block.
* length = The number of bytes to read.
*
* Returns: The function returns 0 on success.
* Nonzero return codes may be passed to `strerror()` to get a textual explanation of what happened.
* Generally, positive error codes represent errors reported by the PLC,
* Returns: The function returns 0 on success.
* Nonzero return codes may be passed to `strerror()` to get a textual explanation of what happened.
* Generally, positive error codes represent errors reported by the PLC,
* while negative ones represent errors detected by LIBNODAVE, e.g. no response from the PLC.
*/
void readBytes(in int DB, in int start, in int length) {
int err = daveReadBytes(dc, daveDB, DB, start, length, null);
const(int) err = daveReadBytes(dc, daveDB, DB, start, length, null);
if (err != 0) {
throw new NodaveException(err);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ class IsoTcp: IPlc {

/**
* Write a sequence of bytes from a buffer to PLC memory.
* Params:
* Params:
* DB = The number of a data block
* start = The address of the first byte in the block.
* length = The number of bytes to write.
Expand All @@ -169,11 +169,11 @@ class IsoTcp: IPlc {
*
*
* Params: param = param description
*
*
*
* Returns: return value
*
* Throws: Exception
* Throws: Exception
*/
int readPLCTime() {
return daveReadPLCTime(dc);
Expand Down Expand Up @@ -201,7 +201,7 @@ class IsoTcp: IPlc {
}

class NodaveException: Exception {
this(int errNo){
this(int errNo) {
string message = strerror(errNo);
this(message);
}
Expand Down
1 change: 1 addition & 0 deletions tests/app.d
@@ -1,5 +1,6 @@
import unit_threaded.runner;
import std.stdio;

int main(string[] args) {
return args.runTests!(
"dinodave.helper",
Expand Down

0 comments on commit 41f225d

Please sign in to comment.