# # by Frank Rysanek # # Based on the source code of ioperm.c by Marcel Telka # - thanks a million :-) # # See also my_names.h # Note that after changing the driver name, you also have # to rename $(DRVNAME).c manually in this directory :-) DRVNAME = even INCLUDES = -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/ddk INCLUDES += # We could in fact just add -DEVEN_DRIVER_NAME=\"$(DRVNAME)\" to CFLAGS, # but we'd have to be careful to "make clean" after changing # the driver name here in the makefile... #CFLAGS = -Wall $(INCLUDES) -DEVEN_DRIVER_NAME=\"$(DRVNAME)\" CFLAGS = -Wall -Wpedantic -DNDEBUG $(INCLUDES) ifneq ($(RELEASE),) VERSION = $(shell git describe --tags --always --dirty) CFLAGS += -DEVEN_VERSION=\"$(VERSION)\" endif # Kernel-mode libs: # libntoskrnl = basic kernel-mode environment # libhal = WRITE_PORT_UCHAR et al. #KRNLIBS = -lntoskrnl -lhal KRNLIBS = -lntoskrnl CC = x86_64-w64-mingw32-gcc DLLTOOL = x86_64-w64-mingw32-dlltool STRIP = x86_64-w64-mingw32-strip #STRIP = true all: $(DRVNAME).sys # Dependencies on header files: $(DRVNAME).sys: even_names.h even_ioctl.h even_peb.h utlist.h # This shall get appended to the built-in set of suffixes supported: .SUFFIXES: .sys .exe # Otherwise the custom inference rules below wouldn't ever kick in. # This is implicit, no need to define this explicitly: #.c.o: # $(CC) $(CFLAGS) -c -o $@ $< # This inference rule allows us to turn an .o into a .sys without # much hassle, implicitly. # The downside is, that you cannot potentially add further object files # to get linked into the .sys driver (such as, some custom ASM routines). # Oh wait, maybe you can... try adding your .o after the last $(CC) in the rule... .o.sys: $(CC) -Wl,--base-file,$*.base \ -Wl,--entry,DriverEntry@8 \ -nostartfiles -nostdlib \ -o junk.tmp \ $*.o \ $(KRNLIBS) -rm -f junk.tmp $(DLLTOOL) --dllname $*.sys \ --base-file $*.base --output-exp $*.exp $(CC) -Wl,--subsystem,native \ -Wl,--image-base,0x10000 \ -Wl,--file-alignment,0x1000 \ -Wl,--section-alignment,0x1000 \ -Wl,--entry,DriverEntry@8 \ -Wl,$*.exp \ -mdll -nostartfiles -nostdlib \ -o $*.sys \ $*.o \ $(KRNLIBS) $(STRIP) $*.sys JUNK = *.base *.exp *.o *~ junk.tmp clean: rm -f $(JUNK) *.sys semiclean: rm -f $(JUNK)