You are not logged in.

#1 2013-05-31 18:42:45

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,688
Website

Advice for managing a Makefile generic to many distros [solved]

The way I have handled installation on multiple distros of my homegrown project, psd, is by providing matching Makefiles that correspond to each distro.  For example:

Makefile.archlinux
Makefile.fedora
Makefile.ubuntu

The INSTALL file shows users to simply symlink the correct makefile for their distro prior to building, i.e.:

ln -s Makefile.archlinux Makefile && make

This works but isn't very elegant.  I am seeking advice for combining these multiple Makefiles into a simplistic method to allow the same functionality.  Suggestions are welcomed.

There is an open issue on my github about this.  Feel free to comment in this thread or in the issue itself.

Last edited by graysky (2013-06-02 20:29:35)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Online

#2 2013-05-31 18:46:09

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,097
Website

Re: Advice for managing a Makefile generic to many distros [solved]

You could add a variable like ${DISTRO} or something similar and have it do the specific operations as necessary based on the value of distro, which could then be declared in the make command by the user.

Thoughts?

All the best,

-HG

Offline

#3 2013-05-31 18:48:57

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Advice for managing a Makefile generic to many distros [solved]

I briefly looked at the different Makefiles... What's different in them that causes you to need separate Makefiles? What causes different distributions to need special cases?

I, too, immediately thought "Use GNU Autotools" (or a modern replacement). Is there a reason why you wouldn't?

Offline

#4 2013-05-31 19:04:36

digirium
Member
Registered: 2012-11-15
Posts: 51

Re: Advice for managing a Makefile generic to many distros [solved]

Thought of using m4?

You could combine all the subtleties for various distros into one single makefile, run the makefile through the m4 pre-processor for a specific distro. Nice thing about it is that you will just have one makefile to maintain.

Offline

#5 2013-05-31 20:23:22

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Advice for managing a Makefile generic to many distros [solved]

digirium wrote:

Thought of using m4?

You could combine all the subtleties for various distros into one single makefile, run the makefile through the m4 pre-processor for a specific distro. Nice thing about it is that you will just have one makefile to maintain.

This is a trick question, right? Because I think you just described GNU Autotools... tongue

Offline

#6 2013-05-31 21:32:09

digirium
Member
Registered: 2012-11-15
Posts: 51

Re: Advice for managing a Makefile generic to many distros [solved]

drcouzelis wrote:
digirium wrote:

Thought of using m4?

You could combine all the subtleties for various distros into one single makefile, run the makefile through the m4 pre-processor for a specific distro. Nice thing about it is that you will just have one makefile to maintain.

This is a trick question, right? Because I think you just described GNU Autotools... tongue

Ahh I suppose so! smile

Offline

#7 2013-05-31 21:50:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: Advice for managing a Makefile generic to many distros [solved]

TARGET   =  `uname -a`
...

default: ${TARGET}

Arch:
    #arch linux specific stuff here

Ubuntoo:
    #uboontoo specifics here <note, check the output of uname -a on these systems, I only have arch>

Fedora:
    #get it?

Autotools shmatotools.  I have one Make file for three different operating systems.  Ever notice how many projects that use autotools may only take a second or two to compile, but the damned configure script could take a minute or two to finish.

EDIT: Better yet, combine this with HalosGhost's suggestion so the top would be:

TARGET   ?= `uname -a`

Then users who know what they are doing can specify/override the default behavior, but if they just blindly run 'make' it should still work.

Last edited by Trilby (2013-05-31 21:54:11)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2013-05-31 21:52:25

HalosGhost
Forum Moderator
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 2,097
Website

Re: Advice for managing a Makefile generic to many distros [solved]

Trilby wrote:
[snip]

Much more elegantly explained. But I'd recommend this solution as opposed to autotools; it's much cleaner imho.

All the best,

-HG

P.S., but `uname -s` or `uname -o` might be better than `uname -a`

Last edited by HalosGhost (2013-05-31 21:54:17)

Offline

#9 2013-05-31 22:01:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: Advice for managing a Makefile generic to many distros [solved]

Crap ... yes, -n was just a coincidence in my case.  I named my computer "Arch".  Sorry.  But -s and -o are good for determining the os (Linux), not the distro.  But /etc/os-release should have it.

TARGET   ?= `source /etc/os-release && echo $$NAME`

Last edited by Trilby (2013-05-31 22:12:44)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2013-05-31 22:22:30

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,688
Website

Re: Advice for managing a Makefile generic to many distros [solved]

Good suggestions here, all.  Thank you.  I am attracted to the simplicity of trilby's suggestion.

Last edited by graysky (2013-05-31 22:23:23)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Online

#11 2013-06-01 00:08:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: Advice for managing a Makefile generic to many distros [solved]

See my email reply - I did botch some of the particulars in my initial suggestions - but the concept will work.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2013-06-01 01:43:37

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Advice for managing a Makefile generic to many distros [solved]

HalosGhost wrote:

But I'd recommend this solution as opposed to autotools; it's much cleaner imho.

But, but, but, but, what about "make install" to a special location? What about "make uninstall"? What about ensuring that necessary dependencies are installed? What about "make dist" to package up the source code? What about installing on Slackware, FreeBSD, Cygwin, and Haiku? yikes

...It doesn't really matter to me, of course. tongue But I TOTALLY got bitten recently by NOT using THE "standard" for makefiles.

Offline

#13 2013-06-01 02:21:51

progandy
Member
Registered: 2012-05-17
Posts: 5,280

Re: Advice for managing a Makefile generic to many distros [solved]

a makefile can contain include statements and conditional code. So you could include the system specific makefile.
http://www.chemie.fu-berlin.de/chemnet/ … html#SEC15
http://www.chemie.fu-berlin.de/chemnet/ … html#SEC67

Edit: or create your custom ./configure. Who says you have to use autotools? You can put your own shellscript there, and e.g. check dependencies with pkg-config.

Last edited by progandy (2013-06-01 02:38:21)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#14 2013-06-01 02:24:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: Advice for managing a Makefile generic to many distros [solved]

Here's what went out via email:

include /etc/os-release
NULL		:=
SPACE		:= ${NULL} ${NULL}
${SPACE}	:= ${SPACE}
TARGET		:= $(subst ",,$(subst ${ },_,${NAME}))

default: ${TARGET}

install: ${TARGET}.install


Arch_Linux:
	echo "build related stuff here"

Arch_Linux.install:
	echo "installation stuff here"

Fedora:
	...

Fedora.install:
	...

One can have install/uninstall/whatever directives that are different for every distro ... as long as they use os-release.  Other OSs don't, but there are simpler methods for detecting the OS.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#15 2013-06-01 16:40:46

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,688
Website

Re: Advice for managing a Makefile generic to many distros [solved]

Firstly, thanks to everyone who relied with suggestions.  I don't want to learn autotools/m4 and opted for a simple configure script that will select which Makefile.xxx is needed (supported distros).  Changes reside on the unstable branch in commit 7450fae.

Feedback is appreciated.

EDIT: Bah, mine was a dirty hack.  This is now solved thanks to a gentoo user/dev.  The Makefile he proposed is rather elegant solution.  Check it out on the github repo and thank you all who replied.

Last edited by graysky (2013-06-02 20:30:45)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Online

Board footer

Powered by FluxBB