Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Tcl TIP477 nmake-based builds #15

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generic/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/

#include "multi.h"
#ifndef _WIN32
#include <sys/time.h>
#endif

/*
*----------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion generic/tclcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "tclcurl.h"

#include <sys/types.h>
#ifndef _WIN32
#include <unistd.h>
#endif

/*
*----------------------------------------------------------------------
Expand All @@ -35,7 +37,7 @@
*----------------------------------------------------------------------
*/

int
EXTERN int
Tclcurl_Init (Tcl_Interp *interp) {

if(Tcl_InitStubs(interp,"8.1",0)==NULL) {
Expand Down
4 changes: 2 additions & 2 deletions generic/tclcurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
* I ever understand what it is for.
*/

#ifdef BUILD_tclcurl
#ifdef BUILD_TclCurl
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT
#endif
Expand Down Expand Up @@ -387,7 +387,7 @@ int Tclcurl_MultiInit (Tcl_Interp *interp);

#endif

int Tclcurl_Init(Tcl_Interp *interp);
EXTERN int Tclcurl_Init(Tcl_Interp *interp);

char *curlCreateObjCmd(Tcl_Interp *interp,struct curlObjData *curlData);
int curlInitObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
Expand Down
3 changes: 2 additions & 1 deletion tests/versionInfo.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ test 1.03 {: Test that -features returns something} -body {
test 1.04 {: Test that -sslversion returns something} -body {
# unix sslversion string looks like {^(OpenSSL|GnuTLS|LibreSSL)/\d+\.\d+\.\d+\w*$}
# macosx sslversion string looks like {^SecureTransport \(OpenSSL/\d+\.\d+\.\d+\w*\)$}
# On Windows, Schannel does not provide any version numbers
return [curl::versioninfo -sslversion]
} -match regexp -result {(OpenSSL|GnuTLS|LibreSSL)/\d+\.\d+\.\d+\w*}
} -match regexp -result {((OpenSSL|GnuTLS|LibreSSL)/\d+\.\d+\.\d+\w*)|Schannel}

test 1.05 {: Test that -sslversionnum returns something} -body {
return [curl::versioninfo -sslversionnum]
Expand Down
63 changes: 63 additions & 0 deletions win/makefile.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#------------------------------------------------------------- -*- makefile -*-
#
# Makefile for TclCurl
#
# Example build:
# nmake /f makefile.vc INSTALLDIR=d:\tcl\debug\x64 CURLDIR=D:\src\curl-7.74.0\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-schannel CURLDEPSDIR=D:\src\curl-7.74.0\deps\x64
# nmake /f makefile.vc INSTALLDIR=d:\tcl\debug\x64 CURLDIR=D:\src\curl-7.74.0\builds\libcurl-vc15-x64-release-static-zlib-static-ipv6-sspi-schannel CURLDEPSDIR=D:\src\curl-7.74.0\deps\x64 install
#
# For other build options (debug, static etc.),
# See TIP 477 (https://core.tcl.tk/tips/doc/trunk/tip/477.md) for
# detailed documentation.
#
#
# This makefile assumes static linking to the curl libraries
#------------------------------------------------------------------------------

PROJECT = TclCurl

!if "$(CURLDIR)" == ""
!error Please define CURLDIR on command line to point to CURL distribution containing lib and include dirs.
!endif

# Curl dependencies directory.
!if "$(CURLDEPSDIR)" == ""
!error Please define CURLDEPDIR on command line to point to CURL dependencies containing lib and include dirs.
!endif

# Make package version same as Curl version for now
!if [echo DOTVERSION = \> nmakehlp.out] \
|| [for /f "tokens=3" %i in ('findstr /C:"define LIBCURL_VERSION " $(CURLDIR)\include\curl\curlver.h') do @echo %i >> nmakehlp.out]
!error *** Could not retrieve PACKAGE_VERSION from Curl.
!endif
!include nmakehlp.out

# Remove the quotes from DOTVERSION
DOTVERSION=$(DOTVERSION:"=)
# " - Fix for Emacs highlighting to match quotes above

# Script files (LIBDIR) are in same location as C generic files
# NOTE: define this BEFORE including rules-ext.vc
LIBDIR = $(GENERICDIR)

!include "rules-ext.vc"

PRJ_OBJS = \
$(TMP_DIR)\tclcurl.obj \
$(TMP_DIR)\multi.obj

PRJ_DEFINES = -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE


PRJ_INCLUDES = $(PRJ_INCLUDES) -I"$(CURLDIR)\include" -I"$(CURLDEPSDIR)\include"
PRJ_LIBS = $(PRJ_LIBS) "$(CURLDIR)\lib\libcurl_a.lib" "$(CURLDEPSDIR)\lib\zlib_a.lib" ws2_32.lib crypt32.lib wldap32.lib Normaliz.lib

!include "$(_RULESDIR)\targets.vc"

install: default-install-docs-html default-install-libraries

pkgindex:
@type << >"$(OUT_DIR)\pkgIndex.tcl"
package ifneeded $(PROJECT) $(DOTVERSION) "[list load [file join $$dir $(PRJLIBNAME)] TclCurl]; [list source [file join $$dir tclcurl.tcl]]"
<<

118 changes: 118 additions & 0 deletions win/rules-ext.vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# This file should only be included in makefiles for Tcl extensions,
# NOT in the makefile for Tcl itself.

!ifndef _RULES_EXT_VC

# We need to run from the directory the parent makefile is located in.
# nmake does not tell us what makefile was used to invoke it so parent
# makefile has to set the MAKEFILEVC macro or we just make a guess and
# warn if we think that is not the case.
!if "$(MAKEFILEVC)" == ""

!if exist("$(PROJECT).vc")
MAKEFILEVC = $(PROJECT).vc
!elseif exist("makefile.vc")
MAKEFILEVC = makefile.vc
!endif
!endif # "$(MAKEFILEVC)" == ""

!if !exist("$(MAKEFILEVC)")
MSG = ^
You must run nmake from the directory containing the project makefile.^
If you are doing that and getting this message, set the MAKEFILEVC^
macro to the name of the project makefile.
!message WARNING: $(MSG)
!endif

!if "$(PROJECT)" == "tcl"
!error The rules-ext.vc file is not intended for Tcl itself.
!endif

# We extract version numbers using the nmakehlp program. For now use
# the local copy of nmakehlp. Once we locate Tcl, we will use that
# one if it is newer.
!if [$(CC) -nologo "nmakehlp.c" -link -subsystem:console > nul]
!endif

# First locate the Tcl directory that we are working with.
!if "$(TCLDIR)" != ""

_RULESDIR = $(TCLDIR:/=\)

!else

# If an installation path is specified, that is also the Tcl directory.
# Also Tk never builds against an installed Tcl, it needs Tcl sources
!if defined(INSTALLDIR) && "$(PROJECT)" != "tk"
_RULESDIR=$(INSTALLDIR:/=\)
!else
# Locate Tcl sources
!if [echo _RULESDIR = \> nmakehlp.out] \
|| [nmakehlp -L generic\tcl.h >> nmakehlp.out]
_RULESDIR = ..\..\tcl
!else
!include nmakehlp.out
!endif

!endif # defined(INSTALLDIR)....

!endif # ifndef TCLDIR

# Now look for the targets.vc file under the Tcl root. Note we check this
# file and not rules.vc because the latter also exists on older systems.
!if exist("$(_RULESDIR)\lib\nmake\targets.vc") # Building against installed Tcl
_RULESDIR = $(_RULESDIR)\lib\nmake
!elseif exist("$(_RULESDIR)\win\targets.vc") # Building against Tcl sources
_RULESDIR = $(_RULESDIR)\win
!else
# If we have not located Tcl's targets file, most likely we are compiling
# against an older version of Tcl and so must use our own support files.
_RULESDIR = .
!endif

!if "$(_RULESDIR)" != "."
# Potentially using Tcl's support files. If this extension has its own
# nmake support files, need to compare the versions and pick newer.

!if exist("rules.vc") # The extension has its own copy

!if [echo TCL_RULES_MAJOR = \> versions.vc] \
&& [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MAJOR >> versions.vc]
!endif
!if [echo TCL_RULES_MINOR = \>> versions.vc] \
&& [nmakehlp -V "$(_RULESDIR)\rules.vc" RULES_VERSION_MINOR >> versions.vc]
!endif

!if [echo OUR_RULES_MAJOR = \>> versions.vc] \
&& [nmakehlp -V "rules.vc" RULES_VERSION_MAJOR >> versions.vc]
!endif
!if [echo OUR_RULES_MINOR = \>> versions.vc] \
&& [nmakehlp -V "rules.vc" RULES_VERSION_MINOR >> versions.vc]
!endif
!include versions.vc
# We have a newer version of the support files, use them
!if ($(TCL_RULES_MAJOR) != $(OUR_RULES_MAJOR)) || ($(TCL_RULES_MINOR) < $(OUR_RULES_MINOR))
_RULESDIR = .
!endif

!endif # if exist("rules.vc")

!endif # if $(_RULESDIR) != "."

# Let rules.vc know what copy of nmakehlp.c to use.
NMAKEHLPC = $(_RULESDIR)\nmakehlp.c

# Get rid of our internal defines before calling rules.vc
!undef TCL_RULES_MAJOR
!undef TCL_RULES_MINOR
!undef OUR_RULES_MAJOR
!undef OUR_RULES_MINOR

!if exist("$(_RULESDIR)\rules.vc")
!message *** Using $(_RULESDIR)\rules.vc
!include "$(_RULESDIR)\rules.vc"
!else
!error *** Could not locate rules.vc in $(_RULESDIR)
!endif

!endif # _RULES_EXT_VC