Skip Navigation
makefile

πŸ“’   All about Makefiles, Gnu Make, BSD Make & POSIX Make:

  • Questions
  • Tips & tricks
  • Success stories
  • Failures
  • Use-cases / Showing off
  • Ideas / Design discussions

😎   Don't repeat yourself - Make Make make things happen for you!

πŸ“–   Gnu Make manual is your friend.

πŸ—¨   Join the chatter in #.mk:matrix.org.


⚠   Knowing/Mastering Make is nothing special. Please bear that in mind & keep the conversations respectful & civil.

β›”   Hate speech, bigotry and NSFW content will not be tolerated.


Members
57
Posts
7
Active Today
1
Created
2 yr. ago
  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    bmakelib v0.7.0

    github.com Release v0.7.0 Β· bahmanm/bmakelib

    The highlight is the introduction of fail-fast alternative to $(shell) which relieves you from checking .SHELLSTATUS every time $(shell) is used. Makefile: VAR1 := $(call bmakelib.shell.error-if-no...

    Release v0.7.0 Β· bahmanm/bmakelib

    bmakelib v0.7.0 has just been released.

    The highlight is the fail-fast alternative to $(shell) which relieves you from checking .SHELLSTATUS every time $(shell) is used.


    Makefile:

     makefile
        
    include  bmakelib/bmakelib.mk
    
    VAR1 := $(call bmakelib.shell.error-if-nonzero,\
               echo Fails hard❗ && false)
    
    unreachable-target :
    
      

    Shell:

     text
        
    $ make unreachable-target
    Makefile:3: *** shell.error-if-nonzero: Command exited with non-zero value 1.  Stop.
    
    
      
  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    bmakelib v0.6.0 with enums

    github.com Release v0.6.0 Β· bahmanm/bmakelib

    The highlight of this release is the introduction of enums (aka variants or options) which can be used to limit and validate a variable's value. For example: Makefile: define-enum : bmakelib.enum.d...

    Release v0.6.0 Β· bahmanm/bmakelib

    bmakelib is a collection of useful targets, recipes and variables you can use to augment your Makefiles.


    I just released bmakelib v0.6.0 w/ the main highlight being the ability to define enums and validate variable values against them.


    ➀ Makefile:

     Makefile
        
    define-enum : bmakelib.enum.define( DEPLOY-ENV/dev,staging,prod )
    include define-enum
    
    deploy : bmakelib.enum.error-unless-member( DEPLOY-ENV,ENV )
    deploy :
        @echo πŸš€ Deploying to $(ENV)...
    
      

    ➀ Shell:

     text
        
    $ make ENV=local-laptop deploy
    *** 'local-laptop' is not a member of enum 'DEPLOY-ENV'.  Stop.
    
    $ make ENV=prod deploy
    πŸš€ Deploying to prod...
    
      
  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    How do you comment your makefiles?

    Fed up w/ my ad-hoc scripts to display the targets and variables in a makefile(s), I've decided to write a reusable piece of code to do that: https://github.com/bahmanm/bmakelib/issues/81


    The first step toward that would be to understand the common commenting styles. So far I have identified 4 patterns in the wild which you can find below.

    Are there any style guides/conventions around this topic? Any references to well-written makefiles I can get inspiration from?


    A

     undefined
        
    VAR1 = foo   ## short one-liner comment
    my-target:   ## short one-liner comment 
        …
    
      

    B

     undefined
        
    # longer comment which 
    # may span
    # several lines
    VAR1 = foo
    
    ## comments can be prefixed w/ more than # 
    ## lorem ipsum dolor
    my-target: 
        …
    
      

    C

     undefined
        
    #####
    # a comment block which is marked w/ several #s on
    # an otherwise blank line
    #####
    VAR1 = foo
    
      

    D

     undefined
        
    #####
    #>    # heading 1
    #     This is a variation to have markdown comments
    #     inside makefile comments.
    #
    #     ## It's a made
      
  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    When writing a (GNU) Makefile, there are times when you need a particular target(s) to be run before anything else. That can be for example to check the environment, ensure variables are set or prepare a particular directory layout.

    ... take advantage of GNU Make's mechanism of includeing and makeing makefiles which is described in details in the manual:

  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    bmakelib - Print available Make targets and variables along w/ their docs

    I'm trying to gather requirements wrt a potential bmakelib feature linked in the post.

    I'd appreciate your feedback around:

    • What are the conventions you follow to document your Makefiles?
    • How/where do you usually declare variables and how do you document them?

    Please take a second to share your thoughts on the issue or simply reply to this post if you'd prefer πŸ™

  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    Variables in GNU Make: Simple and Recursive

    There are two major flavours of variables in GNU Make: "simple" and "recursive".

    While simple variables are quite simple and easy to understand, they can be limiting at times. On the other hand, recursive variables are powerful yet tricky.

    ...

    There is exactly one rule to recall when using recursive variables...

    🧠 The value of a recursive variable is computed every time it is expanded.

  • makefile @lemmy.ml
    bahmanm @lemmy.ml

    Using Make and cURL to measure Lemmy's performance

    A follow up on [DISCUSS] Website to monitor Lemmy servers' performance/availability


    I wanted to experiment w/ Lemmy's APIs to, eventually, build a public-facing performance monitoring solution for Lemmy.

    It started w/ a couple of shell commands which I found myself repeating. Then I recalled the saying "Don't repeat yourself - make Make make things happen for you!" and, well, stopped typing commands in bash.

    Instead I, incrementally, wrote a makefile to do the crud work for me (esp thanks to its declarative style): https://github.com/bahmanm/lemmy-clerk/blob/v0.0.1/run-clerk


    TBH there's nothing special about the file. But I thought I'd share this primarily b/c it is a demonstration of the patterns I usually use in my makefiles and I'd love some feedback on those.

    Additionally, it's a real world use-case for bmakelib (a library that I maintain 😎 )