Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📂 mommy allows custom dirs during make~ #70

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* 📈 mommy now explains how to integrate with nushell, thanks to [aemogie.](https://github.com/aemogie)~ ([#65](https://github.com/FWDekker/mommy/issues/65))

### changed
* 💨 mommy is now much faster at doing her exams~ ([#69](https://github.com/FWDekker/mommy/pull/69))
* 🍳 mommy uses newer github actions, thanks to [zopolis4](https://github.com/Zopolis4)~ ([#68](https://github.com/FWDekker/mommy/pull/68))
* 💨 mommy became much faster at doing her exams~ ([#69](https://github.com/FWDekker/mommy/pull/69))
* 📂 mommy supports specifying a custom directory during `make`~ ([#70](https://github.com/FWDekker/mommy/pull/70))


## [1.2.4] -- 2023-08-28
Expand Down
98 changes: 51 additions & 47 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Target locations
# Build file locations
build_dir := build/
dist_dir := dist/

# Install locations
prefix := /usr/
bin_prefix := $(prefix)/bin/
man_prefix := $(prefix)/share/man/
Expand Down Expand Up @@ -26,7 +30,7 @@ list:
# Clean up previous builds
.PHONY: clean
clean:
@rm -rf build/ dist/
@rm -rf "$(build_dir)" "$(dist_dir)"


## Tests
Expand All @@ -39,37 +43,37 @@ test/%:
@MOMMY_SYSTEM="$(system)" MOMMY_MAKE="$(MAKE)" shellspec "src/test/sh/$(@:test/%=%)_spec.sh"


## "Compile" files into `build/`
## "Compile" source files into '$(build_dir)' along a simple prefix layout
.PHONY: build
build:
@# Copy relevant files
@mkdir -p build/bin/; cp src/main/sh/mommy build/bin/
@mkdir -p build/man/man1/; cp src/main/man/man1/mommy.1 build/man/man1/
@mkdir -p build/completions/fish/; cp src/main/completions/fish/mommy.fish build/completions/fish/
@mkdir -p build/completions/zsh/; cp src/main/completions/zsh/_mommy build/completions/zsh/
@mkdir -p "$(build_dir)/bin/"; cp src/main/sh/mommy "$(build_dir)/bin/"
@mkdir -p "$(build_dir)/man/man1/"; cp src/main/man/man1/mommy.1 "$(build_dir)/man/man1/"
@mkdir -p "$(build_dir)/completions/fish/"; cp src/main/completions/fish/mommy.fish "$(build_dir)/completions/fish/"
@mkdir -p "$(build_dir)/completions/zsh/"; cp src/main/completions/zsh/_mommy "$(build_dir)/completions/zsh/"

@# Insert version information
@sed -i".bak" "s/%%VERSION_NUMBER%%/$(version)/g;s/%%VERSION_DATE%%/$(date)/g" \
build/bin/mommy \
build/man/man1/mommy.1
@rm -f build/bin/mommy.bak build/man/man1/mommy.1.bak
"$(build_dir)/bin/mommy" \
"$(build_dir)/man/man1/mommy.1"
@rm -f "$(build_dir)/bin/mommy.bak" "$(build_dir)/man/man1/mommy.1.bak"

@# Compress
@gzip -f build/man/man1/mommy.1
@gzip -f "$(build_dir)/man/man1/mommy.1"


## Installation
# Copy built files into appropriate directories
# Copy built files into prefix-appropriate directories
.PHONY: install
install: build
@# Create directories
@install -m 755 -d "$(bin_prefix)" "$(man_prefix)/man1/" "$(fish_prefix)" "$(zsh_prefix)"

@# Copy files
@install -m 755 build/bin/mommy "$(bin_prefix)"
@install -m 644 build/man/man1/mommy.1.gz "$(man_prefix)/man1/"
@install -m 644 build/completions/fish/mommy.fish "$(fish_prefix)"
@install -m 644 build/completions/zsh/_mommy "$(zsh_prefix)"
@install -m 755 "$(build_dir)/bin/mommy" "$(bin_prefix)"
@install -m 644 "$(build_dir)/man/man1/mommy.1.gz" "$(man_prefix)/man1/"
@install -m 644 "$(build_dir)/completions/fish/mommy.fish" "$(fish_prefix)"
@install -m 644 "$(build_dir)/completions/zsh/_mommy" "$(zsh_prefix)"

# Install with preset overrides, as specified later
.PHONY: install/%
Expand Down Expand Up @@ -100,25 +104,25 @@ fpm: build
ifndef fpm_target
$(error fpm_target is undefined)
endif
@mkdir -p dist
@mkdir -p "$(dist_dir)"
@fpm -t "$(fpm_target)" \
-p "dist/mommy-$(version).$(fpm_target)" \
-p "$(dist_dir)/mommy-$(version).$(fpm_target)" \
--version "$(version)" \
\
"build/bin/mommy=$(bin_prefix)/mommy" \
"build/man/man1/mommy.1.gz=$(man_prefix)/man1/mommy.1.gz" \
"build/completions/fish/mommy.fish=$(fish_prefix)/mommy.fish" \
"build/completions/zsh/_mommy=$(zsh_prefix)/_mommy"
"$(build_dir)/bin/mommy=$(bin_prefix)/mommy" \
"$(build_dir)/man/man1/mommy.1.gz=$(man_prefix)/man1/mommy.1.gz" \
"$(build_dir)/completions/fish/mommy.fish=$(fish_prefix)/mommy.fish" \
"$(build_dir)/completions/zsh/_mommy=$(zsh_prefix)/_mommy"

# Build generic extractable package
dist/generic: prefix = ./build/generic/mommy/usr/
dist/generic: prefix = $(build_dir)/generic/mommy-$(version)/usr/
dist/generic:
@rm -rf build/generic/
@rm -rf "$(build_dir)/generic/"

@$(MAKE) prefix="$(prefix)" install

@mkdir -p dist/
@tar -C build/generic/ -czf "dist/mommy-$(version)+generic.tar.gz" ./
@mkdir -p "$(dist_dir)"
@tar -C "$(build_dir)/generic/" -czf "$(dist_dir)/mommy-$(version)+generic.tar.gz" ./

# Build Debian package with fpm
dist/deb: zsh_prefix = $(prefix)/share/zsh/vendor-completions/
Expand All @@ -135,34 +139,34 @@ dist/osxpkg:
@$(MAKE) fpm_target=osxpkg prefix="$(prefix)" fpm

@# `installer` program requires `pkg` extension
@mv dist/*.osxpkg "dist/mommy-$(version)+osx.pkg"
@mv "$(dist_dir)/"*".osxpkg" "$(dist_dir)/mommy-$(version)+osx.pkg"

# Build FreeBSD package with fpm
%/freebsd: prefix = /usr/local/
dist/freebsd:
@$(MAKE) fpm_target=freebsd prefix="$(prefix)" fpm

# Build NetBSD package manually
%/netbsd: prefix = build/netbsd/usr/pkg/
%/netbsd: prefix = $(build_dir)/netbsd/usr/pkg/
%/netbsd: man_prefix = $(prefix)/man/
dist/netbsd:
@$(MAKE) prefix="$(prefix)" man_prefix="$(man_prefix)" install

@cd build/netbsd; find . -type f | sed -e "s/^/.\//" > +CONTENTS
@cd "$(build_dir)/netbsd"; find . -type f | sed -e "s/^/.\//" > +CONTENTS

@echo "$(comment)" > build/netbsd/+COMMENT
@echo "$(comment)" > "$(build_dir)/netbsd/+COMMENT"

@echo "$(comment)" > build/netbsd/+DESC
@echo "" >> build/netbsd/+DESC
@echo "Maintainer: $(maintainer)" >> build/netbsd/+DESC
@echo "$(comment)" > "$(build_dir)/netbsd/+DESC"
@echo "" >> "$(build_dir)/netbsd/+DESC"
@echo "Maintainer: $(maintainer)" >> "$(build_dir)/netbsd/+DESC"

@echo "MACHINE_ARCH=$$(uname -p)" > build/netbsd/+BUILD_INFO
@echo "OPSYS=$$(uname)" >> build/netbsd/+BUILD_INFO
@echo "OS_VERSION=$$(uname -r)" >> build/netbsd/+BUILD_INFO
@echo "PKGTOOLS_VERSION=$$(pkg_create -V)" >> build/netbsd/+BUILD_INFO
@echo "MACHINE_ARCH=$$(uname -p)" > "$(build_dir)/netbsd/+BUILD_INFO"
@echo "OPSYS=$$(uname)" >> "$(build_dir)/netbsd/+BUILD_INFO"
@echo "OS_VERSION=$$(uname -r)" >> "$(build_dir)/netbsd/+BUILD_INFO"
@echo "PKGTOOLS_VERSION=$$(pkg_create -V)" >> "$(build_dir)/netbsd/+BUILD_INFO"


@cd build/netbsd; \
@cd "$(build_dir)/netbsd"; \
pkg_create \
-B +BUILD_INFO \
-c +COMMENT \
Expand All @@ -172,23 +176,23 @@ dist/netbsd:
-p . \
"mommy-$(version)+netbsd.tgz"

@mkdir -p dist/
@mv build/netbsd/mommy*.tgz dist/
@mkdir -p "$(dist_dir)"
@mv "$(build_dir)/netbsd/mommy-$(version)+netbsd.tgz" "$(dist_dir)"

# Build OpenBSD package manually
%/openbsd: prefix = build/openbsd/usr/local/
%/openbsd: prefix = $(build_dir)/openbsd/usr/local/
%/openbsd: man_prefix = $(prefix)/man/
dist/openbsd:
@$(MAKE) prefix="$(prefix)" man_prefix="$(man_prefix)" install

@cd build/openbsd; find . -type f | sed -e "s/^/.\//" > +CONTENTS
@cd "$(build_dir)/openbsd"; find . -type f | sed -e "s/^/.\//" > +CONTENTS

@echo "$(comment)" > build/openbsd/+COMMENT
@echo "$(comment)" > "$(build_dir)/openbsd/+COMMENT"

@echo "$(comment)" > build/openbsd/+DESC
@echo "$(comment)" > "$(build_dir)/openbsd/+DESC"


@cd build/openbsd; \
@cd "$(build_dir)/openbsd"; \
pkg_create \
-d +DESC \
-D COMMENT="$(comment)" \
Expand All @@ -199,5 +203,5 @@ dist/openbsd:
-p / \
"mommy-$(version)+openbsd.tgz"

@mkdir -p dist/
@mv build/openbsd/mommy*.tgz dist/
@mkdir -p "$(dist_dir)"
@mv "$(build_dir)/openbsd/mommy-$(version)+openbsd.tgz" "$(dist_dir)"