880c00c69e
The new API improves upon the old API in a number of ways: * The old API provided a single data pipe for input and output, and it provided the pipe in the form of a HANDLE opened with FILE_FLAG_OVERLAPPED. Using a bare HANDLE is difficult in higher-level languages, and overlapped/asynchronous I/O is hard to get right. winpty_close closed the data pipe, which also didn't help things, though I think the handle could have been duplicated. Using a single handle for input and output complicates shutdown. When the child process exits, the agent scrapes the final output, then closes the data pipe once its written. It's possible that a winpty client will first detect the closed pipe when it's writing *input* rather than reading output, which seems wrong. (On the other hand, the agent doesn't implement "backpressure" for either input or output (yet), and if it did, it's possible that post-exit shutdown should interrupt a blocked write into the console input queue. I need to think about it more.) The new API splits the data pipe into CONIN and CONOUT pipes, which are accessed by filename. After `winpty_open` returns, the client queries pipe names using `winpty_conin_name` and `winpty_conout_name`, then opens them using any mechanism, low-level or high-level, blocking or overlapped. * The old libwinpty handled errors by killing the process. The new libwinpty uses C++ exceptions internally and translates exceptions at API boundaries using: - a boolean error result (e.g. BOOL, NULL-vs-non-NULL) - a potentially heap-allocated winpty_error_t object returned via an optional winpty_error_ptr_t parameter. That parameter can be NULL. If it isn't, then an error code and message can be queried from the error object. The winpty_error_t object must be freed with winpty_error_free. * winpty_start_process is renamed to winpty_spawn. winpty_open and winpty_spawn accept a "config" object which holds parameters. New configuration options can be added without disturbing the source or binary API. * The winpty_get_exit_code and winpty_get_process_id APIs are removed. The winpty_spawn function has an out parameter providing the child's process and thread HANDLEs (duplicated from the agent via DuplicateHandle). The winpty client can call GetExitCodeProcess and GetProcessId (as well as the WaitForXXX APIs to wait for child exit).
165 lines
4.5 KiB
Makefile
165 lines
4.5 KiB
Makefile
# Copyright (c) 2011-2015 Ryan Prichard
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to
|
|
# deal in the Software without restriction, including without limitation the
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
# IN THE SOFTWARE.
|
|
|
|
# Use make -n to see the actual command-lines make would run.
|
|
|
|
# The default "make install" prefix is /usr/local. Pass PREFIX=<path> on the
|
|
# command-line to override the default.
|
|
|
|
.SECONDEXPANSION :
|
|
|
|
.PHONY : default
|
|
default : all
|
|
|
|
PREFIX := /usr/local
|
|
UNIX_ADAPTER_EXE := winpty.exe
|
|
MINGW_ENABLE_CXX11_FLAG := -std=c++11
|
|
USE_PCH := 1
|
|
|
|
COMMON_CXXFLAGS :=
|
|
UNIX_CXXFLAGS :=
|
|
MINGW_CXXFLAGS :=
|
|
MINGW_LDFLAGS :=
|
|
UNIX_LDFLAGS :=
|
|
|
|
# Include config.mk but complain if it hasn't been created yet.
|
|
ifeq "$(wildcard config.mk)" ""
|
|
$(error config.mk does not exist. Please run ./configure)
|
|
endif
|
|
include config.mk
|
|
|
|
VERSION_TXT_CONTENT := $(shell cat VERSION.txt | tr -d '\r\n')
|
|
COMMON_CXXFLAGS += \
|
|
-DWINPTY_VERSION=$(VERSION_TXT_CONTENT) \
|
|
-DWINPTY_VERSION_SUFFIX=$(VERSION_SUFFIX) \
|
|
-DWINPTY_COMMIT_HASH=$(COMMIT_HASH) \
|
|
-MMD -Wall \
|
|
-DUNICODE \
|
|
-D_UNICODE \
|
|
-D_WIN32_WINNT=0x0501
|
|
|
|
UNIX_CXXFLAGS += \
|
|
$(COMMON_CXXFLAGS)
|
|
|
|
MINGW_CXXFLAGS += \
|
|
$(COMMON_CXXFLAGS) \
|
|
-O2 \
|
|
$(MINGW_ENABLE_CXX11_FLAG)
|
|
|
|
MINGW_LDFLAGS += -static -static-libgcc -static-libstdc++
|
|
UNIX_LDFLAGS += $(UNIX_LDFLAGS_STATIC)
|
|
|
|
ifeq "$(USE_PCH)" "1"
|
|
MINGW_CXXFLAGS += -include build/mingw/PrecompiledHeader.h
|
|
PCH_DEP := build/mingw/PrecompiledHeader.h.gch
|
|
else
|
|
PCH_DEP :=
|
|
endif
|
|
|
|
build/mingw/PrecompiledHeader.h : src/shared/PrecompiledHeader.h | $$(@D)/.mkdir
|
|
$(info Copying $< to $@)
|
|
@cp $< $@
|
|
|
|
build/mingw/PrecompiledHeader.h.gch : build/mingw/PrecompiledHeader.h | $$(@D)/.mkdir
|
|
$(info Compiling $<)
|
|
@$(MINGW_CXX) $(MINGW_CXXFLAGS) -c -o $@ $<
|
|
|
|
-include build/mingw/PrecompiledHeader.h.d
|
|
|
|
define def_unix_target
|
|
build/$1/%.o : src/%.cc VERSION.txt | $$$$(@D)/.mkdir
|
|
$$(info Compiling $$<)
|
|
@$$(UNIX_CXX) $$(UNIX_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
|
|
endef
|
|
|
|
define def_mingw_target
|
|
build/$1/%.o : src/%.cc VERSION.txt $$(PCH_DEP) | $$$$(@D)/.mkdir
|
|
$$(info Compiling $$<)
|
|
@$$(MINGW_CXX) $$(MINGW_CXXFLAGS) $2 -I src/include -c -o $$@ $$<
|
|
endef
|
|
|
|
include src/subdir.mk
|
|
|
|
.PHONY : all
|
|
all : $(ALL_TARGETS)
|
|
|
|
.PHONY : tests
|
|
tests : $(TEST_PROGRAMS)
|
|
|
|
.PHONY : install-bin
|
|
install-bin : all
|
|
mkdir -p $(PREFIX)/bin
|
|
install -m 755 -p -s build/$(UNIX_ADAPTER_EXE) $(PREFIX)/bin
|
|
install -m 755 -p -s build/winpty.dll $(PREFIX)/bin
|
|
install -m 755 -p -s build/winpty-agent.exe $(PREFIX)/bin
|
|
|
|
.PHONY : install-debugserver
|
|
install-debugserver : all
|
|
mkdir -p $(PREFIX)/bin
|
|
install -m 755 -p -s build/winpty-debugserver.exe $(PREFIX)/bin
|
|
|
|
.PHONY : install-lib
|
|
install-lib : all
|
|
mkdir -p $(PREFIX)/lib
|
|
install -m 644 -p build/winpty.lib $(PREFIX)/lib
|
|
|
|
.PHONY : install-doc
|
|
install-doc :
|
|
mkdir -p $(PREFIX)/share/doc/winpty
|
|
install -m 644 -p LICENSE $(PREFIX)/share/doc/winpty
|
|
install -m 644 -p README.md $(PREFIX)/share/doc/winpty
|
|
install -m 644 -p RELEASES.md $(PREFIX)/share/doc/winpty
|
|
|
|
.PHONY : install-include
|
|
install-include :
|
|
mkdir -p $(PREFIX)/include/winpty
|
|
install -m 644 -p src/include/winpty.h $(PREFIX)/include/winpty
|
|
install -m 644 -p src/include/winpty_constants.h $(PREFIX)/include/winpty
|
|
|
|
.PHONY : install
|
|
install : \
|
|
install-bin \
|
|
install-debugserver \
|
|
install-lib \
|
|
install-doc \
|
|
install-include
|
|
|
|
.PHONY : clean
|
|
clean :
|
|
rm -fr build
|
|
|
|
.PHONY : clean-msvs
|
|
clean-msvs :
|
|
rm -fr src/Default src/Release src/.vs
|
|
rm -f src/*.vcxproj src/*.vcxproj.filters src/*.sln src/*.sdf
|
|
|
|
.PHONY : distclean
|
|
distclean : clean
|
|
rm -f config.mk
|
|
|
|
.PRECIOUS : %.mkdir
|
|
%.mkdir :
|
|
$(info Creating directory $(dir $@))
|
|
@mkdir -p $(dir $@)
|
|
@touch $@
|
|
|
|
src/%.h :
|
|
@echo "Missing header file $@ (stale dependency file?)"
|