Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
The Makefile now produces a working .dll. The problem was that the
.rc file was built with the wrong option.
There is also a debug and a release build. The release build is
the default.
And the dependencies have been updated. No need for "Makefile.depend"
anymore.
  • Loading branch information
ffes committed Nov 30, 2015
1 parent b7a35fd commit e3e4b58
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ __*
ipch/
*.depend
*.layout
*.d
*.o
NppSnippets.dll
83 changes: 54 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,65 @@
#############################################################################
# #
# Makefile for building a MinGW NppSnippets.dll #
# #
# NOTE: remember to keep tabs in the file. Don't convert them to spaces! #
# Makefile for building a MinGW-w64 NppSnippets.dll #
# #
#############################################################################

.SUFFIXES: .exe .res .a .o .gch .c .cpp .cc .cxx .m .rc .p .f .F .r .y .l .s .S .def .h
.SUFFIXES: .dll .o .c .cpp .rc .h

ARCH = i686-w64-mingw32
CC = $(ARCH)-gcc
CXX = $(ARCH)-g++
AR = $(ARCH)-ar
RANLIB = $(ARCH)-ranlib
WINDRES = $(ARCH)-windres

#
CFLAGS = -c -O2 -DUNICODE -mtune=i686
CXXFLAGS = $(CFLAGS) -W -Wall -gstabs -mwindows
RESFLAGS = -O coff
# The main targets
PROGRAM = NppSnippets
TARGET = $(PROGRAM).dll

now: $(TARGET)
all: clean now

# The general compiler flags
CFLAGS = -DUNICODE -mtune=i686
CXXFLAGS = $(CFLAGS) -Wno-write-strings --std=c++11
LIBS = -static -lshlwapi -lgdi32 -lcomdlg32 -lcomctl32
LDFLAGS = -Wl,--out-implib,$(TARGET) -shared

# Default target is RELEASE
DEBUG ?= 0
ifeq ($(DEBUG), 1)
# Add DEBUG define, debug info and specific optimizations
CFLAGS += -D_DEBUG -g -O0
CXXFLAGS += -D_DEBUG -g -O0
# Add dependencies flags
CFLAGS += -MMD -MP
CXXFLAGS += -MMD -MP
# Enable almost all warnings
CXXFLAGS += -W -Wall
else
# Set the optimizations
OPT = -fexpensive-optimizations -Os -O2
# Strip the dll
LDOPT = -s
endif

# Silent/verbose commands. For verbose output of commands set V=1
V ?= 0
ifeq ($(V), 0)
SILENT = @
V_CC = @echo [CC] $@;
V_CXX = @echo [CXX] $@;
V_RES = @echo [WINDRES] $@;
endif

# All the build targets
.c.o:
$(CC) $(CFLAGS) -o $@ $<
$(V_CC) $(CC) -c $(CFLAGS) $(OPT) -o $@ $<

.cpp.o:
$(CXX) $(CXXFLAGS) -o $@ $<
$(V_CXX) $(CXX) -c $(CXXFLAGS) $(OPT) -o $@ $<

.rc.o:
$(WINDRES) $(RESFLAGS) -o $@ -i $<

PROGRAM = NppSnippets
TARGET = $(PROGRAM).dll

now: $(TARGET)

all: clean depend now
$(V_RES) $(WINDRES) -o $@ -i $<

PROGRAM_SRCS_CPP = \
DlgAbout.cpp \
Expand Down Expand Up @@ -64,18 +87,20 @@ PROGRAM_OBJS_C=$(PROGRAM_SRCS_C:.c=.o)
PROGRAM_RC=$(PROGRAM)_res.rc
PROGRAM_OBJS_RC=$(PROGRAM_RC:.rc=.o)

$(PROGRAM).dll: $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC)
$(CXX) -o $@ $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) $(LDFLAGS) $(LIBS)
PROGRAM_DEP_CPP=$(PROGRAM_SRCS_CPP:.cpp=.d)
PROGRAM_DEP_C=$(PROGRAM_SRCS_C:.c=.d)

depend: $(PROGRAM_SRCS_CPP)
$(CXX) -MM $^ > Makefile.depend
$(PROGRAM).dll: $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC)
$(V_CXX) $(CXX) -o $@ $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) $(LDFLAGS) $(LDOPT) $(LIBS)

clean:
rm -f $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) $(PROGRAM).dll $(PROGRAM).a tags tags.sqlite Makefile.depend
touch Makefile.depend

### code dependencies ###
@echo Cleaning
$(SILENT) rm -f $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC)
$(SILENT) rm -f $(PROGRAM_DEP_CPP) $(PROGRAM_DEP_C) $(PROGRAM).dll
$(SILENT) rm -f tags tags.out tags.sqlite

# The dependencies
$(PROGRAM)_res.o: $(PROGRAM)_res.rc Version.h

include Makefile.depend
-include $(PROGRAM_DEP_CPP)
-include $(PROGRAM_DEP_C)

0 comments on commit e3e4b58

Please sign in to comment.