# Makefile for CygwinShellInterface classes (and C JNI code on Win32).
#   *** THIS Makefile REQUIRES GNU `make' ***
# Last Change: Mon Aug 19 07:00 AM 2002 EDT
# (C)2002 Soren Andersen <libertador@flashmail.com> All Rights Reserved
# This file is Free Software. It may be used, redistributed or modified
# only in compliance with the terms of the GNU Library General Public
# License (LGPL). Please see www.fsf.org for further information.

# TODO: (Aug 19 2002) 'clean' and 'install' targets.

TOP_SRCDIR = .
VPATH = $(TOP_SRCDIR)/src

#------- User Configuration may be required ---------------------------
# The author is using Sun java version "1.4.0_01" (JRE2SE). YMMV.
JAVAROOT = D:/java2
JAVAC = $(JAVAROOT)/bin/javac
JAVAH = $(JAVAROOT)/bin/javah
# MinGW: mingw32-gcc.exe ... "-mno-cygwin" is broken for me these days.
# The JNI code presently does NOT link to the Cygwin DLL, but probably
# should later on if this code gets developed further. At present, it
# uses Win32 API calls exclusively. What it does is very limited (it
# fetches the user-setting cygdrive prefix from the Registry).
CC = mingw32-gcc

INCL_DIRS = . $(addprefix $(JAVAROOT)/,include include/win32)
CFLAGS = -O2 -Wall $(addprefix -I,$(INCL_DIRS))
LDFLAGS = -shared -Wl,--export-all-symbols -Wl,--add-stdcall-alias
JAVACFLAGS = -verbose -d .
#--- User Configuration unlikely to be helpful below this point -------


#------- "productfilename" macros -------------------------------------
JPACKAG = CygwinShellInterface
CLASSES = CygwinShellPathXl8or.class \
     CygwinTestFor.class CygDrivePrefix.class
SOLIBSUFF = .dll
DLLNAME = Java_CygwinInterface$(SOLIBSUFF)

#------- sourcefilename macros ----------------------------------------
J_SRC = CygwinShellPathXl8or.java
C_SRC = Java_CygwinInterface.c
# Only two of the three generated headers are actually meaningful:
C_HDR = CygwinShellInterface_CygDrivePrefix.h \
     CygwinShellInterface_CygwinTestFor.h
INCLUDES = $(addprefix -include , \
 $(addprefix $(TOP_SRCDIR)/src/,$(C_HDR)))

#------- Dependencies -------------------------------------------------
.PHONY: all depcheck generated_JNI_headers
all: $(JPACKAG)/$(CLASSES) $(DLLNAME)

generated_JNI_headers: $(JPACKAG)/$(CLASSES)
    $(JAVAH) -verbose -d ./src  -classpath . \
 $(strip $(patsubst %.class,$(JPACKAG).%,$(CLASSES)))

$(JPACKAG)/$(CLASSES): $(J_SRC)
    $(JAVAC) $(JAVACFLAGS) $<

$(DLLNAME): $(C_SRC) generated_JNI_headers
    $(strip $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(INCLUDES))

#------- Other targets ------------------------------------------------
# Check your C dependencies.
depcheck: $(C_SRC)
    $(CC) $(CFLAGS) -E -H -M -MG $<


#------- Cleanup & installation: To-Do --------------------------------
# The .dll must go somewhere in the PATH that the JVM will see
# (your env PATH); the classes must go somewhere your CLASSPATH
# environmental variable points to, and they must be correctly
# placed (hierarchically) in a subdir named for the package
# ("CygwinShellInterface/"). Not too hard to do manually...


code syntax highlighting by GVIM, using the "nightshimmer" theme (modified).