Convert the makefiles from recursive to non-recursive

* This change reduces the total build time from about 14 seconds to about
   9 seconds on my computer.

Also:

 * Consolidate all the intermediate files into the build directory to
   reduces clutter.

 * Allow specifying UNIX_ADAPTER_EXE to make.  Perhaps this will be helpful
   to the MSYS2 fork, which renames console.exe to winpty.exe.  (I like
   the renaming, but I don't know about the other winpty users.  Maybe
   I'll make the change after I've put out another stable release...)

 * Rename the WINPTY define to COMPILING_WINPTY_DLL define.  The longer
   name is clearer.  I define the macro inside libwinpty/winpty.cc, so the
   build system no longer needs to.  (I removed the define from
   winpty.gyp.)

 * Consolidate config-unix.mk and config-mingw.mk into config.mk.  The
   separation was previously necessary because each file had a conflicting
   definition of CXX.

 * Rename the UNIX_LDFLAGS_STATIC_LIBSTDCXX macro to UNIX_LDFLAGS_STATIC,
   because libstdc++ isn't the only thing I'm linking statically.
This commit is contained in:
Ryan Prichard 2015-11-06 22:08:24 -06:00
parent 70eafd08d3
commit 52b11bfba9
16 changed files with 105 additions and 213 deletions

9
.gitignore vendored
View File

@ -1,8 +1,3 @@
*.o
*.d
*.h.gch
*.exe
*.dll
*.sln
*.suo
*.vcxproj
@ -10,5 +5,5 @@
Default
winpty.sdf
winpty.opensdf
config-mingw.mk
config-unix.mk
/config.mk
/build

View File

@ -18,33 +18,64 @@
# 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.
default : all
PREFIX ?= /usr/local
UNIX_ADAPTER_EXE ?= console.exe
all :
cd agent && $(MAKE)
cd libwinpty && $(MAKE)
cd unix-adapter && $(MAKE)
cd debugserver && $(MAKE)
# 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
tests :
cd tests && $(MAKE)
UNIX_CXXFLAGS += -MMD -Wall
MINGW_CXXFLAGS += \
-MMD -Wall \
-DUNICODE \
-D_UNICODE \
-D_WIN32_WINNT=0x0501 \
-fno-exceptions \
-fno-rtti \
-O2
MINGW_LDFLAGS += -static -static-libgcc -static-libstdc++
UNIX_LDFLAGS += $(UNIX_LDFLAGS_STATIC)
include agent/subdir.mk
include debugserver/subdir.mk
include libwinpty/subdir.mk
include tests/subdir.mk
include unix-adapter/subdir.mk
all : $(ALL_TARGETS)
tests : $(TEST_PROGRAMS)
install : all
mkdir -p $(PREFIX)/bin
install -m 755 -p -s build/console.exe $(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
install -m 755 -p -s build/winpty-debugserver.exe $(PREFIX)/bin
clean :
cd agent && $(MAKE) clean
cd libwinpty && $(MAKE) clean
cd unix-adapter && $(MAKE) clean
cd debugserver && $(MAKE) clean
cd tests && $(MAKE) clean
rm -fr build
distclean : clean
rm -f config-unix.mk
rm -f config-mingw.mk
rm -f config.mk
.PHONY : all tests install clean distclean
.PHONY : default all tests install clean distclean
build/mingw/%.o : %.cc
@echo Compiling $<
@mkdir -p $$(dirname $@)
@$(MINGW_CXX) $(MINGW_CXXFLAGS) -I include -c -o $@ $<
build/unix/%.o : %.cc
@echo Compiling $<
@mkdir -p $$(dirname $@)
@$(UNIX_CXX) $(UNIX_CXXFLAGS) -I include -c -o $@ $<

View File

@ -18,46 +18,27 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
include ../config.mk
include ../config-mingw.mk
ALL_TARGETS += build/winpty-agent.exe
PROGRAM = ../build/winpty-agent.exe
AGENT_OBJECTS = \
build/mingw/agent/Agent.o \
build/mingw/agent/ConsoleFont.o \
build/mingw/agent/ConsoleInput.o \
build/mingw/agent/ConsoleLine.o \
build/mingw/agent/Coord.o \
build/mingw/agent/EventLoop.o \
build/mingw/agent/LargeConsoleRead.o \
build/mingw/agent/NamedPipe.o \
build/mingw/agent/SmallRect.o \
build/mingw/agent/Terminal.o \
build/mingw/agent/Win32Console.o \
build/mingw/agent/main.o \
build/mingw/shared/DebugClient.o \
build/mingw/shared/WinptyAssert.o \
build/mingw/shared/winpty_wcsnlen.o
OBJECTS = \
EventLoop.o \
NamedPipe.o \
Agent.o \
WinptyAssert.o \
Terminal.o \
Win32Console.o \
ConsoleInput.o \
DebugClient.o \
Coord.o \
SmallRect.o \
ConsoleLine.o \
ConsoleFont.o \
LargeConsoleRead.o \
winpty_wcsnlen.o \
main.o
CXXFLAGS += \
-DUNICODE \
-D_UNICODE \
-D_WIN32_WINNT=0x0501 \
-fno-exceptions \
-fno-rtti \
-O2
LDFLAGS += -static -static-libgcc -static-libstdc++
all : $(PROGRAM)
$(PROGRAM) : $(OBJECTS)
build/winpty-agent.exe : $(AGENT_OBJECTS)
@echo Linking $@
@$(CXX) -o $@ $^ $(LDFLAGS)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -o $@ $^
.PHONY : clean
clean:
rm -f $(PROGRAM) *.o *.d
-include $(OBJECTS:.o=.d)
-include $(AGENT_OBJECTS:.o=.d)

View File

View File

@ -1,43 +0,0 @@
# Copyright (c) 2011-2012 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.
CFLAGS += -MMD -Wall
CXXFLAGS += -MMD -Wall
# Use gmake -n to see the command-lines gmake would run.
%.o : %.c
@echo Compiling $<
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
%.o : %.cc
@echo Compiling $<
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
%.o : ../shared/%.cc
@echo Compiling $<
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
# Attempt to detect whether configure has been run yet. The CWD will
# be one of the subdirectories, so refer to ../config-mingw.mk instead
# of ./config-mingw.mk.
ifeq "$(wildcard ../config-mingw.mk)" ""
$(error config-mingw.mk does not exist. Please run ./configure)
endif

13
configure vendored
View File

@ -52,7 +52,7 @@ IS_MSYS=0
# also statically linked and therefore depend only on Windows DLLs. I started
# linking the Cygwin/MSYS binary statically, because G++ 4.7 changed the
# Windows C++ ABI.
UNIX_LDFLAGS_STATIC_LIBSTDCXX='-static -static-libgcc -static-libstdc++'
UNIX_LDFLAGS_STATIC='-static -static-libgcc -static-libstdc++'
# Detect the environment -- Cygwin or MSYS.
case $(uname -s) in
@ -109,7 +109,7 @@ case $(uname -s) in
# This is suboptimal because MSYS2 is not actually the
# second version of MSYS--it's a brand-new fork of Cygwin.
#
UNIX_LDFLAGS_STATIC_LIBSTDCXX=
UNIX_LDFLAGS_STATIC=
fi
;;
x86_64)
@ -136,8 +136,7 @@ findTool "MinGW G++ compiler" "$MINGW_GPP"
MINGW_GPP=$FINDTOOL_OUT
# Write config files.
echo Writing config-unix.mk
echo CXX=$UNIX_GPP > config-unix.mk
echo LDFLAGS_STATIC_LIBSTDCXX=$UNIX_LDFLAGS_STATIC_LIBSTDCXX >> config-unix.mk
echo Writing config-mingw.mk
echo CXX=$MINGW_GPP > config-mingw.mk
echo Writing config.mk
echo UNIX_CXX=$UNIX_GPP > config.mk
echo UNIX_LDFLAGS_STATIC=$UNIX_LDFLAGS_STATIC >> config.mk
echo MINGW_CXX=$MINGW_GPP >> config.mk

View File

@ -18,31 +18,13 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
include ../config.mk
include ../config-mingw.mk
ALL_TARGETS += build/winpty-debugserver.exe
PROGRAM = ../build/winpty-debugserver.exe
DEBUGSERVER_OBJECTS = \
build/mingw/debugserver/DebugServer.o
OBJECTS = \
DebugServer.o
CXXFLAGS += \
-DUNICODE \
-D_UNICODE \
-D_WIN32_WINNT=0x0501 \
-fno-exceptions \
-fno-rtti
LDFLAGS += -static -static-libgcc -static-libstdc++
all : $(PROGRAM)
$(PROGRAM) : $(OBJECTS)
build/winpty-debugserver.exe : $(DEBUGSERVER_OBJECTS)
@echo Linking $@
@$(CXX) -o $@ $^ $(LDFLAGS)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -o $@ $^
.PHONY : clean
clean:
rm -f $(PROGRAM) *.o *.d
-include $(OBJECTS:.o=.d)
-include $(DEBUGSERVER_OBJECTS:.o=.d)

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <windows.h>
#ifdef WINPTY
#ifdef COMPILING_WINPTY_DLL
#define WINPTY_API __declspec(dllexport)
#else
#define WINPTY_API __declspec(dllimport)

View File

@ -18,22 +18,14 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
include ../config.mk
include ../config-unix.mk
ALL_TARGETS += build/winpty.dll
PROGRAM = ../build/console.exe
OBJECTS = main.o Shared.o
CXXFLAGS += -I../include
LDFLAGS += $(LDFLAGS_STATIC_LIBSTDCXX) ../build/winpty.dll
LIBWINPTY_OBJECTS = \
build/mingw/libwinpty/winpty.o \
build/mingw/shared/DebugClient.o
all : $(PROGRAM)
$(PROGRAM) : $(OBJECTS)
build/winpty.dll : $(LIBWINPTY_OBJECTS)
@echo Linking $@
@$(CXX) -o $@ $^ $(LDFLAGS)
@$(MINGW_CXX) $(MINGW_LDFLAGS) -shared -o $@ $^
.PHONY : clean
clean:
rm -f $(PROGRAM) *.o *.d
-include $(OBJECTS:.o=.d)
-include $(LIBWINPTY_OBJECTS:.o=.d)

View File

@ -18,6 +18,8 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#define COMPILING_WINPTY_DLL
#include <winpty.h>
#include <windows.h>
#include <assert.h>

View File

@ -1 +1 @@
build/
/build

View File

@ -1,4 +1,5 @@
include ../../config-mingw.mk
include ../../config.mk
CXX = $(MINGW_CXX)
# Pass -Wno-format to disable format checking because gcc complains about
# %I64x. I can't use %lld because it's broken on MinGW-on-WinXP, though it

View File

@ -18,22 +18,11 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
include ../config.mk
include ../config-mingw.mk
LDFLAGS += -static-libgcc -static-libstdc++
../build/%.exe : %.cc
build/%.exe : tests/%.cc build/winpty.dll
@echo Building $@
@$(CXX) $(CXXFLAGS) -std=c++11 -o $@ $^ $(LDFLAGS) ../build/winpty.dll
@$(MINGW_CXX) $(MINGW_CXXFLAGS) $(MINGW_LDFLAGS) -std=c++11 -o $@ $^
TEST_PROGRAMS := \
../build/trivial_test.exe
all : $(TEST_PROGRAMS)
.PHONY : clean
clean:
rm -f *.o *.d $(TEST_PROGRAMS) $(TEST_PROGRAMS:.exe=.d)
TEST_PROGRAMS = \
build/trivial_test.exe
-include $(TEST_PROGRAMS:.exe=.d)

View File

@ -1,21 +0,0 @@
// Copyright (c) 2011-2012 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.
#include "../shared/DebugClient.cc"

View File

@ -18,29 +18,14 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
include ../config.mk
include ../config-mingw.mk
ALL_TARGETS += build/$(UNIX_ADAPTER_EXE)
LIBRARY = ../build/winpty.dll
OBJECTS = winpty.o DebugClient.o
LDFLAGS += -shared -static -static-libgcc -static-libstdc++
UNIX_ADAPTER_OBJECTS = \
build/unix/unix-adapter/main.o \
build/unix/shared/DebugClient.o
CXXFLAGS += \
-I../include \
-DUNICODE \
-D_UNICODE \
-D_WIN32_WINNT=0x0501 \
-DWINPTY \
-fno-exceptions \
-fno-rtti \
-O2
$(LIBRARY) : $(OBJECTS)
build/$(UNIX_ADAPTER_EXE) : $(UNIX_ADAPTER_OBJECTS) build/winpty.dll
@echo Linking $@
@$(CXX) $(LDFLAGS) -o $@ $^
@$(UNIX_CXX) $(UNIX_LDFLAGS) -o $@ $^
.PHONY : clean
clean :
rm -f $(LIBRARY) *.o *.d
-include $(OBJECTS:.o=.d)
-include $(UNIX_ADAPTER_OBJECTS:.o=.d)

View File

@ -64,7 +64,6 @@
'_UNICODE',
'_WIN32_WINNT=0x0501',
'NOMINMAX',
'WINPTY',
],
'libraries' : [
'-luser32.lib',