diff --git a/Makefile b/Makefile
index a1f3c46a..30913fbf 100644
--- a/Makefile
+++ b/Makefile
@@ -28,10 +28,7 @@ all:
LUA = lua-5.2.1/src
LUA_FLAGS = -DUSE_LUA -I$(LUA) -L$(LUA) -llua -lm
-GCC_WARNS = -W -Wall -pedantic
-CFLAGS = -std=c99 -O2 $(GCC_WARNS) $(COPT)
-MAC_SHARED = -flat_namespace -bundle -undefined suppress
-LINFLAGS = -ldl -pthread $(CFLAGS)
+CFLAGS = -std=c99 -O2 -W -Wall -pedantic $(COPT)
LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX)
# Make sure that the compiler flags come last in the compilation string.
@@ -39,20 +36,20 @@ LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX)
# "-Wl,--as-needed" turned on by default in cc command.
# Also, this is turned in many other distros in static linkage builds.
linux:
- $(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) $(LINFLAGS)
- $(CC) mongoose.c main.c -o $(PROG) $(LINFLAGS)
+ $(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) -ldl -pthread $(CFLAGS)
+ $(CC) mongoose.c main.c -o $(PROG) -ldl -pthread $(CFLAGS)
bsd:
$(CC) mongoose.c -shared -pthread -fpic -fPIC -o $(LIB) $(CFLAGS)
$(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
mac:
- $(CC) mongoose.c -pthread -o $(LIB) $(MAC_SHARED) $(CFLAGS)
- $(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
+ $(CC) mongoose.c -pthread -o $(LIB) -flat_namespace -bundle -undefined suppress $(CFLAGS)
+ $(CC) mongoose.c main.c -DUSE_COCOA -pthread $(CFLAGS) -framework Cocoa -ObjC -arch i386 -arch x86_64 -o $(PROG)
+ V=`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' mongoose.c`; DIR=dmg/$(PROG).app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 build/mongoose_*.png $$DIR/Contents/Resources/ && install -m 644 build/Info.plist $$DIR/Contents/ && install -m 755 $(PROG) $$DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create $(PROG)_$$V.dmg -volname "Mongoose $$V" -srcfolder dmg -ov #; rm -rf dmg
solaris:
- $(CC) mongoose.c -pthread -lnsl \
- -lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS)
+ $(CC) mongoose.c -pthread -lnsl -lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS)
$(CC) mongoose.c main.c -pthread -lnsl -lsocket -o $(PROG) $(CFLAGS)
diff --git a/build/Info.plist b/build/Info.plist
index 91b4e144..6747ac3a 100644
--- a/build/Info.plist
+++ b/build/Info.plist
@@ -2,7 +2,17 @@
- CFBundleIconFile mongoose_16x16.png
- LSUIElement
+ CFBundleExecutable
+ mongoose
+ CFBundlePackageType
+ APPL
+ CFBundleTypeRole
+ None
+ CFBundleIconFiles
+
+ mongoose_16x16.png
+
+ LSUIElement
+
diff --git a/main.c b/main.c
index b8c2285e..3dab9c01 100644
--- a/main.c
+++ b/main.c
@@ -490,6 +490,87 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
// Return the WM_QUIT value.
return msg.wParam;
}
+#elif defined(USE_COCOA)
+#import
+
+@interface Mongoose : NSObject
+- (void) openBrowser;
+- (void) shutDown;
+@end
+
+@implementation Mongoose
+- (void) openBrowser {
+ [[NSWorkspace sharedWorkspace]
+ openURL:[NSURL URLWithString:
+ [NSString stringWithUTF8String:"http://www.yahoo.com"]]];
+}
+- (void) editConfig {
+ [[NSWorkspace sharedWorkspace]
+ openFile:@"mongoose.conf" withApplication:@"TextEdit"];
+}
+- (void)shutDown{
+ [NSApp terminate:nil];
+}
+@end
+
+int main(int argc, char *argv[]) {
+ init_server_name();
+ start_mongoose(argc, argv);
+
+ [NSAutoreleasePool new];
+ [NSApplication sharedApplication];
+
+ // Add delegate to process menu item actions
+ Mongoose *myDelegate = [[Mongoose alloc] autorelease];
+ [NSApp setDelegate: myDelegate];
+
+ // Run this app as agent
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
+ TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
+ SetFrontProcess(&psn);
+
+ // Add status bar menu
+ id menu = [[NSMenu new] autorelease];
+
+ // Add version menu item
+ [menu addItem:[[[NSMenuItem alloc]
+ //initWithTitle:[NSString stringWithFormat:@"%s", server_name]
+ initWithTitle:[NSString stringWithUTF8String:server_name]
+ action:@selector(noexist) keyEquivalent:@""] autorelease]];
+
+ // Add configuration menu item
+ [menu addItem:[[[NSMenuItem alloc]
+ initWithTitle:@"Edit configuration"
+ action:@selector(editConfig) keyEquivalent:@""] autorelease]];
+
+ // Add connect menu item
+ [menu addItem:[[[NSMenuItem alloc]
+ initWithTitle:@"Open web root in a browser"
+ action:@selector(openBrowser) keyEquivalent:@""] autorelease]];
+
+ // Separator
+ [menu addItem:[NSMenuItem separatorItem]];
+
+ // Add quit menu item
+ [menu addItem:[[[NSMenuItem alloc]
+ initWithTitle:@"Quit"
+ action:@selector(shutDown) keyEquivalent:@"q"] autorelease]];
+
+ // Attach menu to the status bar
+ id item = [[[NSStatusBar systemStatusBar]
+ statusItemWithLength:NSVariableStatusItemLength] retain];
+ [item setHighlightMode:YES];
+ [item setImage:[NSImage imageNamed:@"mongoose_22x22.png"]];
+ [item setMenu:menu];
+
+ // Run the app
+ [NSApp activateIgnoringOtherApps:YES];
+ [NSApp run];
+
+ mg_stop(ctx);
+
+ return EXIT_SUCCESS;
+}
#else
int main(int argc, char *argv[]) {
init_server_name();