# Copyright (c) 2015-2021 Damien Ciabrini
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see .
include Makefile.config
# External subpackages
EMUDBG_GIT=https://github.com/dciabrin/emudbg
GNGEO_GIT=https://github.com/dciabrin/gngeo
TOOLCHAIN_GIT=https://github.com/dciabrin/ngdevkit-toolchain
EXAMPLES_GIT=https://github.com/dciabrin/ngdevkit-examples
# ------ base targets ------
# and may be extended with targets from
# toolchain, emudbg and gngeo if enabled
all: build-tools
install: install-tools install-pkgconfig
clean: clean-tools
distclean: clean clean-pkgconfig
rm -rf build config.log config.status
find . \( -name '*~' -or -name Makefile -or -name Makefile.config \) \
-exec rm {} \;
build:
mkdir $@
.PHONY: clean distclean
# ------ toolchain (gcc, binutils, newlib, gdb) ------
ifeq ($(EXTERNAL_TOOLCHAIN), no)
build-tools: build-toolchain
install-tools: install-toolchain
distclean: distclean-toolchain
endif
download-toolchain: | toolchain
toolchain:
$(GIT) clone $(TOOLCHAIN_GIT) $@
build-toolchain: | download-toolchain build
$(MAKE) -Ctoolchain all BUILD=$(PWD)/build DESTDIR= prefix=$(prefix) EXTRA_BUILD_CMD='$(EXTRA_BUILD_CMD_TOOLCHAIN)' EXTRA_BUILD_FLAGS='$(EXTRA_BUILD_FLAGS_TOOLCHAIN)'
install-toolchain: $(prefix)/bin
$(prefix)/bin: build/ngbinutils build/nggcc build/nggdb build/ngnewlib build/ngsdcc
$(MAKE) -Ctoolchain install BUILD=$(PWD)/build DESTDIR= prefix=$(prefix) EXTRA_BUILD_CMD='$(EXTRA_BUILD_CMD_TOOLCHAIN)' EXTRA_BUILD_FLAGS='$(EXTRA_BUILD_FLAGS_TOOLCHAIN)'
distclean-toolchain:
rm -rf toolchain
# ------ ngdevkit ------
build-tools:
$(EXTRA_BUILD_CMD) && \
set -e; \
for i in nullsound runtime nullbios include tools; do \
$(MAKE) -C $$i; \
done
install-tools:
$(EXTRA_BUILD_CMD) && \
set -e; \
for i in nullsound runtime nullbios include tools; do \
$(MAKE) -C $$i install; \
done
install-pkgconfig:
$(INSTALL) -d $(DESTDIR)$(prefix)/share/pkgconfig && \
$(INSTALL) ngdevkit.pc $(DESTDIR)$(prefix)/share/pkgconfig && \
$(INSTALL) -d $(DESTDIR)$(prefix)/lib/pkgconfig && \
$(INSTALL) ngdevkit.pc $(DESTDIR)$(prefix)/lib/pkgconfig
clean-tools:
set -e; \
for i in nullsound runtime nullbios include tools; do \
$(MAKE) -C $$i clean; \
done
clean-pkgconfig:
rm -f ngdevkit.pc
ifneq ($(EXAMPLES), no)
all: download-examples
distclean: distclean-examples
endif
download-examples: | examples
examples:
$(GIT) clone --recursive $(EXAMPLES_GIT) $@ && \
cd examples && autoreconf -iv
distclean-examples:
rm -rf examples
# ------ emudbg ------
ifeq ($(EXTERNAL_EMUDBG), no)
all: build-emudbg
build-gngeo: build-emudbg
install: install-emudbg
distclean: distclean-emudbg
endif
emudbg:
$(GIT) clone $(EMUDBG_GIT) $@ && \
cd emudbg && autoreconf -iv
build-emudbg: build/emudbg
build/emudbg: emudbg
@echo compiling emudbg...
CURPWD=$$(pwd) && \
$(EXTRA_BUILD_CMD) && \
mkdir -p build/emudbg && \
cd build/emudbg && \
$$CURPWD/emudbg/configure --prefix=$(prefix) \
$(EMUDBG_BUILD_FLAGS) -v && $(MAKE)
install-emudbg: $(prefix)/lib/libemudbg.a
$(prefix)/lib/libemudbg.a: build/emudbg
$(MAKE) -C build/emudbg install
distclean-emudbg:
rm -rf emudbg
# ------ gngeo ------
ifeq ($(EXTERNAL_GNGEO), no)
all: build-gngeo
install: install-gngeo
ifeq ($(ENABLE_MSYS2), yes)
install: install-gngeo-dll
install-gngeo-dll: install-gngeo
endif
distclean: distclean-gngeo
endif
ifeq ($(ENABLE_MSYS2), yes)
GNGEO=$(GNGEO_INSTALL_PATH)/ngdevkit-gngeo.exe
GNGEOPKGDATADIR=$(GNGEO_INSTALL_PATH)/share
else
GNGEO=$(prefix)/bin/ngdevkit-gngeo
GNGEOPKGDATADIR=$(prefix)/share/ngdevkit-gngeo
endif
gngeo:
$(GIT) clone --branch ngdevkit $(GNGEO_GIT) $@ && \
cd gngeo && autoreconf -iv $(GNGEO_ACLOCAL_PATH)
build-gngeo: build/gngeo
build-emulator-config: $(GNGEO_CFG)
build/gngeo: gngeo
@echo compiling gngeo...
CURPWD=$$(pwd) && \
$(EXTRA_BUILD_CMD) && \
mkdir -p build/gngeo && \
cd build/gngeo && \
$$CURPWD/gngeo/configure --program-prefix=ngdevkit- $(GNGEO_BUILD_FLAGS) \
CPPFLAGS="$$CPPFLAGS -Wno-implicit-function-declaration -I$$CURPWD/emudbg/src -I$(prefix)/include" CFLAGS="$$CFLAGS -Wno-implicit-function-declaration -I$$CURPWD/emudbg/src -I$(prefix)/include -DGNGEORC=\\\"ngdevkit-gngeorc\\\"" LDFLAGS="-L$$PWD/../emudbg/src -L$(prefix)/lib" PKG_CONFIG_PATH="$$PWD/../emudbg:$(prefix)/lib/pkgconfig" \
-v && $(MAKE) -j1 pkgdatadir=$(GNGEOPKGDATADIR)
install-gngeo: $(GNGEO)
$(GNGEO): build/gngeo
$(MAKE) -C build/gngeo install pkgdatadir=$(GNGEOPKGDATADIR)
ifeq ($(ENABLE_MSYS2), yes)
install-gngeo-dll: build/gngeo
cp $(SDL2_DLL) $(ZLIB1_DLL) $(GLEW_DLL) $(GNGEO_INSTALL_PATH)
endif
$(GNGEO_CFG): export INPUT_SETTINGS:=$(GNGEO_DEFAULT_INPUT_SETTINGS)
$(GNGEO_CFG):
@ echo generating a default input config for gngeo; \
mkdir -p $(dir $(GNGEO_CFG)) && \
echo "$$INPUT_SETTINGS" > $(GNGEO_CFG)
distclean-gngeo:
rm -rf gngeo
# ------ Target to set up shell environment ------
SHELL_BIN_PATH := $(prefix)/bin
ifeq ($(ENABLE_MSYS2), yes)
ifeq ($(EXTERNAL_GNGEO), no)
ifneq ($(prefix),$(GNGEO_INSTALL_PATH))
SHELL_BIN_PATH := $(SHELL_BIN_PATH):$(GNGEO_INSTALL_PATH)
endif
endif
endif
shellinit:
@ echo Variables set with eval $$\(make shellinit\) >&2
@ echo export PATH="$(SHELL_BIN_PATH):\$$PATH"
@ echo export PKG_CONFIG_PATH="$(prefix)/share/pkgconfig:\$$PKG_CONFIG_PATH"
ifeq ($(shell uname), Darwin)
@ echo export DYLD_LIBRARY_PATH="$(prefix)/lib:\$$DYLD_LIBRARY_PATH"
else
@ echo export LD_LIBRARY_PATH="$(prefix)/lib:\$$LD_LIBRARY_PATH"
endif
@ echo export PYTHONPATH="$(prefix)/bin:\$$PYTHONPATH"