restructure makefile for agent program

This commit is contained in:
xenia 2020-12-29 03:12:48 -05:00
parent e555a6237e
commit 311ce74f82
2 changed files with 98 additions and 59 deletions

View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
.PHONY: all clean mrproper local-racket
.PHONY: all clean mrproper
APP_NAME=crossfire-agent
RKT_NAME=$(APP_NAME).rkt
@ -27,35 +27,20 @@ TARGET_ARCH=$(shell $(CC) -dumpmachine)
####################################################################################################
LIBS=-ldl -lm
ifneq (,$(findstring x86_64,$(TARGET_ARCH)))
LIBS+=-lpthread -lffi
endif
# for musl
# TODO autodetect musl or something
#LIBS=-lffi -lucontext
ARCH_DIR=arch_$(TARGET_ARCH)
CACHE_DIR=cache
VENDOR_DIR=$(ARCH_DIR)/vendor
MONOCYPHER_DIR=$(VENDOR_DIR)/monocypher-$(MONOCYPHER_VERSION)
MONOCYPHER_URL=https://monocypher.org/download/monocypher-$(MONOCYPHER_VERSION).tar.gz
MONOCYPHER_FILE=$(CACHE_DIR)/monocypher.tar.gz
RACKET_DIR=$(VENDOR_DIR)/racket-$(RACKET_VERSION)
RACKET_URL=https://mirror.racket-lang.org/installers/$(RACKET_VERSION)/racket-minimal-$(RACKET_VERSION)-src.tgz
RACKET_FILE=$(CACHE_DIR)/racket.tar.gz
APP_CFLAGS=-pipe -fPIC -O3 -DAPP_NAME='"$(APP_NAME)"' -DAPP_ARCH='"$(TARGET_ARCH)"'
APP_LDFLAGS=-static -ldl -lm -lpthread
# musl needs -lucontext
all: $(ARCH_DIR)/$(APP_NAME)
include dependencies.mk
# main build
$(ARCH_DIR)/$(APP_NAME): main_bc.c app.o $(MONOCYPHER_DIR)/lib/libmonocypher.a
$(ARCH_DIR)/$(APP_NAME): main_bc.c app.o vnd-deps
[ -d $(ARCH_DIR) ] || mkdir -p $(ARCH_DIR)
$(CC) -o $@ -pipe -fPIC -O3 -DAPP_NAME='"$(APP_NAME)"' -I$(MONOCYPHER_DIR)/src -static $^ \
-DAPP_ARCH='"$(TARGET_ARCH)"' \
-L$(MONOCYPHER_DIR)/lib -L$(RACKET_DIR)/lib \
-lracket3m -lrktio -lmonocypher $(LIBS)
$(CC) -o $@ $(APP_CFLAGS) $(VND_CFLAGS) main_bc.c app.o \
$(VND_LDFLAGS) $(APP_LDFLAGS)
# this is faster than --c-mods by a lot
# it's potentially less portable but works on GNU ld and probably lld too
@ -66,40 +51,6 @@ app.zo: $(RKT_NAME)
raco ctool --mods $@ $<
clean:
$(RM) $(APP_NAME) *.zo *.o
$(RM) $(ARCH_DIR)/$(APP_NAME) *.zo *.o
mrproper: clean
$(RM) -r $(VENDOR_DIR) $(CACHE_DIR)
$(MONOCYPHER_DIR)/lib/libmonocypher.a: $(MONOCYPHER_DIR)/.extracted
cd $(MONOCYPHER_DIR) && $(MAKE) USE_ED22519=true static-library
$(MONOCYPHER_DIR)/.extracted: $(MONOCYPHER_FILE)
[ -d $(MONOCYPHER_DIR) ] || mkdir -p $(MONOCYPHER_DIR)
tar xf $< -C $(VENDOR_DIR) && touch $@
$(MONOCYPHER_FILE):
[ -d $(CACHE_DIR) ] || mkdir -p $(CACHE_DIR)
wget -O $@ $(MONOCYPHER_URL) || curl -o $@ $(MONOCYPHER_URL)
local-racket: $(RACKET_DIR)/lib/libracket3m.a
$(RACKET_DIR)/lib/libracket3m.a: $(RACKET_DIR)/.extracted
cd $(RACKET_DIR)/src && ./configure --enable-bconly --prefix=/usr --sysconfdir=/etc \
--disable-libffi
cd $(RACKET_DIR)/src && $(MAKE)
[ -d $(RACKET_DIR)/lib ] || mkdir $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/rktio/librktio.a $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/libracket3m.a $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/foreign/libffi/.libs/libffi.a $(RACKET_DIR)/lib
$(RACKET_DIR)/.extracted: $(RACKET_FILE)
[ -d $(RACKET_DIR) ] || mkdir -p $(RACKET_DIR)
tar xf $< -C $(VENDOR_DIR) && touch $@
$(RACKET_FILE):
[ -d $(CACHE_DIR) ] || mkdir -p $(CACHE_DIR)
wget -O $@ $(RACKET_URL) || curl -o $@ $(RACKET_URL)

View File

@ -0,0 +1,88 @@
# crossfire: distributed brute force infrastructure
#
# Copyright (C) 2020 haskal
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
CACHE_DIR=cache
VENDOR_DIR=$(ARCH_DIR)/vendor
MONOCYPHER_DIR=$(VENDOR_DIR)/monocypher-$(MONOCYPHER_VERSION)
MONOCYPHER_URL=https://monocypher.org/download/monocypher-$(MONOCYPHER_VERSION).tar.gz
MONOCYPHER_FILE=$(CACHE_DIR)/monocypher.tar.gz
RACKET_DIR=$(VENDOR_DIR)/racket-$(RACKET_VERSION)
RACKET_URL=https://mirror.racket-lang.org/installers/$(RACKET_VERSION)/racket-minimal-$(RACKET_VERSION)-src.tgz
RACKET_FILE=$(CACHE_DIR)/racket.tar.gz
define download-file =
[ -d $(CACHE_DIR) ] || mkdir -p $(CACHE_DIR)
wget -O $@ $1 || curl -o $@ $1
endef
define extract-file =
[ -d $1 ] || mkdir -p $1
tar xf $< -C $(VENDOR_DIR) && touch $@
endef
## monocypher
VND_MONOCYPHER=$(MONOCYPHER_DIR)/lib/libmonocypher.a
VND_MONOCYPHER_CFLAGS=-I$(MONOCYPHER_DIR)/src
VND_MONOCYPHER_LDFLAGS=-L$(MONOCYPHER_DIR)/lib -lmonocypher
$(VND_MONOCYPHER): $(MONOCYPHER_DIR)/.extracted
cd $(MONOCYPHER_DIR) && $(MAKE) USE_ED22519=true static-library
$(MONOCYPHER_DIR)/.extracted: $(MONOCYPHER_FILE)
$(call extract-file,$(MONOCYPHER_DIR))
$(MONOCYPHER_FILE):
$(call download-file,$(MONOCYPHER_URL))
## racket
VND_RACKET_BC=$(RACKET_DIR)/lib/libracket3m.a
VND_RACKET_BC_CFLAGS=-I$(RACKET_DIR)/src/include
VND_RACKET_BC_LDFLAGS=-L$(RACKET_DIR)/lib -lracket3m -lrktio -lffi
$(VND_RACKET_BC): $(RACKET_DIR)/.extracted
cd $(RACKET_DIR)/src && ./configure --enable-bconly --prefix=/usr --sysconfdir=/etc \
--disable-libffi
cd $(RACKET_DIR)/src && $(MAKE)
[ -d $(RACKET_DIR)/lib ] || mkdir $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/rktio/librktio.a $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/libracket3m.a $(RACKET_DIR)/lib
cp $(RACKET_DIR)/src/bc/foreign/libffi/.libs/libffi.a $(RACKET_DIR)/lib
$(RACKET_DIR)/.extracted: $(RACKET_FILE)
$(call extract-file,$(RACKET_DIR))
$(RACKET_FILE):
$(call download-file,$(RACKET_URL))
## common
.PHONY: vnd-deps-clean vnd-deps
VND_CFLAGS=$(VND_MONOCYPHER_CFLAGS) $(VND_RACKET_BC_CFLAGS)
VND_LDFLAGS=$(VND_MONOCYPHER_LDFLAGS) $(VND_RACKET_BC_LDFLAGS)
vnd-deps: $(VND_MONOCYPHER) $(VND_RACKET_BC)
mrproper: vnd-deps-clean
vnd-deps-clean:
$(RM) -r $(VENDOR_DIR) $(CACHE_DIR)