Last active
May 26, 2018 03:06
-
-
Save gvanem/7d10b3c9e519ad388721 to your computer and use it in GitHub Desktop.
GNU makefile for Pylibnet and MSVC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# GNU Makefile for libnet.pyd (MSVC) | |
# Only Python 2.7 have been tested. | |
# | |
# By G. Vanem <gvanem@yahoo.no> 2013. | |
# | |
# | |
# Options and paths. Change to suite your setup. | |
# | |
# Use Winsock-tracer library. Ref.: | |
# https://github.com/gvanem/wsock-trace/ | |
# | |
USE_WSTRACE = 0 | |
# | |
# The '4' should match your libnet version. | |
# I have no idea what the '4' represents. Watch the warnings/errors | |
# to verify the number is correct. And from src/constants.h: | |
# #if LIBNET_RELEASE >= 4 | |
# {"HSRP_H", LIBNET_HSRP_H}, | |
# ... | |
# | |
# If you compiled libnet with libnet_build_hsrp.c, you can probably | |
# safely set '-DLIBNET_RELEASE=4'. | |
# | |
CFLAGS = -DLIBNET_RELEASE=4 | |
LIBNET_ROOT = ../libnet | |
PYTHON_ROOT = $(realpath $(PYTHON_INCLUDE_DIR)/..) | |
# | |
# In case 'sh.exe' is on PATH, we'll pick up e.g. CygWin's python in it's PATH. | |
# We DONT want that. Hence specify SHELL explisitly. Using 'SHELL = 4nt.exe' | |
# does not seem to work. | |
# | |
SHELL = cmd.exe | |
# | |
# Not needed | |
# .SHELLFLAGS = /C | |
# | |
# | |
# This fails if 'sh' uses e.g. CygWin's python in it's PATH. | |
# | |
PYTHON_ROOT = $(shell python.exe -c "from distutils import sysconfig; print(sysconfig.project_base)") | |
PYTHON_ROOT := $(subst \,/,$(PYTHON_ROOT)) | |
CC = cl | |
CFLAGS += -nologo -Zi -Ox -MD -W3 -GS- -DNDEBUG \ | |
-D_WINSOCK_DEPRECATED_NO_WARNINGS -D__WIN32__ \ | |
-I./src -I$(LIBNET_ROOT)/include -I$(PYTHON_ROOT)/include | |
LDFLAGS = -nologo -libpath:$(PYTHON_ROOT)/libs -dll -incremental:no \ | |
-map -debug -verbose -subsystem:console -export:initlibnet | |
ifeq ($(USE_WSTRACE),1) | |
EX_LIBS = wsock_trace.lib | |
else | |
EX_LIBS = ws2_32.lib | |
endif | |
all: libnet.pyd | |
libnet.pyd: libnetmodule.obj $(LIBNET_ROOT)/src/libnet_imp.lib Makefile.MSVC | |
link $(LDFLAGS) -out:$@ libnetmodule.obj $(LIBNET_ROOT)/src/libnet_imp.lib $(EX_LIBS) > link.tmp | |
cat link.tmp >> libnet.map | |
rm -f link.tmp libnet.lib libnet.exp | |
@echo . | |
install: libnet.pyd libnet.pdb | |
cp --update $^ $(PYTHON_ROOT)/Lib/site-packages | |
@echo . | |
libnetmodule.obj: | |
$(CC) -c $(CFLAGS) src/libnetmodule.c | |
@echo . | |
clean vclean realclean: | |
rm -f libnet.pyd libnet.pdb libnetmodule.obj libnet.map .depend.MSVC | |
test: | |
@echo '$$(PYTHON_ROOT): "$(PYTHON_ROOT)".' | |
depend: | |
gcc -MM $(filter -I% -D%, $(CFLAGS)) src/libnetmodule.c | \ | |
sed -e 's/\(.*\)\.o: /\1.obj: /' > .depend.MSVC | |
-include .depend.MSVC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment