From 1a295958ee9fd875eaf58cf8c36f90db379f82e0 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 3 Apr 2021 11:31:41 +0200 Subject: [PATCH] use CMake to build the fxSDK --- .gitignore | 9 ---- CMakeLists.txt | 39 +++++++++++++++ Makefile | 126 ------------------------------------------------- configure | 74 ----------------------------- fxsdk/fxsdk.sh | 2 +- giteapc.make | 10 ++-- 6 files changed, 46 insertions(+), 214 deletions(-) create mode 100644 CMakeLists.txt delete mode 100755 Makefile delete mode 100755 configure diff --git a/.gitignore b/.gitignore index e04cd14..8eb17a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,6 @@ -# Configuration file -Makefile.cfg - # Build directory build/ -# Binaries -bin/ - -# Test icons -icons/ - # Documentation drafts doc/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8072175 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/Makefile b/Makefile deleted file mode 100755 index dc886bf..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/configure b/configure deleted file mode 100755 index b93e9e6..0000000 --- a/configure +++ /dev/null @@ -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: - 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- Build and install the selected tool [default] - --disable- Do not build or install the selected tool - -Install folders: - Executables will be installed in /bin and runtime data in - /share/fxsdk. - - --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 diff --git a/fxsdk/fxsdk.sh b/fxsdk/fxsdk.sh index a284570..a56d252 100755 --- a/fxsdk/fxsdk.sh +++ b/fxsdk/fxsdk.sh @@ -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") diff --git a/giteapc.make b/giteapc.make index 605d2d5..8a1c4ff 100644 --- a/giteapc.make +++ b/giteapc.make @@ -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