diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-04-24 17:41:54 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-04-24 17:41:54 +0200 |
commit | 785dde4caef136c59a30f8142ffdb0b59757c4e9 (patch) | |
tree | b12d9be48e50e6f6515565b41a76e5ec96d07b2d | |
parent | a3afac01c87283038d66d4f89918873637dadc84 (diff) |
Re-worked all the Makefile's as they were not sufficient for external projects.
* simplified DriverThread::SpinLock
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | DriverThread.cpp | 13 | ||||
-rw-r--r-- | DriverThread.hpp | 6 | ||||
-rw-r--r-- | Makefile | 64 | ||||
-rw-r--r-- | Makefile.deps | 81 | ||||
-rw-r--r-- | Makefile.external | 100 | ||||
-rw-r--r-- | Makefile.inc | 163 | ||||
-rw-r--r-- | Makefile.internal | 113 | ||||
-rw-r--r-- | README.md | 30 |
8 files changed, 299 insertions, 271 deletions
diff --git a/DriverThread.cpp b/DriverThread.cpp index c048c04..efc4023 100644 --- a/DriverThread.cpp +++ b/DriverThread.cpp @@ -71,14 +71,19 @@ DriverThread::Spinlock::Spinlock(void) KeInitializeSpinLock(&m_spinLock); } -NTSTATUS DriverThread::Spinlock::Acquire(KIRQL * const oldIrql) +NTSTATUS DriverThread::Spinlock::Acquire(void) { - return KeAcquireSpinLock(&m_spinLock, oldIrql); + return KeAcquireSpinLock(&m_spinLock, &m_oldIrql); } -void DriverThread::Spinlock::Release(KIRQL * const oldIrql) +void DriverThread::Spinlock::Release(void) { - KeReleaseSpinLock(&m_spinLock, *oldIrql); + KeReleaseSpinLock(&m_spinLock, m_oldIrql); +} + +KIRQL DriverThread::Spinlock::GetOldIrql(void) +{ + return m_oldIrql; } // Semaphore diff --git a/DriverThread.hpp b/DriverThread.hpp index a15b3d1..d00db1b 100644 --- a/DriverThread.hpp +++ b/DriverThread.hpp @@ -58,10 +58,12 @@ class Spinlock { public: Spinlock(void); - NTSTATUS Acquire(KIRQL * const oldIrql); - void Release(KIRQL * const oldIrql); + NTSTATUS Acquire(void); + void Release(void); + KIRQL GetOldIrql(void); private: + KIRQL m_oldIrql; KSPIN_LOCK m_spinLock; }; @@ -1,65 +1,59 @@ 1_DRIVER_NAME = ddk-template -1_SOURCES = $(1_DRIVER_NAME).c 1_OBJECTS = $(1_DRIVER_NAME).o 1_TARGET = $(1_DRIVER_NAME).sys 2_DRIVER_NAME = ddk-template-cplusplus -2_SOURCES = $(2_DRIVER_NAME).cpp 2_OBJECTS = $(2_DRIVER_NAME).opp 2_TARGET = $(2_DRIVER_NAME).sys 3_DRIVER_NAME = ddk-template-cplusplus-EASTL -3_SOURCES = $(3_DRIVER_NAME).cpp 3_OBJECTS = $(3_DRIVER_NAME).opp 3_TARGET = $(3_DRIVER_NAME).sys DPP_ROOT = . INSTALL = install -all: $(1_TARGET) $(2_TARGET) $(3_TARGET) +all: deps $(1_TARGET) $(2_TARGET) $(3_TARGET) + +include $(DPP_ROOT)/Makefile.inc + +deps: + $(call CHECK_DPP) + +%.o: %.c + $(call BUILD_C_OBJECT,$<,$@) + +%.opp: %.cpp + $(call BUILD_CPP_OBJECT,$<,$@) + +# simple C driver +$(1_TARGET): $(1_OBJECTS) + $(call LINK_C_KERNEL_TARGET,$(1_OBJECTS),$@) + +# C++ driver w/ MT +$(2_TARGET): $(2_OBJECTS) + $(call LINK_CPP_KERNEL_TARGET,$(2_OBJECTS),$@) + +# C++ driver w/ EASTL +$(3_TARGET): $(3_OBJECTS) + $(call LINK_CPP_KERNEL_TARGET,$(3_OBJECTS),$@) install: all - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DESTDIR=$(DESTDIR) \ - TARGETS="$(1_TARGET) $(2_TARGET) $(3_TARGET)" \ - DRIVER_DIR="$(CURDIR)" \ - install-sign + $(call INSTALL_EXEC_SIGN,$(1_TARGET)) + $(call INSTALL_EXEC_SIGN,$(2_TARGET)) + $(call INSTALL_EXEC_SIGN,$(3_TARGET)) $(INSTALL) $(1_DRIVER_NAME).bat $(DESTDIR) $(INSTALL) $(2_DRIVER_NAME).bat $(DESTDIR) $(INSTALL) $(3_DRIVER_NAME).bat $(DESTDIR) distclean: clean - $(MAKE) -C $(DPP_ROOT) -f Makefile.external distclean + $(MAKE) -C $(DPP_ROOT) -f Makefile.deps distclean clean: - $(MAKE) -C $(DPP_ROOT) -f Makefile.external clean + $(MAKE) -C $(DPP_ROOT) -f Makefile.deps clean rm -f $(1_OBJECTS) $(1_TARGET) rm -f $(2_OBJECTS) $(2_TARGET) rm -f $(3_OBJECTS) $(3_TARGET) -# simple C driver -$(1_TARGET): $(1_SOURCES) - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DRIVER_TARGET="$(1_TARGET)" \ - DRIVER_DIR="$(CURDIR)" \ - DRIVER_OBJECTS="$(1_OBJECTS)" \ - driver-c - -# C++ driver w/ MT -$(2_TARGET): $(2_SOURCES) - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DRIVER_TARGET="$(2_TARGET)" \ - DRIVER_DIR="$(CURDIR)" \ - DRIVER_OBJECTS="$(2_OBJECTS)" \ - driver-cpp - -# C++ driver w/ EASTL -$(3_TARGET): $(3_SOURCES) - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DRIVER_TARGET="$(3_TARGET)" \ - DRIVER_DIR="$(CURDIR)" \ - DRIVER_OBJECTS="$(3_OBJECTS)" \ - driver-cpp - .PHONY: all install distclean clean .DEFAULT_GOAL := all diff --git a/Makefile.deps b/Makefile.deps new file mode 100644 index 0000000..1824d6e --- /dev/null +++ b/Makefile.deps @@ -0,0 +1,81 @@ +DPP_ROOT = . +include Makefile.inc + +all: deps + +%.o: %.c + $(Q)$(CC) -std=c99 $(CFLAGS) -c $< -o $@ + @echo 'CC $@' + +%.opp: %.cpp + $(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(EASTL_CXXFLAGS) -c $< -o $@ + @echo 'CXX $@' + +deps-print-local-notice: $(CC) +ifeq ($(CC),$(LOCAL_MINGW64_CC)) + @echo + @echo "-- [Build Config]" + @echo "-- CC : $(realpath $(CC))" + @echo "-- CXX: $(realpath $(CXX))" + @echo "-- DDK: $(realpath $(DDK_INCLUDE_DIR))" + @echo +endif + +$(LOCAL_MINGW64_BUILD_SCRIPT): +ifeq ($(CC),$(LOCAL_MINGW64_CC)) + @echo + @echo "------------------------------------------------------------------------------" + @echo "-- ./mingw-w64-build/mingw-w64-build does not exist, clonging git submodule --" + @echo "------------------------------------------------------------------------------" + @echo + git submodule update --init mingw-w64-build +endif + +$(LOCAL_MINGW64_CC): $(LOCAL_MINGW64_BUILD_SCRIPT) +ifeq ($(CC),$(LOCAL_MINGW64_CC)) + @echo + @echo "----------------------------------------------------------------------------------------" + @echo "-- ./x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc does not exist, building toolchain --" + @echo "----------------------------------------------------------------------------------------" + @echo + env -i ./mingw-w64-build/mingw-w64-build x86_64 +endif + +deps-build: \ + $(LOCAL_MINGW64_BUILD_SCRIPT) \ + $(LOCAL_MINGW64_CC) \ + $(EASTL_STATIC_LIB) \ + $(DRIVER_ADDITIONAL_OBJS) \ + $(DRIVER_EASTL_COMPAT) \ + $(USER_EASTL_COMPAT) \ + $(SIGNTOOL_PREFIX) + +deps: deps-print-local-notice deps-build + +$(EASTL_STATIC_LIB): $(EASTL_DEPS) + mkdir -p EASTL-build + cd EASTL-build && \ + $(CMAKE) ../EASTL \ + -DCMAKE_CXX_COMPILER="$(realpath $(CXX))" \ + -DCMAKE_SYSTEM_NAME="Windows" \ + -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ + -DCMAKE_CXX_FLAGS='-ffunction-sections -fdata-sections $(CXXFLAGS) $(EASTL_CXXFLAGS)' && \ + $(MAKE) $(CMAKE_Q) + +$(SIGNTOOL_PREFIX)-code.p12: + ./create_codesign_ca.sh $(SIGNTOOL_PREFIX) + +$(SIGNTOOL_PREFIX): $(SIGNTOOL_PREFIX)-code.p12 + +distclean: clean + rm -f $(SIGNTOOL_PREFIX)-ca-* $(SIGNTOOL_PREFIX)-code-* + rm -rf $(LOCAL_MINGW64_BUILD_DIR) + git submodule deinit --all + +clean: + rm -f $(DRIVER_EASTL_COMPAT) $(USER_EASTL_COMPAT) $(EASTL_STATIC_LIB) + rm -f $(DRIVER_ADDITIONAL_OBJS) + rm -rf EASTL-build + +.PHONY: all deps-print-local-notice deps-build deps distclean clean +.DEFAULT_GOAL := all diff --git a/Makefile.external b/Makefile.external deleted file mode 100644 index 162450c..0000000 --- a/Makefile.external +++ /dev/null @@ -1,100 +0,0 @@ -include Makefile.internal - -%.o: %.c - $(Q)$(CC) -std=c99 $(CFLAGS) -c $< -o $@ - @echo 'CC $@' - -%.opp: %.cpp - $(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(EASTL_CXXFLAGS) -c $< -o $@ - @echo 'CXX $@' - -check-driver-env: -ifndef DRIVER_TARGET - $(error DRIVER_TARGET is undefined) -endif -ifndef DRIVER_DIR - $(error DRIVER_DIR is undefined) -endif -ifndef DRIVER_OBJECTS - $(error DRIVER_OBJECTS is undefined) -endif - -check-user-env: -ifndef USER_TARGET - $(error USER_TARGET is undefined) -endif -ifndef USER_DIR - $(error USER_DIR is undefined) -endif -ifndef USER_OBJECTS - $(error USER_OBJECTS is undefined) -endif - -driver-c: check-driver-env deps $(addprefix $(DRIVER_DIR)/,$(DRIVER_OBJECTS)) - $(Q)$(CC) \ - $(DRIVER_LDFLAGS) \ - -o '$(DRIVER_DIR)/$(DRIVER_TARGET)' \ - $(addprefix $(DRIVER_DIR)/,$(DRIVER_OBJECTS)) \ - $(DRIVER_LIBS) - @echo 'LD $(DRIVER_DIR)/$(DRIVER_TARGET)' - -user-c: check-user-env deps $(addprefix $(USER_DIR)/,$(USER_OBJECTS)) - $(Q)$(CC) \ - $(USER_LDFLAGS) \ - -o '$(USER_DIR)/$(USER_TARGET)' \ - $(addprefix $(USER_DIR)/,$(USER_OBJECTS)) - @echo 'LD $(USER_DIR)/$(USER_TARGET)' - -driver-cpp: check-driver-env deps \ - $(DRIVER_ADDITIONAL_HDRS) $(DRIVER_ADDITIONAL_OBJS) \ - $(EASTL_STATIC_LIB) $(DRIVER_EASTL_COMPAT) \ - $(addprefix $(DRIVER_DIR)/,$(DRIVER_OBJECTS)) - - $(Q)$(CXX) \ - $(CXXFLAGS) \ - $(EASTL_CXXFLAGS) \ - $(DRIVER_LDFLAGS) \ - -o '$(DRIVER_DIR)/$(DRIVER_TARGET)' \ - $(addprefix $(DRIVER_DIR)/,$(DRIVER_OBJECTS)) \ - $(DRIVER_ADDITIONAL_OBJS) $(DRIVER_EASTL_COMPAT) $(EASTL_STATIC_LIB) $(DRIVER_LIBS) - @echo 'LD $(DRIVER_DIR)/$(DRIVER_TARGET)' - -user-cpp: check-user-env deps \ - $(EASTL_STATIC_LIB) $(USER_EASTL_COMPAT) \ - $(addprefix $(USER_DIR)/,$(USER_OBJECTS)) - - $(Q)$(CXX) \ - $(CXXFLAGS) \ - $(EASTL_CXXFLAGS) \ - $(USER_LDFLAGS) \ - -o '$(USER_DIR)/$(USER_TARGET)' \ - $(addprefix $(USER_DIR)/,$(USER_OBJECTS)) \ - $(USER_EASTL_COMPAT) $(EASTL_STATIC_LIB) - @echo 'LD $(USER_DIR)/$(USER_TARGET)' - -check-env-install: -ifndef TARGETS - $(error TARGETS is undefined) -endif - -install: check-env-install $(addprefix $(DRIVER_DIR)/,$(TARGETS)) - $(INSTALL) -d '$(DESTDIR)/' - for target in $(addprefix $(DRIVER_DIR)/,$(TARGETS)); do \ - $(INSTALL) -s --strip-program='$(dir $(CC))/x86_64-w64-mingw32-strip' "$$target" '$(DESTDIR)'; \ - done - -install-sign: check-env-install $(SIGNTOOL_PREFIX) $(addprefix $(DRIVER_DIR)/,$(TARGETS)) - $(INSTALL) -d '$(DESTDIR)/' - test -x '$(shell which $(SIGNTOOL))' || { \ - printf '\n *** %s ***\n\n' "$(SIGNTOOL) does not exist / not in your PATH / not executable."; \ - false; \ - } - for target in $(TARGETS); do \ - rm -f "$(DESTDIR)/$$target"; \ - $(SIGNTOOL) sign -pkcs12 $(SIGNTOOL_PREFIX)-code.p12 -ac $(SIGNTOOL_PREFIX)-ca-cert.pem \ - -in "$(DRIVER_DIR)/$$target" \ - -out "$(DESTDIR)/$$target"; \ - done - $(INSTALL) "$(SIGNTOOL_PREFIX)-ca-cert.pem" '$(DESTDIR)/$(SIGNTOOL_PREFIX)-ca-cert.crt' - -.PHONY: check-driver-env check-user-env driver-c driver-cpp user-c user-cpp check-env-install install install-sign diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..8e3f9d1 --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,163 @@ +ifndef DPP_ROOT +$(error DPP_ROOT is undefined) +endif + +Q = @ +ifeq ($(Q),) +CMAKE_Q = VERBOSE=1 +endif +DPP_ROOT ?= . +LOCAL_MINGW64_BUILD_SCRIPT := $(DPP_ROOT)/mingw-w64-build/mingw-w64-build +LOCAL_MINGW64_BUILD_DIR := $(DPP_ROOT)/x86_64-w64-mingw32 +LOCAL_MINGW64_CC := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-gcc +SIGNTOOL := osslsigncode +SIGNTOOL_PREFIX := codesign + +INSTALL = install +CMAKE = cmake +CC = $(LOCAL_MINGW64_CC) +CXX = $(dir $(CC))x86_64-w64-mingw32-g++ +DDK_INCLUDE_DIR = $(dir $(CC))../x86_64-w64-mingw32/include/ddk +CFLAGS := -Wall -Wextra -m64 -shared -fPIC \ + -I$(DPP_ROOT) -I$(DDK_INCLUDE_DIR) \ + -D__INTRINSIC_DEFINED_InterlockedBitTestAndSet \ + -D__INTRINSIC_DEFINED_InterlockedBitTestAndReset +CXXFLAGS := -fno-exceptions -fno-rtti +EASTL_CXXFLAGS := -I$(DPP_ROOT)/EASTL/include -I$(DPP_ROOT)/EASTL/test/packages/EABase/include/Common \ + -DEASTL_THREAD_SUPPORT_AVAILABLE=0 \ + -DEASTL_EXCEPTIONS_ENABLED=0 \ + -DEASTL_ASSERT_ENABLED=0 \ + -DEA_COMPILER_NO_EXCEPTIONS=1 \ + -DEA_COMPILER_MANAGED_CPP=1 \ + -Wno-unknown-pragmas \ + -Wno-deprecated-copy +DRIVER_LDFLAGS := -Wl,--subsystem,native \ + -Wl,--image-base,0x140000000 \ + -Wl,--dynamicbase -Wl,--nxcompat \ + -Wl,--file-alignment,0x200 \ + -Wl,--section-alignment,0x1000 \ + -Wl,--stack,0x100000 \ + -Wl,--entry,DriverEntry \ + -Wl,--gc-sections \ + -nostartfiles -nostdlib +DRIVER_LIBS := -lntoskrnl -lhal +USER_LDFLAGS := -Wl,--dynamicbase -Wl,--nxcompat \ + -Wl,--gc-sections + +DRIVER_ADDITIONAL_DEPS := $(DPP_ROOT)/DriverThread.cpp $(DPP_ROOT)/DriverThread.hpp +DRIVER_ADDITIONAL_OBJS := $(DPP_ROOT)/DriverThread.opp + +EASTL_DEPS := $(wildcard $(DPP_ROOT)/EASTL/source/*.cpp) $(wildcard $(DPP_ROOT)/EASTL/include/EASTL/*.h) +EASTL_STATIC_LIB := $(DPP_ROOT)/EASTL-build/libEASTL.a + +DRIVER_EASTL_COMPAT_DEPS := $(DPP_ROOT)/EASTL-compat/kcrt.cpp +DRIVER_EASTL_COMPAT := $(DPP_ROOT)/EASTL-compat/kcrt.opp + +USER_EASTL_COMPAT_DEPS := $(DPP_ROOT)/EASTL-compat/ucrt.cpp +USER_EASTL_COMPAT := $(DPP_ROOT)/EASTL-compat/ucrt.opp + +is_set = \ + $(if $1,, \ + $(error ERROR: $(if $2,$2))) + +define BUILD_C_OBJECT + $(call is_set,$(1),First argument: Source file missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CC) -std=c99 $(CFLAGS) -c $(1) -o $(2) + @echo 'CC $(2)' +endef + +define BUILD_CPP_OBJECT + $(call is_set,$(1),First argument: Source file missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CXX) $(CFLAGS) $(CXXFLAGS) $(EASTL_CXXFLAGS) -c $(1) -o $(2) + @echo 'CXX $@' +endef + +define LINK_C_KERNEL_TARGET + $(call is_set,$(1),First argument: Object files missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CC) \ + $(CFLAGS) \ + $(DRIVER_LDFLAGS) \ + -o '$(2)' \ + $(1) \ + $(DRIVER_LIBS) + @echo 'LD $(2)' +endef + +define LINK_C_USER_TARGET + $(call is_set,$(1),First argument: Object files missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CC) \ + $(CFLAGS) \ + -o '$(2)' \ + $(1) \ + $(EASTL_STATIC_LIB) \ + @echo 'LD $(2)' +endef + +define LINK_CPP_KERNEL_TARGET + $(call is_set,$(1),First argument: Object files missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CXX) \ + $(CFLAGS) \ + $(CXXFLAGS) \ + $(EASTL_CXXFLAGS) \ + $(DRIVER_LDFLAGS) \ + -o '$(2)' \ + $(1) \ + $(DRIVER_ADDITIONAL_OBJS) \ + $(DRIVER_EASTL_COMPAT) \ + $(EASTL_STATIC_LIB) \ + $(DRIVER_LIBS) + @echo 'LD $(2)' +endef + +define LINK_CPP_USER_TARGET + $(call is_set,$(1),First argument: Object files missing) + $(call is_set,$(2),Second argument: Output object file missing) + $(Q)$(CXX) \ + $(CFLAGS) \ + $(CXXFLAGS) \ + $(EASTL_CXXFLAGS) \ + $(USER_LDFLAGS) \ + -o '$(2)' \ + $(1) \ + $(USER_EASTL_COMPAT) \ + $(EASTL_STATIC_LIB) + @echo 'LD $(2)' +endef + +define INSTALL_EXEC + $(call is_set,$(1),First argument: Executables to install missing) + $(call is_set,$(DESTDIR),DESTDIR missing) + $(INSTALL) -d '$(DESTDIR)/' + for target in $(1); do \ + $(INSTALL) -s --strip-program='$(dir $(CC))/x86_64-w64-mingw32-strip' "$$target" '$(DESTDIR)'; \ + done +endef + +define INSTALL_EXEC_SIGN + $(call is_set,$(1),First argument: Executables to install missing) + $(call is_set,$(DESTDIR),DESTDIR missing) + $(MAKE) -C '$(DPP_ROOT)' -f Makefile.deps $(SIGNTOOL_PREFIX) + $(INSTALL) -d '$(DESTDIR)/' + test -x '$(shell which $(SIGNTOOL))' || { \ + printf '\n *** %s ***\n\n' "$(SIGNTOOL) does not exist / not in your PATH / not executable."; \ + false; \ + } + for target in $(1); do \ + rm -f "$(DESTDIR)/$$target"; \ + $(dir $(CC))/x86_64-w64-mingw32-strip -s "$$target"; \ + $(SIGNTOOL) sign -pkcs12 '$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-code.p12' \ + -ac '$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-ca-cert.pem' \ + -in "$$target" \ + -out "$(DESTDIR)/$$target"; \ + done + $(INSTALL) "$(DPP_ROOT)/$(SIGNTOOL_PREFIX)-ca-cert.pem" '$(DESTDIR)/$(SIGNTOOL_PREFIX)-ca-cert.crt' +endef + +define CHECK_DPP + $(MAKE) -C $(DPP_ROOT) -f Makefile.deps all +endef diff --git a/Makefile.internal b/Makefile.internal deleted file mode 100644 index d2d895d..0000000 --- a/Makefile.internal +++ /dev/null @@ -1,113 +0,0 @@ -Q = @ -ifeq ($(Q),) -CMAKE_Q = VERBOSE=1 -endif -ifeq ($(DPP_EXTERNAL_MAKEFILE),) -DPP_EXTERNAL_MAKEFILE := . -endif -LOCAL_MINGW64_BUILD_SCRIPT := $(DPP_EXTERNAL_MAKEFILE)/mingw-w64-build/mingw-w64-build -LOCAL_MINGW64_BUILD_DIR := $(DPP_EXTERNAL_MAKEFILE)/x86_64-w64-mingw32 -LOCAL_MINGW64_CC := $(LOCAL_MINGW64_BUILD_DIR)/bin/x86_64-w64-mingw32-gcc -SIGNTOOL := osslsigncode -SIGNTOOL_PREFIX := codesign - -INSTALL = install -CMAKE = cmake -CC = $(LOCAL_MINGW64_CC) -CXX = $(dir $(CC))/x86_64-w64-mingw32-g++ -DDK_INCLUDE_DIR = $(dir $(CC))../x86_64-w64-mingw32/include/ddk -CFLAGS := -Wall -Wextra -m64 -shared -fPIC \ - -I. -I$(DDK_INCLUDE_DIR) \ - -D__INTRINSIC_DEFINED_InterlockedBitTestAndSet \ - -D__INTRINSIC_DEFINED_InterlockedBitTestAndReset -CXXFLAGS := -fno-exceptions -fno-rtti -EASTL_CXXFLAGS := -IEASTL/include -IEASTL/test/packages/EABase/include/Common \ - -DEASTL_THREAD_SUPPORT_AVAILABLE=0 \ - -DEASTL_EXCEPTIONS_ENABLED=0 \ - -DEASTL_ASSERT_ENABLED=0 \ - -DEA_COMPILER_NO_EXCEPTIONS=1 \ - -DEA_COMPILER_MANAGED_CPP=1 \ - -Wno-unknown-pragmas \ - -Wno-deprecated-copy -DRIVER_LDFLAGS := -Wl,--subsystem,native \ - -Wl,--image-base,0x140000000 \ - -Wl,--dynamicbase -Wl,--nxcompat \ - -Wl,--file-alignment,0x200 \ - -Wl,--section-alignment,0x1000 \ - -Wl,--stack,0x100000 \ - -Wl,--entry,DriverEntry \ - -Wl,--gc-sections \ - -nostartfiles -nostdlib -DRIVER_LIBS := -lntoskrnl -lhal -USER_LDFLAGS := -Wl,--dynamicbase -Wl,--nxcompat \ - -Wl,--gc-sections - -DRIVER_ADDITIONAL_OBJS := DriverThread.opp -DRIVER_ADDITIONAL_HDRS := DriverThread.hpp -EASTL_STATIC_LIB := EASTL-build/libEASTL.a -DRIVER_EASTL_COMPAT := EASTL-compat/kcrt.opp -USER_EASTL_COMPAT := EASTL-compat/ucrt.opp -DEPS_STAMP := .deps-built - -deps-print-local-notice: $(CC) -ifeq ($(CC),$(LOCAL_MINGW64_CC)) - @echo - @echo "-- [Build Config]" - @echo "-- CC : $(realpath $(CC))" - @echo "-- CXX: $(realpath $(CXX))" - @echo "-- DDK: $(realpath $(DDK_INCLUDE_DIR))" - @echo -endif - -$(LOCAL_MINGW64_BUILD_SCRIPT): -ifeq ($(CC),$(LOCAL_MINGW64_CC)) - @echo - @echo "------------------------------------------------------------------------------" - @echo "-- ./mingw-w64-build/mingw-w64-build does not exist, clonging git submodule --" - @echo "------------------------------------------------------------------------------" - @echo - git submodule update --init mingw-w64-build -endif - -$(LOCAL_MINGW64_CC): $(LOCAL_MINGW64_BUILD_SCRIPT) -ifeq ($(CC),$(LOCAL_MINGW64_CC)) - @echo - @echo "----------------------------------------------------------------------------------------" - @echo "-- ./x86_64-w64-mingw32/bin/x86_64-w64-mingw32-gcc does not exist, building toolchain --" - @echo "----------------------------------------------------------------------------------------" - @echo - env -i ./mingw-w64-build/mingw-w64-build x86_64 -endif - -$(DEPS_STAMP): $(LOCAL_MINGW64_BUILD_SCRIPT) $(LOCAL_MINGW64_CC) - touch $(DEPS_STAMP) - -deps: deps-print-local-notice $(DEPS_STAMP) - -$(EASTL_STATIC_LIB): $(DEPS_STAMP) - mkdir -p EASTL-build - cd EASTL-build && \ - $(CMAKE) ../EASTL \ - -DCMAKE_CXX_COMPILER="$(realpath $(CXX))" \ - -DCMAKE_SYSTEM_NAME="Windows" \ - -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ - -DCMAKE_CXX_FLAGS='-ffunction-sections -fdata-sections $(CXXFLAGS) $(EASTL_CXXFLAGS)' && \ - $(MAKE) $(CMAKE_Q) - -$(SIGNTOOL_PREFIX)-code.p12: - ./create_codesign_ca.sh $(SIGNTOOL_PREFIX) - -$(SIGNTOOL_PREFIX): $(SIGNTOOL_PREFIX)-code.p12 - -distclean: clean - rm -f $(DEPS_STAMP) - rm -rf $(LOCAL_MINGW64_BUILD_DIR) - rm -f codesign* - git submodule deinit --all - -clean: - rm -f $(DRIVER_EASTL_COMPAT) $(USER_EASTL_COMPAT) $(EASTL_STATIC_LIB) - rm -f $(DRIVER_ADDITIONAL_OBJS) - rm -rf EASTL-build - -.PHONY: deps distclean-deps clean-deps @@ -37,25 +37,25 @@ make deps ## HowTo use it in your own project -At the moment only **GMake** is supported. -The process is similiar to KBuild from the Linux kernel. -You'll write a minimal Makefile that triggers some targets from **Makefile.external**. - -You can use the **Makefile** in this repository. +At the moment only a **GMake** build system is supported. A minimal working **Makefile** for your own project could look alike: ```make DRIVER_NAME = Driver -DRIVER_SOURCES = $(DRIVER_NAME).cpp DRIVER_OBJECTS = $(DRIVER_NAME).opp DRIVER_TARGET = $(DRIVER_NAME).sys -$(DRIVER_TARGET): $(DRIVER_SOURCES) - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DRIVER_TARGET="$(DRIVER_TARGET)" \ - DRIVER_DIR="$(PWD)" \ - DRIVER_OBJECTS="$(DRIVER_OBJECTS)" \ - driver-cpp +ifndef DPP_ROOT +$(error DPP_ROOT is undefined) +endif + +include $(DPP_ROOT)/Makefile.inc + +%.opp: %.cpp + $(call BUILD_CPP_OBJECT,$<,$@) + +$(DRIVER_TARGET): $(DRIVER_OBJECTS) + $(call LINK_CPP_KERNEL_TARGET,$(DRIVER_OBJECTS),$@) ``` Build it with: `make Driver.sys DPP_ROOT=[path/to/this/repository]` @@ -64,11 +64,7 @@ It also possible to (self-)sign your driver and install your driver with: ```make install: $(DRIVER_TARGET) - $(MAKE) -C $(DPP_ROOT) -f Makefile.external \ - DESTDIR="$(DESTDIR)" \ - TARGETS="$(DRIVER_TARGET)" \ - DRIVER_DIR="$(CURDIR)" \ - install-sign + $(call INSTALL_EXEC_SIGN,$(DRIVER_TARGET)) ``` ## Thanks! |