LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2007, 02:04 PM   #1
xface66
LQ Newbie
 
Registered: Dec 2006
Posts: 29

Rep: Reputation: 15
create shell script in makefile


hello everyone;
say i have java source files,
i must write a makefile that compiles the source files and creates an executable shell script

my shell script will be like this;

Code:
#! /bin/bash
$@
	make clean
	make all
	java Server $@
exit 0
when "make all" is typed this must generate the shell script file named "server"

how can i do this?
 
Old 05-07-2007, 07:22 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
This sounds an awful lot like homework. For fear that it is, here's some easy pointers:

a target gets defined by a word starting on column 1 & ending with a ':'
a line that starts with a <tab> will be run as a command - like it were run from the command line.

so, a makefile that looks like so:
Code:
foo:
	ls

bar:
	ls -l
will behave like so:

"make foo" will run "ls"
"make bar" will run "ls -l"

there can be more than one command per target - each needs it's own line. Thos commands can be anything - "ls", "g++ foo.C", "java bar", "rm *" - doesn't matter.

All those variables are nice & help you speed things up in the future, but they aren't necessary for now, so save that stuff for later.

btw - there's *loads* more to makefiles than this - this is just a start.

edit: after re-reading your post, the next to last line confuses me. "Server" should be a compiled java binary, right? In other words, your makefile should compile some java for you to a file called "Server" and then this shell script will execute that file - correct?

Last edited by BrianK; 05-07-2007 at 07:28 PM.
 
Old 05-08-2007, 04:26 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
or use suffixes and default rules:


Code:
.SUFFIXES: .java .class
COMPILE.java = /opt/j2sdk1.4.0_03/bin/javac
CLASSPATH = /opt/app/ipedo/ipedo3.2/lib/xmlclient.jar



.java.class:
 $(COMPILE.java) -classpath ${CLASSPATH}  $<
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can create shell script user52 Linux - Newbie 4 11-27-2006 11:16 AM
Create configure script, makefile etc. introuble Programming 2 07-26-2006 02:19 PM
Makefile call shell script thllgo Programming 4 12-28-2005 09:51 AM
Linux shell command for makefile.in to create a text file and write to it alix123 Programming 8 01-07-2005 08:18 AM
Shell Script and makefile thomasmathew Programming 11 12-23-2003 03:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration