Skip to content

Instantly share code, notes, and snippets.

@serialhex
Created October 12, 2016 15:00
Show Gist options
  • Save serialhex/ada2b37581591716d41f70edd2986938 to your computer and use it in GitHub Desktop.
Save serialhex/ada2b37581591716d41f70edd2986938 to your computer and use it in GitHub Desktop.
Makefiles on Windows!!!

This is a simple pair of files one can use so that development on Windows is more like Linux. The command is slightly different .\make.bat all instead of make all when you're using powershell, but overall the effect is the same. Realy the only thing that needs to be edited is the makefile itself, to fit your project structure and any other libs you may want to include.

Happy hacking!

@echo off
REM this is a *much* abridged version of the makefile thing.
REM fortunately, there is the %VS140COMNTOOLS% env variable,
REM which makes it so i don't have to copy/paste that file here,
REM and i can change the version of visual studio tools based on
REM just that one var.
REM have fun!!!
@call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x86_amd64
nmake %*
#define macros
EXE = executable.exe
SRC = src
BIN = bin
INT = obj
INCL = include
OCV_INC = "$(OPENCV_DIR)\..\..\include"
OCV_LIB = "$(OPENCV_DIR)\lib\opencv_world310.lib"
ZMQ_LIB = "$(ZEROMQ_HOME)\lib\libzmq-v120-mt-4_0_4.lib"
ZMQ_INC = "$(ZEROMQ_HOME)\include"
# add other things here...
CFLAGS = /nologo /c /openmp /EHsc
all: clean create_dirs make_exe
make_exe: $(EXE)
# compile each .cpp file to its respective .obj file
{$(SRC)}.cpp{$(INT)}.obj ::
@echo Compiling...
cl $(CFLAGS) /Fo$(INT)\ /I$(INCL) /I$(OCV_INC) /I$(ZMQ_INC) $<
# link the files into an executable
$(EXE): $(INT)\*.obj
@echo Linking $(EXE)...
link /out:$(BIN)\$(EXE) $(INT)\*.obj $(OCV_LIB) $(ZMQ_LIB)
# create output directories
create_dirs:
@if not exist $(BIN) mkdir $(BIN)
@if not exist $(INT) mkdir $(INT)
# delete output directories
clean:
@if exist $(BIN) rmdir /S /Q $(BIN)
@if exist $(INT) rmdir /S /Q $(INT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment