use CMake to build the fxSDK

This commit is contained in:
Lephenixnoir 2021-04-03 11:31:41 +02:00
parent 6415476fe3
commit 1a295958ee
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
6 changed files with 46 additions and 214 deletions

9
.gitignore vendored
View file

@ -1,15 +1,6 @@
# Configuration file
Makefile.cfg
# Build directory
build/
# Binaries
bin/
# Test icons
icons/
# Documentation drafts
doc/

39
CMakeLists.txt Normal file
View file

@ -0,0 +1,39 @@
# Build system for the fxSDK
cmake_minimum_required(VERSION 3.16)
project(fxSDK VERSION 2.3.1 LANGUAGES C)
find_package(PkgConfig REQUIRED)
find_package(PNG REQUIRED)
pkg_check_modules(libusb REQUIRED libusb-1.0 IMPORTED_TARGET)
set(CMAKE_INSTALL_MESSAGE LAZY)
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}")
set(BIN "${CMAKE_CURRENT_BINARY_DIR}")
add_compile_options(-Wall -Wextra -std=c11 -Og -g -D_GNU_SOURCE)
# fxg1a
add_executable(fxg1a fxg1a/dump.c fxg1a/edit.c fxg1a/file.c fxg1a/icon.c
fxg1a/main.c fxg1a/util.c)
target_include_directories(fxg1a PUBLIC fxg1a/)
target_link_libraries(fxg1a PNG::PNG)
# fxsdk
add_custom_command(OUTPUT "${BIN}/fxsdk.sh"
COMMAND sed "'s#@FXSDK_PREFIX@#${CMAKE_INSTALL_PREFIX}#'"
"${SRC}/fxsdk/fxsdk.sh" > "${BIN}/fxsdk.sh"
DEPENDS "${SRC}/fxsdk/fxsdk.sh")
add_custom_target(fxsdk ALL DEPENDS "${BIN}/fxsdk.sh")
# Install rules
# fxsdk
install(PROGRAMS "${BIN}/fxsdk.sh" TYPE BIN RENAME fxsdk)
install(DIRECTORY fxsdk/assets DESTINATION share/fxsdk)
install(DIRECTORY fxsdk/cmake/ DESTINATION lib/cmake/fxsdk)
# fxg1a
install(TARGETS fxg1a)
# fxconv
install(PROGRAMS fxconv/fxconv-main.py TYPE BIN RENAME fxconv)
install(FILES fxconv/fxconv.py TYPE BIN)

126
Makefile
View file

@ -1,126 +0,0 @@
#! /usr/bin/make -f
# Require config file if not cleaning up
ifeq "$(filter clean distclean,$(MAKECMDGOALS))" ""
include Makefile.cfg
endif
# Compiler flags
cflags = -Wall -Wextra -std=c11 -g -I $(dir $<) -D_GNU_SOURCE \
-DFXSDK_PREFIX='"$(PREFIX)"' $(CFLAGS)
# Linker flags
lflags = -lpng
# Dependency generation flags
dflags = -MT $@ -MMD -MP -MF $(@:%.o=%.d)
#
# Main targets and symbolic targets
# $TARGETS is provided by Makefile.cfg.
#
INSTALL := $(TARGETS:%=install-%)
TARGETS := $(TARGETS:%=all-%)
# fxconv has no sources files because it's written in Python, and fxsdk has no
# source either because it's written in Bash.
src-fxg1a := $(wildcard fxg1a/*.c)
obj-fxg1a := $(src-fxg1a:%=build/%.o)
# Sed command to copy install path to fxsdk.sh. On Mac OS, BSD sed is used so
# we need to do it a bit differently with a printf helper to insert a literal
# newline into the command.
sed := -E -e '/^PREFIX=.?.?.?\\$$/ a \$(PREFIX)'
ifeq "$(shell uname)" "Darwin"
sed := -e "$$(printf '/^PREFIX=.?.?.?/ a \\\n$(PREFIX)')"
endif
# Symbolic targets
all: $(TARGETS)
all-fxsdk: bin/fxsdk.sh
all-fxg1a: bin/fxg1a
all-fxconv:
# Explicit targets
bin/fxsdk.sh: fxsdk/fxsdk.sh | bin/
sed $(sed) $< > $@
bin/fxg1a: $(obj-fxg1a) | bin/
gcc $^ -o $@ $(lflags)
bin/:
mkdir -p $@
#
# Source rules
#
build/%.c.o: %.c
@ mkdir -p $(dir $@)
gcc -c $< -o $@ $(cflags) $(dflags)
#
# Dependency system, misc.
#
include $(wildcard build/*/*.d)
# Dependency on configuration file
Makefile.cfg:
@ if [[ ! -f Makefile.cfg ]]; then \
echo "error: Makefile.cfg is missing, did you ./configure?" >&2; \
false; \
fi
.PHONY: all clean distclean
#
# Installing
#
m644 := -m 644
m755 := -m 755
# Disable -m on Mac OS
ifeq "$(shell uname)" "Darwin"
m644 :=
m755 :=
endif
install: $(INSTALL)
install-fxsdk: all-fxsdk
install -d $(PREFIX)/bin
install bin/fxsdk.sh $(PREFIX)/bin/fxsdk
install -d $(PREFIX)/share/fxsdk/assets
cp -ra fxsdk/assets $(PREFIX)/share/fxsdk/
install bin/fxsdk.sh $(m755) $(PREFIX)/bin/fxsdk
install -d $(PREFIX)/lib/cmake/fxsdk
install fxsdk/cmake/* $(m644) $(PREFIX)/lib/cmake/fxsdk
install-fxg1a: all-fxg1a
install -d $(PREFIX)/bin
install bin/fxg1a $(m755) $(PREFIX)/bin
install-fxconv: all-fxconv
install -d $(PREFIX)/bin
install fxconv/fxconv-main.py $(m755) $(PREFIX)/bin/fxconv
install fxconv/fxconv.py $(m644) $(PREFIX)/bin
uninstall:
rm -f $(PREFIX)/bin/{fxsdk,fxg1a,fxconv,fxconv.py}
rm -rf $(PREFIX)/share/fxsdk
rm -rf $(PREFIX)/lib/cmake/fxsdk
#
# Cleaning
#
clean-fxg1a:
@rm -rf build/fxg1a
clean:
@rm -rf build
distclean: clean
@rm -rf bin
@rm -f Makefile.cfg

74
configure vendored
View file

@ -1,74 +0,0 @@
#! /usr/bin/env bash
# Install prefix
PREFIX="$HOME/.local"
# Individual component selection
BUILD_fxsdk=1
BUILD_fxconv=1
BUILD_fxg1a=1
help() {
cat << EOF
Configuration options for the fxSDK (fx9860g and fxcg50 development tools).
Tool selection:
<tool> may be one of the following:
fxsdk Project management (you generally want this)
fxconv Asset conversion for standard and custom gint formats
fxg1a G1A file wrapper, editor and analyzer
--enable-<tool> Build and install the selected tool [default]
--disable-<tool> Do not build or install the selected tool
Install folders:
Executables will be installed in <prefix>/bin and runtime data in
<prefix>/share/fxsdk.
--prefix=<prefix> Base install folder [default $HOME/.local]
EOF
exit 0
}
# Parse arguments
for arg; do case "$arg" in
-h | -? | --help)
help;;
--prefix=*)
PREFIX=${arg#--prefix=};;
--enable-*)
tool="${arg#--enable-}"
if [[ ! ":fxsdk:fxg1a:fxconv:" =~ ":$tool:" ]]; then
echo "error: $arg: no such tool"
exit 1
fi
eval "BUILD_${tool}=1";;
--disable-*)
tool="${arg#--disable-}"
if [[ ! ":fxsdk:fxg1a:fxconv:" =~ ":$tool:" ]]; then
echo "error: $arg: no such tool"
exit 1
fi
eval "BUILD_${tool}=0";;
*)
echo "error: unrecognized option $arg"
exit 1;;
esac; done
# Generate sub-Makefile with configuration details
gen() {
# Allow an install script to change the destination at the last second
# to have all files in a separate root before packaging
# TODO: Support DESTDIR instead
echo "PREFIX ?= $PREFIX"
echo -n "TARGETS ="
[[ $BUILD_fxsdk = 1 ]] && echo -n " fxsdk"
[[ $BUILD_fxconv = 1 ]] && echo -n " fxconv"
[[ $BUILD_fxg1a = 1 ]] && echo -n " fxg1a"
echo ""
}
gen > Makefile.cfg

View file

@ -1,7 +1,7 @@
#! /usr/bin/env bash
# Note: this line is edited at compile time to insert the install folder
PREFIX=\
PREFIX=@FXSDK_PREFIX@
R=$(printf "\e[31;1m")
g=$(printf "\e[32m\e[3m")

View file

@ -9,15 +9,17 @@ PREFIX ?= $(GITEAPC_PREFIX)
-include giteapc-config.make
configure:
@ ./configure --prefix=$(PREFIX) $(FXSDK_CONFIGURE)
@ cmake -B build -DCMAKE_INSTALL_PREFIX="$(PREFIX)" $(FXSDK_CONFIGURE)
build:
@ make all
@ make -C build
install:
@ make install
@ make -C build install
uninstall:
@ make uninstall
@ if [ -e build/install_manifest.txt ]; then \
xargs rm -f < build/install_manifest.txt; \
fi
.PHONY: configure build install uninstall