diff --git a/.gitignore b/.gitignore index 6c0ea0c..d7f38f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,43 +1,32 @@ + +# Build config +/build.conf +/.idea + # Prerequisites *.d # Object files *.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp # Precompiled Headers *.gch *.pch # Libraries -*.lib *.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib # Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex +/src/main_cli +/src/main_tui # Debug files *.dSYM/ *.su *.idb *.pdb + +#Test +/test/test_main +/test/test_main2 +/test/test_log diff --git a/Makefile.conf b/Makefile.conf index 267977e..b03e43e 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -1,15 +1,17 @@ -TARGET=orca_tui +LIBNAME:=orca +LIB:=lib$(LIBNAME).a C_LANG_VERSION=c99 CXX_LANG_VERSION=c++11 # Build option defaults -PREFIX?=/opt/local +PREFIX?=$(HOME)/local +SYS_PREFIX?=/opt/local DEBUG?=1 PORTMIDI_ENABLED?=1 MOUSE_ENABLED?=1 -COMPILE_FLAGS:=\ +COMPILE_FLAGS:= -MMD CFLAGS:=-std=$(C_LANG_VERSION) CFLAGS+=\ @@ -42,16 +44,19 @@ else ifneq (,$(findstring clang,$(CXX))) COMPILE_FLAGS+=-fcolor-diagnostics endif - +LIBS:=-lstdc++ -lpEpCxx11 +# ncurses LDFLAGS_NCURSES=$(shell pkg-config --libs ncursesw formw) LDFLAGS+=$(LDFLAGS_NCURSES) -LDFLAGS+=-lstdc++ +LDFLAGS+=$(LIBS) ######### Overrides from build.conf ######### HERE:=$(dir $(lastword $(MAKEFILE_LIST))) -include $(HERE)build.conf +COMPILE_FLAGS+=-isystem$(SYS_PREFIX)/include COMPILE_FLAGS+=-I$(PREFIX)/include +LDFLAGS+=-L$(SYS_PREFIX)/lib LDFLAGS+=-L$(PREFIX)/lib ifeq ($(DEBUG),1) diff --git a/src/Makefile b/src/Makefile index 411af6a..bc5fce5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,53 +1,32 @@ -# Copyright 2022, pEp Foundation -# This file is part of libpEpCxx11 -# This file may be used under the terms of the GNU General Public License version 3 -# see LICENSE - include ../Makefile.conf -EXE_MAIN_CLI:=cli_main -EXE_MAIN_TUI:=tui_main -EXE_MAIN_TEST:=test_main - -OBJ_MAIN_CLI:=$(EXE_MAIN_CLI).o -OBJ_MAIN_TUI:=$(EXE_MAIN_TUI).o -OBJ_MAIN_TEST:=$(EXE_MAIN_TEST).o - -C_SOURCES:=$(wildcard *.c) -CXX_SOURCES+=$(wildcard *.cc) -HEADERS:=$(wildcard *.h) - -OBJECTS:=$(subst .c,.o,$(C_SOURCES)) -OBJECTS+=$(subst .cc,.o,$(CXX_SOURCES)) -OBJECTS:=$(filter-out $(OBJ_MAIN_CLI),$(OBJECTS)) -OBJECTS:=$(filter-out $(OBJ_MAIN_TUI),$(OBJECTS)) -OBJECTS:=$(filter-out $(OBJ_MAIN_TEST),$(OBJECTS)) +SRC:=$(wildcard *.c*) +SRC_EXE:=$(filter main_%, $(SRC)) +SRC_LIB=$(filter-out main_%, $(SRC)) +OBJS:=$(addsuffix .o, $(basename $(SRC))) +OBJS_LIB:=$(addsuffix .o, $(basename $(SRC_LIB))) +EXE:=$(basename $(SRC_EXE)) +DEPS:=$(addsuffix .d, $(basename $(SRC))) -DEPENDS:=$(subst .c,.d,$(SOURCE)) -CFLAGS+= -MMD -MP +.PHONY: all install uninstall clean +.DEFAULT_GOAL:= all ifneq ($(MAKECMDGOALS),clean) - -include $(DEPENDS) + -include $(DEPS) endif -.PHONY: all install uninstall clean -.DEFAULT_GOAL := all - -#all: $(EXE_MAIN_CLI) $(EXE_MAIN_TUI) $(EXE_MAIN_TEST) -all: $(EXE_MAIN_CLI) $(EXE_MAIN_TUI) - -$(EXE_MAIN_CLI): $(OBJECTS) $(OBJ_MAIN_CLI) +all: $(EXE) -$(EXE_MAIN_TUI): $(OBJECTS) $(OBJ_MAIN_TUI) +$(LIB): $(OBJS) + $(AR) -rc $@ $(OBJS_LIB) -$(EXE_MAIN_TEST): $(OBJECTS) $(OBJ_MAIN_TEST) +$(EXE) : $(LIB) clean: - rm -vf \ - $(DEPENDS) \ - $(OBJECTS) \ - $(OBJ_MAIN_TUI) \ - $(OBJ_MAIN_CLI) \ - $(EXE_MAIN_TUI) \ - $(EXE_MAIN_CLI) \ - $(EXE_MAIN_TEST) + rm -rf \ + $(OBJS) \ + $(EXE) \ + $(LIB) \ + $(DEPS) \ + *.dSYM \ + *.h.gch \ No newline at end of file diff --git a/src/cli_main.c b/src/main_cli.c similarity index 100% rename from src/cli_main.c rename to src/main_cli.c diff --git a/src/tui_main.c b/src/main_tui.c similarity index 99% rename from src/tui_main.c rename to src/main_tui.c index 5dc37c0..965c82f 100644 --- a/src/tui_main.c +++ b/src/main_tui.c @@ -6,8 +6,9 @@ #include "sysmisc.h" #include "term_util.h" #include "midi.h" +#include "net.h" -// many transisitve includes +// many transitive includes #include "ged.h" #include "tui.h" @@ -19,6 +20,7 @@ #undef SOKOL_IMPL + #define TIME_DEBUG 0 #if TIME_DEBUG static int spin_track_timeout = 0; @@ -141,7 +143,7 @@ void main_init(int argc, char **argv) int init_grid_dim_y = 25; int init_grid_dim_x = 57; bool explicit_initial_grid_size = false; - + net_init(); tui_init(&tui, &ged); int longindex = 0; diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..090fcc0 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,31 @@ +include ../Makefile.conf + +SRC:=$(wildcard *.c*) +SRC_EXE:=$(filter test_%, $(SRC)) +EXE:=$(basename $(SRC_EXE)) + +$(info src exe: $(SRC_EXE)) +$(info lib: $(LIB)) +$(info exe: $(EXE)) + +LDFLAGS+=-L../src +CFLAGS+=-I../src +CXXFLAGS+=-I../src + +.PHONY: lib all clean ../src/$(LIB) +.DEFAULT_GOAL := all + +all: $(EXE) + +../src/$(LIB): + $(MAKE) -C ../src $(LIB) + +$(EXE): ../src/$(LIB) + +clean: + rm -rf \ + $(OBJS) \ + $(EXE) \ + $(DEPS) \ + *.dSYM \ + *.h.gch \ No newline at end of file diff --git a/test/test_main.cc b/test/test_main.cc new file mode 100644 index 0000000..9c629eb --- /dev/null +++ b/test/test_main.cc @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SOKOL_IMPL +#include "sokol_time.h" +#undef SOKOL_IMPL + + +void init_sockaddr(sockaddr_in *name, std::string hostname, uint16_t port) +{ + + hostent *hostinfo = nullptr; + name->sin_family = AF_INET; + name->sin_port = htons(port); + hostinfo = gethostbyname(hostname.c_str()); + if (hostinfo == nullptr) { + pEpLog("Unknown host: " + hostname); + exit(1); + } + name->sin_addr = *(struct in_addr *)hostinfo->h_addr; +} + + +int make_socket(uint16_t port) +{ + int sock; + sockaddr_in name; + + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) { + pEpLog(strerror(errno)); + exit(1); + } + + name.sin_family = AF_INET; + name.sin_port = htons(port); + name.sin_addr.s_addr = htonl(INADDR_ANY); + if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) { + pEpLog(strerror(errno)); + exit(1); + } + + return sock; +} + +int main(int argc, char *argv[]) +{ + pEp::Adapter::pEpLog::set_enabled(true); + pEpLog("fdsfsd"); + int socket = make_socket(23232); + + return 0; +} \ No newline at end of file