Assuming you have installed GNUstep correctly and your environment is set up (all explained in the documentation) then you actually need to create a blank GNUmakefile in the root directory of your project and list your sources in that.
Here's a simple "Hello World" command line example:
Create a directory to contain your source code. HelloWorld would be a good idea.
In that, create files main.m
, Greeter.m
and Greeter.h
.
We'll create the Greeter
class which will just have one method -sayHelloToRecipient:
.
In the Greeter.h
:
#import <Foundation/Foundation.h>
@interface Greeter : NSObject {
}
-(void)sayHelloToRecipient:(NSString *)recipientName;
@end
And in the Greeter.m
:
#import "Greeter.h"
@implementation Greeter
-(void)sayHelloToRecipient:(NSString *)recipientName {
NSLog(@"Hello %@!", recipientName);
}
@end
Your main.m
file simply includes the Greeter
and invokes it with the argument @"World"
.
#import "Greeter.h"
int main(void) {
Greeter *greeter = [[Greeter alloc] init];
[greeter sayHelloToRecipient:@"World"];
[greeter release];
return 0;
}
Now you've got your sources ready to build, you just need to create a GNUmakefile
. Make an empty file, and start it with the line: include $(GNUSTEP_MAKEFILES)/common.make
, ending with the line include $(GNUSTPEP_MAKEFILES)/tool.make
.
The first line includes all the other makefiles and targets GNUstep provides. The last line includes the makefiles needed to produce a command line tool. If you were build a GUI app you'd include application.make
. For frameworks you'd include framework.make
etc.
include $(GNUSTEP_MAKEFILES)/common.make
# Your project-specific directives will go here
include $(GNUSTEP_MAKEFILES)/tool.make
The stuff you put between these lines is the stuff that changes from project to project.
The complete GNUmakefile
looks like this:
include $(GNUSTEP_MAKEFILES)/common.make
HELLO_ROOT_DIR = $(abspath .)
GNUSTEP_BUILD_DIR = $(HELLO_ROOT_DIR)/build
TOOL_NAME = HelloWorld
HelloWorld_OBJC_FILES = \
Greeter.m \
main.m
include $(GNUSTEP_MAKEFILES)/tool.make
HELLO_ROOT_DIR
is entirely optional and is just a variable that saves me from having to re-type the path to the root as the project grows (and so does the complexity of the makefile).
TOOL_NAME
is required for a command line tool and specifies both the output filename, and determines what you need to use for the *_OBJC_FILES
line (i.e. in this case I need to use HelloWorld_OBJC_FILES
because TOOL_NAME
is "HelloWorld".
With this in place, provided you're in the same directory as the makefile, you should be able to just type `make' to build the tool. It will create a "build" directory and inside that you'll find the executable. This one when invoked just outputs:
-$ ./build/obj/HelloWorld
2010-11-28 03:36:28.459 HelloWorld[12949] Hello World!
None of this will work however if your environment is not configured correctly. I've never done this on Windows, but I assume the same principles apply. That's running a shell script on Linux/UNIX (running batch file on Windows?) in order to configure the environment.
-$ . /usr/share/GNUstep/Makefiles/GNUstep.sh
You can check if it's correctly configured by printing the environment variable GNUSTEP_MAKEFILES
to the console:
-$ echo $GNUSTEP_MAKEFILES
(Not sure how you do this on Windows)
If it outputs nothing, your environment is not correctly configured and/or GNUstep is not correctly installed. If it outputs a path, you should be safe to run `make'.