fxos/Makefile

121 lines
2.1 KiB
Makefile
Executable File

#! /usr/bin/make -f
# Tools
AR = ar
CC = gcc
CXX = g++
# Compiler flags
CFLAGS = -Wall -Wextra -I include -D_GNU_SOURCE -std=c++17 -Og -g \
-fno-diagnostics-show-line-numbers
CXXFLAGS = $(CFLAGS)
# Linker flags
LDFLAGS = $(CFLAGS) -Lbin -lfxos
# Dependency generation flags
DEPFLAGS = -MT $@ -MMD -MP -MF $(@:%.o=%.d)
# Default install prefix (beware of sudo...)
PREFIX ?= $(HOME)/.local
#
# Main targets
#
TARGETS := bin/fxos
all: $(TARGETS)
all-lib: bin/libfxos.a
all-fxos: bin/fxos
obj = $($1:%=build/%.o)
lex = $($1:%.l=build/%.yy.cpp.o)
## The library
src-lib := $(wildcard lib/*.cpp lib/*/*.cpp lib/*/*/*.cpp)
lex-lib := $(wildcard lib/*.l lib/*/*.l lib/*/*/*.l)
obj-lib := $(call obj,src-lib) $(call lex,lex-lib)
bin/libfxos.a: $(obj-lib) | bin/
$(AR) rcs $@ $^
## The command-line interface
src-fxos := $(wildcard fxos/*.cpp fxos/*/*.cpp fxos/*/*/*.cpp)
obj-fxos := $(call obj,src-fxos)
bin/fxos: bin/libfxos.a $(obj-fxos) | bin/
$(CXX) $(obj-fxos) -o $@ $(LDFLAGS)
#
# Source targets
#
# C++ sources
build/%.cpp.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) -c $< -o $@ $(CXXFLAGS) $(DEPFLAGS)
# C sources
build/%.c.o: %.c
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(CFLAGS) $(DEPFLAGS)
# Flex lexers for the database
build/%.yy.cpp: %.l
@mkdir -p $(dir $@)
flex -o $@ -s $<
build/%.yy.cpp.o: build/%.yy.cpp
$(CXX) -c $< -o $@ $(CFLAGS) -Wno-unused-function $(DEPFLAGS)
bin/:
@mkdir -p $@
#
# Dependency generation
#
include $(wildcard build/*/*.d build/*/*/*.d build/*/*/*/*.d)
.PHONY: all all-lib all-fxos clean clean-lib clean-fxos distclean
.PRECIOUS: build/%.d build/%.yy.cpp
#
# Installing
#
m644 := -m 644
m755 := -m 755
sed := -i -e '/^PREFIX=\\$$/ a \$(PREFIX)'
# Disable -m on Mac OS and use sed differently
ifeq "$(shell uname)" "Darwin"
m644 :=
m755 :=
sed := -i '' -e "$$(printf '/^PREFIX=/ a \\\n$(PREFIX)')"
endif
install: $(TARGETS)
install -d $(PREFIX)/bin
install $(TARGETS) $(m755) $(PREFIX)/bin
uninstall:
rm -f $(TARGETS:%=$(PREFIX)/%)
#
# Cleaning
#
clean-lib:
@rm -rf build/lib
clean-fxos:
@rm -rf build/fxos
clean:
@rm -rf build
distclean: clean
@rm -rf bin