Find the answer to your Linux question:
Results 1 to 3 of 3
Probably I am stupid but can not get it... I want to compile different projects within one Makefile. Something like that: #my makefile project.id = 01 lesson$(project.id).class: lesson$(project.id).java javac lesson$(project.id).java ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    11

    making makefile

    Probably I am stupid but can not get it...

    I want to compile different projects within one Makefile.
    Something like that:

    #my makefile

    project.id = 01

    lesson$(project.id).class: lesson$(project.id).java
    javac lesson$(project.id).java

    clean:
    rm -f *.class

    So, is it possible to assign the $(project.id) from command line?
    I mean externally not internally like it was in above example.

    Just like
    >make 'write here something simple to assign project id'

    Any ideas? Thank you

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Well, the simplest solution would be to simply have a different target for each lesson. So you have a target called "lesson01", a target called "lesson02", etc. Then you just call "make lesson01", "make lesson02", etc.

    The problem with this is that whenever you add a new lesson, you need to add a new line to the Makefile. Furthermore, each line in the Makefile will be very similar.

    The other approach is to use the ID variable and give it a value in the commandline:
    GNU Make - How to Run @code{make}

    This allows me to say:
    Code:
    make project.id=1
    The variable "project.id" is now 1 in the Makefile, and may be used accordingly.

    Does this help?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    11
    Code:
    make project.id=1
    It works perfectly. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...