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

Add Makefile #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Add Makefile #5

wants to merge 7 commits into from

Conversation

Toasterson
Copy link

Add a Makefile to help with packaging and building consistently

@citrus-it
Copy link
Member

It would probably better if this was in illumos make and not GNU make, given its target audience.

@Toasterson
Copy link
Author

I agree. But do you have a guide how to write those statements illumos make conform? I never found any.

@jclulow
Copy link
Member

jclulow commented Aug 18, 2021

So I think this slightly different Makefile will work with either:

INSTALL = /usr/sbin/install
BINDIR = /usr/lib
MANIFESTDIR = /lib/svc/manifest/system

PRE_HASH = pre\#
HASH = $(PRE_HASH:pre\%=%)

SET_OWNER = $(HASH)
$(SET_OWNER)OWNER_BIN = -u root -g bin
$(SET_OWNER)OWNER_SMF = -u root -g sys

INSTALL_BIN = $(INSTALL) -s -f $(DESTDIR)$(BINDIR) $(OWNER_BIN) -m 0755
INSTALL_SMF = $(INSTALL) -s -f $(DESTDIR)$(MANIFESTDIR) $(OWNER_SMF) -m 0644

build: build-debug

build-debug:
	cargo build

build-release:
	cargo build --release

install-%: build-%
	mkdir -p $(DESTDIR)/usr/lib
	mkdir -p $(DESTDIR)/lib/svc/manifest/system
	$(INSTALL_BIN) target/$(@:install-%=%)/metadata
	$(INSTALL_BIN) userscript.sh
	$(INSTALL_SMF) metadata.xml
	$(INSTALL_SMF) userscript.xml

install: install-release

clean:
	cargo clean

You would use it thus:

  • To install debug bits: make install-debug DESTDIR=/tmp/proto
  • To install release bits: make install DESTDIR=/tmp/proto
  • To install release bits and set user/group ownership: make install DESTDIR=/tmp/proto SET_OWNER=

@Toasterson
Copy link
Author

Oh, nice. I like it. This is some awesome make foo.

I think I understand most. But what does the PRE_HASH/HASH bit do?

@jclulow
Copy link
Member

jclulow commented Jun 14, 2022

I think I understand most. But what does the PRE_HASH/HASH bit do?

It is the only way of which I am aware to get a macro that contains just the # (hash) character. We then set SET_OWNER to the value of HASH, which means it too will expand to just a #. This means that this line:

$(SET_OWNER)OWNER_BIN = -u root -g bin

Will expand to:

#OWNER_BIN = -u root -g bin

Which means it is effectively commented out, and does nothing, leaving OWNER_BIN unset. If you override SET_OWNER to have no value, then it expands as:

OWNER_BIN = -u root -g bin

Which will set OWNER_BIN. All of this adds up to effectively making a behaviour conditional on arguments (or the environment, under some conditions) passed to make when it's invoked.

@Toasterson
Copy link
Author

@jclulow Updated as suggested. also fixed the bug where SET_OWNER was not overridable as variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants