Skip to content

Instantly share code, notes, and snippets.

@mankyKitty
Last active July 31, 2016 07:02
Show Gist options
  • Save mankyKitty/4ab60f764180a4875bb728627585fa64 to your computer and use it in GitHub Desktop.
Save mankyKitty/4ab60f764180a4875bb728627585fa64 to your computer and use it in GitHub Desktop.
Levelling up my make skills.
REVISION := 1.wut
ARCH := x86_64
PRJ := $(shell basename $(shell pwd))
CABAL := $(PRJ).cabal
VER := $(shell awk '/^version:/{ print $$2 }' $(CABAL))
MAINTAINER := $(shell awk '/^maintainer:/{ print $$2 }' $(CABAL))
DESC := $(shell awk '/^description:/{ print substr($$0, index($$0,$$2)) }' $(CABAL))
SYNOP := $(shell awk '/^synopsis:/{ print substr($$0, index($$0,$$2)) }' $(CABAL))
EXTERNAL_PKGS = external-pkgs.txt
DEPENDS := $(shell awk '{ printf "--depends " $$1 " " }' $(EXTERNAL_PKGS))
BUILD_ROOT := BUILDROOT
RELATIVE_APP_DIR := apps/$(PRJ)
WORK_DIR := build-$(PRJ)_XXXX
EPOCH := $(shell date "+%s")
BLD := stack
TMP_DIR := $(shell mktemp -d "/tmp/$(WORK_DIR)")
BDIR = $(TMP_DIR)/$(BUILD_ROOT)/$(RELATIVE_APP_DIR)
RPM_NAME = $(PRJ)-$(VER)-$(REVISION).$(ARCH).rpm
INIT_F = $(wildcard init/*)
BIN_SCRIPT_F = $(wildcard bin/*.sh)
TEMPLATE_F = $(wildcard templates/*)
.PHONY: all clean
.DEFAULT: build
all:
@echo $(PRJ)
@echo $(VER)
@echo $(DEPENDS)
@echo $(RPM_NAME)
mk_tmp:
@echo Making working folder $(TMP_DIR)
@mkdir -p $(BDIR)
ifneq ($(strip $(INIT_F)),)
init_scripts:
@echo "Init scripts detected"
@mkdir $(BDIR)/init
@cp init/* $(BDIR)/init/
else
init_scripts:
@echo "No init files - Not necessarily an error"
endif
ifneq ($(strip $(TEMPLATE_F)),)
template_files:
@echo "Template files detected"
@mkdir $(BDIR)/templates
@cp templates/* $(BDIR)/templates/
else
template_files:
@echo "No template files - Unlikely to be an error"
endif
ifneq ($(strip ($BIN_SCRIPT_F)),)
bin_scripts:
@echo "Script files detected"
@mkdir $(BDIR)/bin
@cp bin/* $(BDIR)/bin/
else
bin_scripts:
@echo "No bin 'sh' files found - This is probably an error."
endif
build:
@echo "Running build..."
$(BLD) build
test:
@echo "Running tests..."
$(BLD) test
clean:
$(BLD) clean
rpm: all mk_tmp init_scripts template_files bin_scripts
$(BLD) install --local-bin-path $(BDIR)/bin/
@echo "Building RPM and including the following files..."
@echo "bin/$(PRJ)"
@echo $(BIN_SCRIPT_F) $(INIT_F) $(TEMPLATE_F)
@echo "With the following external dependencies...( $(DEPENDS) )"
@echo "Starting RPM build with 'fpm'"
@fpm -n '$(PRJ)' -t rpm -s dir -a native -C $(BDIR) \
-m '$(MAINTAINER)' --vendor 'Team' --version $(VER) \
--rpm-changelog Changelog.fpm --license Non-distributable --description '$(DESC) - $(SYNOP)' --iteration $(REVISION) \
--epoch $(EPOCH) $(DEPENDS) bin/$(PRJ) $(BIN_SCRIPT_F) $(INIT_F) $(TEMPLATE_F)
scp_rpm: rpm
@scp $(RPM_NAME) dat.build.server:/wut/
clean_tmp:
@echo "Removing All Project Build Attempts ... /tmp/build-$(PRJ)_*"
@rm -Rf /tmp/build-$(PRJ)_*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment