2019-03-21 22:54:06 +01:00
|
|
|
#! /usr/bin/make -f
|
|
|
|
|
|
|
|
# Require config file if not cleaning up
|
|
|
|
ifeq "$(filter clean distclean,$(MAKECMDGOALS))" ""
|
|
|
|
include Makefile.cfg
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Compiler flags
|
2019-05-03 11:19:36 +02:00
|
|
|
cflags = -Wall -Wextra -std=c11 -g -I $(dir $<) -D_GNU_SOURCE \
|
2019-03-21 22:54:06 +01:00
|
|
|
-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.
|
|
|
|
#
|
|
|
|
|
2020-02-13 22:13:04 +01:00
|
|
|
TARGETS := $(TARGETS:fxsdk=fxsdk.sh)
|
2020-05-30 12:17:06 +02:00
|
|
|
TARGETS := $(TARGETS:fxconv=fxconv-main.py)
|
2019-03-21 22:54:06 +01:00
|
|
|
bin = $(TARGETS:%=bin/%)
|
|
|
|
|
2019-06-16 17:58:30 +02:00
|
|
|
# fxconv has no sources files because it's written in Python, and fxsdk has no
|
|
|
|
# source either because it's written in Bash.
|
2020-02-19 23:30:39 +01:00
|
|
|
src-fxg1a := $(wildcard fxg1a/*.c)
|
|
|
|
obj-fxg1a := $(src-fxg1a:%=build/%.o)
|
2019-03-21 22:54:06 +01:00
|
|
|
|
2020-02-13 22:13:04 +01:00
|
|
|
# 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.
|
2020-05-30 12:17:06 +02:00
|
|
|
sed := -E -e '/^PREFIX=.?.?.?\\$$/ a \$(PREFIX)'
|
2020-02-13 22:13:04 +01:00
|
|
|
ifeq "$(shell uname)" "Darwin"
|
2020-05-30 12:17:06 +02:00
|
|
|
sed := -e "$$(printf '/^PREFIX=.?.?.?/ a \\\n$(PREFIX)')"
|
2020-02-13 22:13:04 +01:00
|
|
|
endif
|
|
|
|
|
2019-03-21 22:54:06 +01:00
|
|
|
# Symbolic targets
|
|
|
|
|
|
|
|
all: $(bin)
|
|
|
|
|
2020-02-13 22:13:04 +01:00
|
|
|
all-fxsdk: bin/fxsdk.sh
|
2019-03-21 22:54:06 +01:00
|
|
|
all-fxg1a: bin/fxg1a
|
2020-05-30 12:17:06 +02:00
|
|
|
all-fxconv: bin/fxconv-main.py
|
2019-03-21 22:54:06 +01:00
|
|
|
|
|
|
|
# Explicit targets
|
|
|
|
|
2020-02-19 23:22:11 +01:00
|
|
|
bin/fxsdk.sh: fxsdk/fxsdk.sh | bin/
|
2020-05-30 12:17:06 +02:00
|
|
|
sed $(sed) $< > $@
|
|
|
|
bin/fxconv-main.py: fxconv/fxconv-main.py | bin/
|
|
|
|
sed $(sed) $< > $@
|
2019-03-21 22:54:06 +01:00
|
|
|
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
|
|
|
|
#
|
|
|
|
|
2019-06-29 17:49:00 +02:00
|
|
|
m644 := -m 644
|
|
|
|
m755 := -m 755
|
|
|
|
|
2020-02-13 22:13:04 +01:00
|
|
|
# Disable -m on Mac OS
|
2019-06-29 17:49:00 +02:00
|
|
|
ifeq "$(shell uname)" "Darwin"
|
|
|
|
m644 :=
|
|
|
|
m755 :=
|
|
|
|
endif
|
|
|
|
|
2019-03-21 22:54:06 +01:00
|
|
|
install: $(bin)
|
|
|
|
install -d $(PREFIX)/bin
|
2019-05-03 11:19:36 +02:00
|
|
|
install -d $(PREFIX)/share/fxsdk
|
2020-05-30 12:17:06 +02:00
|
|
|
install $(filter bin/fxg1a,$(bin)) $(m755) $(PREFIX)/bin
|
2019-06-16 17:58:30 +02:00
|
|
|
install -d $(PREFIX)/share/fxsdk/assets
|
2019-06-29 17:49:00 +02:00
|
|
|
install fxsdk/assets/* $(m644) $(PREFIX)/share/fxsdk/assets
|
2020-02-13 22:13:04 +01:00
|
|
|
install bin/fxsdk.sh $(m755) $(PREFIX)/bin/fxsdk
|
2020-05-30 12:17:06 +02:00
|
|
|
install bin/fxconv-main.py $(m755) $(PREFIX)/bin/fxconv
|
2019-06-29 17:49:00 +02:00
|
|
|
install fxconv/fxconv.py $(m644) $(PREFIX)/bin
|
2019-03-21 22:54:06 +01:00
|
|
|
|
2019-05-03 11:19:36 +02:00
|
|
|
uninstall:
|
2020-02-19 23:30:39 +01:00
|
|
|
rm -f $(PREFIX)/bin/{fxsdk,fxg1a,fxconv,fxconv.py}
|
2019-05-03 11:19:36 +02:00
|
|
|
rm -rf $(PREFIX)/share/fxsdk
|
|
|
|
|
2019-03-21 22:54:06 +01:00
|
|
|
#
|
|
|
|
# Cleaning
|
|
|
|
#
|
|
|
|
|
|
|
|
clean-fxg1a:
|
|
|
|
@rm -rf build/fxg1a
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@rm -rf build
|
|
|
|
distclean: clean
|
|
|
|
@rm -rf bin
|
|
|
|
@rm -f Makefile.cfg
|