#! /usr/bin/make -f # Tools AR = ar CC = gcc CXX = g++ # Compiler flags CFLAGS = -Wall -Wextra -I include -D_GNU_SOURCE -std=c++17 -O3 -flto \ -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.c.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: $(obj-fxos) bin/libfxos.a | 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.c: %.l flex -o $@ -s $< build/%.yy.c.o: build/%.yy.c $(CXX) -c $< -o $@ $(CFLAGS) -Wno-unused-function $(DEPFLAGS) bin/: @mkdir -p $@ # # Dependency generation # include $(wildcard build/*/*.d) .PHONY: all all-lib all-fxos clean clean-lib clean-fxos distclean .PRECIOUS: build/%.d build/%.yy.c # # 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 -d $(PREFIX)/share/fxos install $(TARGETS) $(m755) $(PREFIX)/bin @echo "TODO: Install data files" @false # install fxos/*.txt $(m644) $(PREFIX)/share/fxos uninstall: rm -f $(TARGETS:%=$(PREFIX)/%) rm -rf $(PREFIX)/share/fxos # # Cleaning # clean-lib: @rm -rf build/lib clean-fxos: @rm -rf build/fxos clean: @rm -rf build distclean: clean @rm -rf bin