alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (Makefile)

This example Java source code file (Makefile) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

arch, cflags, echo, extra_libs, java_home, launcherlib, ldflags_common, libdir, linux, platform, uname

The Makefile Java example source code

#
#
# Makefile for building libLauncher.so
#
# To build libLauncher.so requires :-
#     JAVA_HOME environment variable 
#     cc (Solaris) or gcc (Linux) on PATH
#
# The library is created in a architecture specific directory :-
#
#     lib/solaris-sparc/libLauncher.so	(Solaris/SPARC)
#     lib/solaris-i586/libLauncher.so	(Solaris/x86)
#     lib/linux-i586/libLauncher.so	(Linux/x86)

ECHO  = echo
MKDIR = mkdir
UNAME = uname

uname := $(shell uname)

ifeq ($(uname), SunOS)
  PLATFORM = solaris
  ISAINFO = isainfo
  ARCH_DATA_MODEL=64
  ARCH := $(shell $(ISAINFO) -n)
  CC = cc
  LD = ld
  CFLAGS = -D_REENTRANT -D__solaris__
  LDFLAGS_COMMON = -G
  EXTRA_LIBS = -lc
  CC += -m64 -Kpic
endif

ifeq ($(uname), Linux)
  PLATFORM = linux
  archExpr = case "`$(UNAME) -m`" in  \
		i[3-6]86) \
                    $(ECHO) i586 \
                    ;; \
		sparc*)	 \
                    $(ECHO) sparc \
                    ;; \
		*) \
                    $(UNAME) -m	 \
                    ;; \
	   esac
  ARCH	    := $(shell $(archExpr) )
  CC = gcc
  CFLAGS = -fno-strict-aliasing -fPIC -W -Wall
  LD = ld
  LDFLAGS_COMMON = -shared
  EXTRA_LIBS = -lc
endif

LIBDIR=lib/$(PLATFORM)-$(ARCH)
LAUNCHERLIB=$(LIBDIR)/libLauncher.so

all: java_home $(LAUNCHERLIB)

$(LAUNCHERLIB) : $(LIBDIR) $(LIBDIR)/Launcher.o
	$(LD) $(LDFLAGS_COMMON) -o $(LAUNCHERLIB) $(LIBDIR)/Launcher.o $(EXTRA_LIBS)

$(LIBDIR):
	@$(MKDIR) -p $(LIBDIR)

$(LIBDIR)/Launcher.o : Launcher.c \
		       Launcher.h
	$(CC) -c $(CFLAGS) -o $(LIBDIR)/Launcher.o \
	    -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM) Launcher.c
	
Launcher.h : Launcher.class
	$(JAVA_HOME)/bin/javah -force Launcher

Launcher.class : Launcher.java
	$(JAVA_HOME)/bin/javac Launcher.java

java_home:
ifndef JAVA_HOME
	@$(ECHO) "ERROR: Your JAVA_HOME environment variable is not set."
	exit 1	
endif

Other Java examples (source code examples)

Here is a short list of links related to this Java Makefile source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.