134 lines
4.3 KiB
Makefile
Executable file
134 lines
4.3 KiB
Makefile
Executable file
# Generic Makefile for NetBeans for C/C++ projects
|
|
# Copyright (C) 2025 Benny Lyons
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
#
|
|
# Uses the variable NETBEANSBUILD which is added to _both_ the compile flags
|
|
# and the link process. Without this option Netbeans will not recognise the
|
|
# binary, so it is not possible to debug the binary in NetBeans.
|
|
# If you obtain the NetBeans error 'Not an ELF Binary', or something similar,
|
|
# then using $(NETBEANSBUILD) will most likely fix this.
|
|
#
|
|
|
|
|
|
# Change this to the name of your application, programme
|
|
# or the name of the binary this makefile produces
|
|
APP = myapp
|
|
|
|
# C++ compiler
|
|
#CXX:=clang++
|
|
CXX := g++
|
|
|
|
|
|
#
|
|
# NETBEANSBUILD
|
|
#
|
|
# Netbeans does not recognise an executable to debug out of the box.
|
|
# You must instruct the compiler to produce Platform Independent Code by
|
|
# using -no-pie. PIE is required to use Address Space Layout Randomization
|
|
# (ASLR), which is a security feature, which Netbeans cannot currently use.
|
|
#
|
|
# To fix, add the following option to CFLAGS and LDFLAGS
|
|
# -no-pie
|
|
NETBEANSBUILD := -no-pie
|
|
|
|
ifeq ($(MAKECMDGOALS),debug)
|
|
DBG_REL :=-ggdb3
|
|
else
|
|
DBG_REL :=
|
|
endif
|
|
|
|
#
|
|
# OS dependent flags
|
|
#
|
|
OS := $(shell uname -s)
|
|
ifeq ($(UNAME_S),Linux)
|
|
# installed by system and in PATH
|
|
CPPCHECK := cppcheck
|
|
DBG_REL +=
|
|
endif
|
|
# OpenIndiana and flavours
|
|
ifeq ($(UNAME_S),SunOS)
|
|
# local installation
|
|
CPPCHECK := $(HOME)/devl/cppcheck/bin/cppcheck
|
|
DBG_REL +=
|
|
endif
|
|
|
|
|
|
SRC_DIR := src
|
|
OBJ_DIR := obj
|
|
SRC := $(wildcard $(SRC_DIR)/*.cpp)
|
|
|
|
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC))
|
|
|
|
##
|
|
## Add checks and issue warnings
|
|
##
|
|
# -Wall -Wextra # turn on all warnings.
|
|
# -Wconversion -Wsign-conversio # warn on unsign/sign conversions.
|
|
# -Wformat-security # warn onformat functions that might be a security issue
|
|
# -Werror # deactivate this initially? convert all warnings into errors.
|
|
# -march=x86-64 # take max advantage of address space (important for ASLR;
|
|
# # more virtual address space to chose from when randomising layout).
|
|
# -fstack-protector-all #
|
|
# -Wstack-protector #
|
|
# --param ssp-buffer-size=4 #
|
|
# -ftrapv # generate traps for signed overflow (currently bugged in gcc)
|
|
# -D_FORTIFY_SOURCE=2 -O2 # buffer overflow check. -D_FORTIFY_SOURCE=1 also possible
|
|
# -Wfloat-equal # testing floating-point numbers for equality is usually bad
|
|
# -Wpointer-arith # warn if anything depends upon the size of a function or of void
|
|
_CXXFLAGS=-Wall -Wextra \
|
|
-Wconversion -Wsign-conversion \
|
|
-march=x86-64 \
|
|
-Wformat-security \
|
|
-fstack-protector-all -Wstack-protector --param ssp-buffer-size=4 \
|
|
-ftrapv \
|
|
-D_FORTIFY_SOURCE=2 -O2 \
|
|
-Wfloat-equal \
|
|
-Wpointer-arith
|
|
|
|
|
|
CXXFLAGS = $(NETBEANSBUILD) $(DBG_REL) $(_CXXFLAGS)
|
|
LIBS = $(NETBEANSBUILD)
|
|
|
|
# Uncomment one of the following to select an output format
|
|
#CHECKFLAGS = --template="{file},{line},{severity},{id},{message}"
|
|
CHECKFLAGS = --quiet --enable=all --error-exitcode=1
|
|
#CHECKFLAGS = --enable=all --error-exitcode=1
|
|
|
|
debug release: DIRS $(APP)
|
|
check: cppcheck.out
|
|
|
|
|
|
$(APP): $(OBJS)
|
|
$(CXX) -o bin/$@ $^ $(LIBS)
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
|
$(CXX) $(CXXFLAGS) -o $@ -c $<
|
|
|
|
DIRS: obj bin
|
|
mkdir -p obj bin
|
|
|
|
cppcheck.out: $(SRC)
|
|
$(info output to cppcheck.out)
|
|
$(CPPCHECK) $(CHECKFLAGS) $^ > $@ 2>&1
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(info cleaning up)
|
|
@rm -f $(APP) $(OBJ_DIR)/* ./bin/$(APP) cppcheck.out
|
|
@if [ -d "./bin" ]; then rmdir ./bin ; fi
|
|
@if [ -d "./obj" ]; then rmdir ./obj ; fi
|