Subversion Repositories NedoOS

Rev

Details | Last modification | View Log

Rev Author Line No. Line
125 lvd 1
# Makefile for sjasmplus created by Tygrys' hands.
2
# install/uninstall features added, CFLAGS and LDFLAGS modification by z00m's hands. [05.05.2016]
3
# overall optimization and beautification by mborik's hands. [05.05.2016]
4
# overall rewrite by Ped7g [2019-03-21]
5
 
6
## Some examples of my usage of this Makefile:
7
# make DEBUG=1					- to get DEBUG build
8
# make tests 					- to run the CI test+example script runner
9
# make memcheck TEST=misc DEBUG=1		- to use valgrind on assembling sub-directory "misc" in tests
10
# make PREFIX=~/.local install			- to install release version into ~/.local/bin/
11
# make clean && make CC=gcc-8 CXX=g++-8		- to compile binary with gcc-8
12
 
13
# set up CC+CXX explicitly, because windows MinGW/MSYS environment don't have it set up
14
CC=gcc
15
CXX=g++
16
BASH=/bin/bash
17
 
18
PREFIX=/usr/local
19
INSTALL=install -c
20
UNINSTALL=rm -vf
21
REMOVEDIR=rm -vdf
22
DOCBOOKGEN=xsltproc
23
MEMCHECK=valgrind --leak-check=yes
24
 
25
EXE := sjasmplus
26
BUILD_DIR := build
27
 
28
SUBDIR_BASE=sjasm
29
SUBDIR_LUA=lua5.1
30
SUBDIR_TOLUA=tolua++
31
SUBDIR_DOCS=docs
32
 
33
CFLAGS := -Wall -pedantic -DUSE_LUA -DLUA_USE_LINUX -DMAX_PATH=PATH_MAX -I$(SUBDIR_LUA) -I$(SUBDIR_TOLUA)
34
LDFLAGS := -ldl
35
 
36
ifdef DEBUG
37
BUILD_DIR := $(BUILD_DIR)/debug
38
CFLAGS += -g -O0
39
else
40
BUILD_DIR := $(BUILD_DIR)/release
41
CFLAGS += -DNDEBUG -O2
42
# for Linux (added strip flag)
43
LDFLAGS += -s
44
endif
45
 
46
# C++ flags (the CPPFLAGS are for preprocessor BTW, if you always wonder, like me...)
47
#CXXFLAGS = -std=gnu++14 $(CFLAGS)
48
CXXFLAGS = -std=gnu++11 $(CFLAGS)
49
#full path to executable
50
EXE_FP := "$(CURDIR)/$(BUILD_DIR)/$(EXE)"
51
 
52
# turns list of %.c/%.cpp files into $BUILD_DIR/%.o list
53
define object_files
54
	$(addprefix $(BUILD_DIR)/, $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(1))))
55
endef
56
 
57
# sjasmplus files
58
SRCS := $(wildcard $(SUBDIR_BASE)/*.c) $(wildcard $(SUBDIR_BASE)/*.cpp)
59
OBJS := $(call object_files,$(SRCS))
60
 
61
# liblua files
62
LUASRCS := $(wildcard $(SUBDIR_LUA)/*.c)
63
LUAOBJS := $(call object_files,$(LUASRCS))
64
 
65
# tolua files
66
TOLUASRCS := $(wildcard $(SUBDIR_TOLUA)/*.c)
67
TOLUAOBJS := $(call object_files,$(TOLUASRCS))
68
 
69
#implicit rules to compile C/CPP files into $(BUILD_DIR)
70
$(BUILD_DIR)/%.o : %.c
71
	@mkdir -p $(@D)
72
	$(COMPILE.c) $(OUTPUT_OPTION) $<
73
 
74
$(BUILD_DIR)/%.o : %.cpp
75
	@mkdir -p $(@D)
76
	$(COMPILE.cc) $(OUTPUT_OPTION) $<
77
 
78
.PHONY: all install uninstall clean docs tests memcheck
79
 
80
# "all" will also copy the produced binary into project root directory (to mimick old makefile)
81
all: $(EXE_FP)
82
	cp $(EXE_FP) $(EXE)
83
 
84
$(EXE_FP): $(LUAOBJS) $(TOLUAOBJS) $(OBJS)
85
	$(CXX) -o $(EXE_FP) $(CXXFLAGS) $(OBJS) $(LUAOBJS) $(TOLUAOBJS) $(LDFLAGS)
86
 
87
install: $(EXE_FP)
88
	$(INSTALL) $(EXE_FP) $(PREFIX)/bin
89
 
90
uninstall:
91
	$(UNINSTALL) $(PREFIX)/bin/$(EXE)
92
 
93
tests: $(EXE_FP)
94
ifdef TEST
95
	EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_tests.sh" $(TEST)
96
else
97
	EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_tests.sh"
98
	@EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_examples.sh"
99
endif
100
 
101
memcheck: $(EXE_FP)
102
ifdef TEST
103
	MEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_tests.sh" $(TEST)
104
else
105
	MEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_tests.sh"
106
	MEMCHECK="$(MEMCHECK)" EXE=$(EXE_FP) $(BASH) "$(CURDIR)/ContinuousIntegration/test_folder_examples.sh"
107
endif
108
 
109
docs: $(SUBDIR_DOCS)/documentation.html ;
110
 
111
$(SUBDIR_DOCS)/documentation.html: Makefile $(wildcard $(SUBDIR_DOCS)/*.xml) $(wildcard $(SUBDIR_DOCS)/*.xsl)
112
	$(DOCBOOKGEN) \
113
		--stringparam html.stylesheet docbook.css \
114
		--stringparam generate.toc "book toc" \
115
		-o $(SUBDIR_DOCS)/documentation.html \
116
		$(SUBDIR_DOCS)/docbook-xsl-ns-html-customization-linux.xsl \
117
		$(SUBDIR_DOCS)/documentation.xml
118
 
119
clean:
120
	$(UNINSTALL) \
121
		$(EXE) \
122
		$(BUILD_DIR)/$(EXE) \
123
		$(LUAOBJS) \
124
		$(TOLUAOBJS) \
125
		$(OBJS)
126
	$(REMOVEDIR) \
127
		$(BUILD_DIR)/$(SUBDIR_BASE) \
128
		$(BUILD_DIR)/$(SUBDIR_LUA) \
129
		$(BUILD_DIR)/$(SUBDIR_TOLUA) \
130
		$(BUILD_DIR)