use the less-painful CMake
This commit is contained in:
parent
41fbdb144e
commit
f1ccb5ce88
|
@ -0,0 +1,61 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(fxos LANGUAGES C CXX)
|
||||
|
||||
find_package(BISON 3.7)
|
||||
find_package(FLEX 2.6)
|
||||
|
||||
add_compile_options(-Wall -Wextra -D_GNU_SOURCE -std=c++17 -O2)
|
||||
|
||||
#---
|
||||
# fxos core
|
||||
#---
|
||||
|
||||
flex_target(LoadAsm lib/load-asm.l "${CMAKE_CURRENT_BINARY_DIR}/load-asm.yy.cpp" COMPILE_FLAGS -s)
|
||||
flex_target(LoadHeader lib/load-header.l "${CMAKE_CURRENT_BINARY_DIR}/load-header.yy.cpp" COMPILE_FLAGS -s)
|
||||
flex_target(LoadSymbols lib/load-symbols.l "${CMAKE_CURRENT_BINARY_DIR}/load-symbols.yy.cpp" COMPILE_FLAGS -s)
|
||||
flex_target(LoadTarget lib/load-target.l "${CMAKE_CURRENT_BINARY_DIR}/load-target.yy.cpp" COMPILE_FLAGS -s)
|
||||
|
||||
set(fxos_core_SOURCES
|
||||
lib/disassembly.cpp
|
||||
lib/domains/relconst.cpp
|
||||
lib/lang.cpp
|
||||
lib/library.cpp
|
||||
lib/log.cpp
|
||||
lib/memory.cpp
|
||||
lib/os.cpp
|
||||
lib/passes/cfg.cpp
|
||||
lib/passes/pcrel.cpp
|
||||
lib/passes/print.cpp
|
||||
lib/passes/syscall.cpp
|
||||
lib/semantics.cpp
|
||||
lib/symbols.cpp
|
||||
lib/util.cpp
|
||||
lib/vspace.cpp)
|
||||
|
||||
add_library(fxos-core ${fxos_core_SOURCES}
|
||||
${FLEX_LoadAsm_OUTPUTS} ${FLEX_LoadHeader_OUTPUTS}
|
||||
${FLEX_LoadSymbols_OUTPUTS} ${FLEX_LoadTarget_OUTPUTS})
|
||||
|
||||
target_include_directories(fxos-core PUBLIC include)
|
||||
|
||||
#---
|
||||
# fxos shell
|
||||
#---
|
||||
|
||||
#bison_target()
|
||||
|
||||
set(fxos_shell_SOURCES
|
||||
fxos/disassembly.cpp
|
||||
fxos/info.cpp
|
||||
fxos/library.cpp
|
||||
fxos/main.cpp)
|
||||
|
||||
add_executable(fxos ${fxos_shell_SOURCES})
|
||||
|
||||
target_link_libraries(fxos fxos-core)
|
||||
|
||||
#---
|
||||
# Install
|
||||
#---
|
||||
|
||||
install(TARGETS fxos DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
120
Makefile
120
Makefile
|
@ -1,120 +0,0 @@
|
|||
#! /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
|
14
README.md
14
README.md
|
@ -20,18 +20,14 @@ requirements.
|
|||
|
||||
* g++ (9.2.0)
|
||||
* flex (2.6.4) and bison (3.5)
|
||||
* make (eg. 4.2.1)
|
||||
* CMake (3.15) and make (eg. 4.2.1)
|
||||
|
||||
The only configure option is the install path; it is specified on the
|
||||
command-line to make. By default the only installed file is the fxos binary,
|
||||
which goes to `$PREFIX/bin`. The default prefix is `$HOME/.local`.
|
||||
The only real configure option is the install path. CMake's default is
|
||||
`/usr/local`; a viable alternative is `$HOME/.local`.
|
||||
|
||||
```sh
|
||||
% make
|
||||
% make install
|
||||
# or, for instance:
|
||||
% make PREFIX=/usr
|
||||
% make install PREFIX=/usr
|
||||
% cmake -B build # -DCMAKE_INSTALL_PREFIX=$HOME/.local
|
||||
% make -C build -j$(nproc) install
|
||||
```
|
||||
|
||||
## Setting up the library
|
||||
|
|
Loading…
Reference in New Issue