1# Make file for SciTE on Linux or compatible OS
2# Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
3# The License.txt file describes the conditions under which this software may be distributed.
4# This makefile assumes GCC 4.x is used and changes will be needed to use other compilers.
5# GNU make does not like \r\n line endings so should be saved to CVS in binary form.
6
7.PHONY: all clean analyze depend install uninstall
8
9srcdir ?= .
10SCINTILLA_DIR ?= $(srcdir)/../../scintilla
11
12.SUFFIXES: .cxx .o .h .a .c
13
14WARNINGS += -Wall -pedantic -Wextra
15
16ifdef CLANG
17# Can choose aspect to sanitize: address and undefined can simply change SANITIZE but for
18# thread also need to create Position Independent Executable -> search online documentation
19SANITIZE = address
20#SANITIZE = undefined
21CXX = clang++
22CC = clang
23BASE_FLAGS += -fsanitize=$(SANITIZE)
24WARNINGS += -Wno-deprecated-register
25WARNINGS += -Wno-empty-body
26else
27WARNINGS += -Wno-misleading-indentation
28endif
29PKG_CONFIG ?= pkg-config
30
31GTK_VERSION = $(if $(GTK3),gtk+-3.0,gtk+-2.0)
32
33PYTHON = $(if $(windir),pyw,python3)
34
35# For the Gnome desktop stuff to work, prefix must point to where Gnome thinks it is.
36CONFIGFLAGS:=$(shell $(PKG_CONFIG) --cflags $(GTK_VERSION))
37CONFIGLIB:=$(shell $(PKG_CONFIG) --libs $(GTK_VERSION) gthread-2.0 gmodule-no-export-2.0)
38gnomeprefix:=$(shell $(PKG_CONFIG) --variable=prefix $(GTK_VERSION) 2>/dev/null)
39ifndef prefix
40ifdef gnomeprefix
41  prefix=$(gnomeprefix)
42else
43  prefix=/usr
44endif
45endif
46datadir=$(prefix)/share
47pixmapdir=$(datadir)/pixmaps
48bindir=$(prefix)/bin
49libdir=$(prefix)/lib/scite
50SYSCONF_PATH=$(prefix)/share/scite
51
52INSTALL=install
53COPY = cp -a
54
55PROG	= $(srcdir)/../bin/SciTE
56# make should be run in ../../scintilla/gtk to compile all the lexers.
57SHAREDEXTENSION = $(if $(windir),dll,so)
58COMPLIB=$(SCINTILLA_DIR)/bin/scintilla.a
59COMPONENT=$(srcdir)/../bin/libscintilla.$(SHAREDEXTENSION)
60LEXILLA=$(srcdir)/../bin/liblexilla.$(SHAREDEXTENSION)
61
62all: $(PROG) $(COMPONENT) $(LEXILLA)
63
64vpath %.h $(srcdir) $(srcdir)/../src $(SCINTILLA_DIR)/include
65vpath %.cxx $(srcdir) $(srcdir)/../src
66
67INCLUDES=-I $(SCINTILLA_DIR)/include -I $(srcdir)/../src
68DEFINES += -DGTK
69DEFINES += -DPIXMAP_PATH=\"$(pixmapdir)\" -DSYSCONF_PATH=\"$(SYSCONF_PATH)\"
70
71DEFINES += -D$(if $(DEBUG),DEBUG,NDEBUG)
72BASE_FLAGS += $(if $(DEBUG),-g,-Os)
73
74ifndef NO_LUA
75LUA_CORE_OBJS = lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
76		lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o \
77		ltable.o ltm.o lundump.o lvm.o lzio.o
78
79LUA_LIB_OBJS =	lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o lmathlib.o ltablib.o \
80		lstrlib.o loadlib.o loslib.o linit.o lutf8lib.o
81
82LUA_OBJS = LuaExtension.o $(LUA_CORE_OBJS) $(LUA_LIB_OBJS)
83
84vpath %.c $(srcdir)/../lua/src
85
86INCLUDES += -I$(srcdir)/../lua/src
87LUA_DEFINES = -DLUA_USE_POSIX -DLUA_USE_DLOPEN
88
89%.o: %.c
90	$(CC) $(CPPFLAGS) $(DEFINES) $(INCLUDES) $(WARNINGS) $(LUA_DEFINES) $(BASE_FLAGS) $(CFLAGS) -c $< -o $@
91
92else
93DEFINES += -DNO_LUA
94endif
95
96LIBS += -lm -lstdc++
97
98UNAME:=$(shell uname -s)
99ifeq ($(UNAME), Linux)
100LIBS += -ldl
101endif
102ifneq (,$(findstring GNU,$(UNAME)))
103LIBS += -ldl
104endif
105
106%.o: %.cxx
107	$(CXX) $(CPPFLAGS) --std=c++17 $(DEFINES) $(INCLUDES) $(WARNINGS) $(CONFIGFLAGS) $(BASE_FLAGS) $(CXXFLAGS) -c $< -o $@
108
109clean:
110	rm -f *.o *.plist $(PROG)
111
112analyze:
113	clang --analyze --std=c++17 $(DEFINES) $(INCLUDES) $(WARNINGS) $(CONFIGFLAGS) $(BASE_FLAGS) $(CXXFLAGS) $(srcdir)/*.cxx $(srcdir)/../src/*.cxx
114
115depend deps.mak:
116	$(PYTHON) AppDepGen.py
117
118../bin/%.$(SHAREDEXTENSION):	../../scintilla/bin/%.$(SHAREDEXTENSION)
119	$(COPY) $< $(@D)
120
121# To almost make lua.vers (needs header and footer added) which is only needed after updating Lua:
122# nm -g ../bin/SciTE | grep lua | awk '{print "\t\t" $3 ";"}' >lua2.vers
123
124SRC_OBJS = \
125	Cookie.o \
126	Credits.o \
127	EditorConfig.o \
128	ExportHTML.o \
129	ExportPDF.o \
130	ExportRTF.o \
131	ExportTEX.o \
132	ExportXML.o \
133	FilePath.o \
134	FileWorker.o \
135	IFaceTable.o \
136	JobQueue.o \
137	LexillaLibrary.o \
138	MatchMarker.o \
139	MultiplexExtension.o \
140	PropSetFile.o \
141	ScintillaCall.o \
142	ScintillaWindow.o \
143	SciTEBase.o \
144	SciTEBuffers.o \
145	SciTEIO.o \
146	SciTEProps.o \
147	StringHelpers.o \
148	StringList.o \
149	StyleDefinition.o \
150	StyleWriter.o \
151	Utf8_16.o
152
153$(PROG): SciTEGTK.o GUIGTK.o Widget.o DirectorExtension.o $(SRC_OBJS) $(LUA_OBJS)
154	$(CXX) $(BASE_FLAGS) $(LDFLAGS) -rdynamic -Wl,--as-needed -Wl,-rpath,'$${ORIGIN}' -Wl,--version-script $(srcdir)/lua.vers -Wl,-rpath,$(libdir) $^ -o $@ $(CONFIGLIB) $(LIBS) -L ../../scintilla/bin -lscintilla $(LDLIBS)
155
156# Automatically generate header dependencies with "make deps"
157include deps.mak
158
159# The two last install commands will fail if Gnome is not installed or is not at $(prefix).
160# This is OK - just means no SciTE in the Gnome Applications menu
161# Dead:	install -D SciTEGTK.properties $(SYSCONF_PATH)/SciTEGlobal.properties
162install:
163	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir) $(DESTDIR)$(SYSCONF_PATH)
164	$(INSTALL) -m 755 -d $(DESTDIR)$(libdir)
165
166	$(INSTALL) -m 755 $(PROG) $(DESTDIR)$(bindir)
167	$(INSTALL) -m 755 $(COMPONENT) $(DESTDIR)$(libdir)
168	$(INSTALL) -m 755 $(LEXILLA) $(DESTDIR)$(libdir)
169
170	for files in $(srcdir)/../src/*.properties $(srcdir)/../doc/*.html $(srcdir)/../doc/SciTEIco.png $(srcdir)/../doc/PrintHi.png $(srcdir)/../doc/SciTEIndicators.png; \
171	do \
172		$(INSTALL) -m 644 $$files $(DESTDIR)$(SYSCONF_PATH); \
173	done
174
175ifdef gnomeprefix
176	$(INSTALL) -m 755 -d $(DESTDIR)$(datadir)/applications $(DESTDIR)$(pixmapdir)
177	$(INSTALL) -m 644 $(srcdir)/SciTE.desktop $(DESTDIR)$(datadir)/applications/SciTE.desktop
178	$(INSTALL) -m 644 $(srcdir)/Sci48M.png $(DESTDIR)$(pixmapdir)/Sci48M.png
179endif
180
181uninstall:
182	rm -f $(DESTDIR)$(bindir)/SciTE
183	rm -f $(DESTDIR)$(libdir)/libscintilla.so
184	rm -f $(DESTDIR)$(libdir)/liblexilla.so
185	rm -rf $(DESTDIR)$(SYSCONF_PATH)
186ifdef gnomeprefix
187	rm -f $(DESTDIR)$(datadir)/applications/SciTE.desktop
188	rm -f $(DESTDIR)$(pixmapdir)/Sci48M.png
189endif
190