gnu java_使用GNU Make来管理Java项目,IDE神马都是浮云

#Super's Java project MakefileVERSION_NUMBER:=1.0MAKE_VERSION:=$(shell make-v|head-1)#Location of trees.SOURCE_DIR:=src

OUT_CLASS_DIR:=classes

OUT_JAR_DIR:=dist

OUT_DOC_DIR:=doc

PROJLIB_DIR:=lib#Linux toolsAWK:=awk

FIND:=/usr/bin/findMKDIR:=mkdir-p

RM:=rm-rf

SHELL:=/bin/bash

SED:=sed

HEAD:=head

MKTEMP:=mktemp

MV:=mv#Path to support tools

# Use "?=" to set the variable a value if this variable hasn't been set

# Mostly, all these variables will be set in environment variablesJAVA_HOME?=/opt/jdk1.6.0_20

TOMCAT_HOME?=/opt/jakarta-tomcat-5.0.18#Java toolsJAVA:=$(JAVA_HOME)/bin/java

JAVAC:=$(JAVA_HOME)/bin/javac

JFLAGS:=-sourcepath $(SOURCE_DIR)-d $(OUT_CLASS_DIR)-source1.5#Enable assert and perform strict class checkingJVMFLAGS:=-ea-esa-Xfuture

JVM:=$(JAVA) $(JVMFLAGS)

JAR:=$(JAVA_HOME)/bin/jar

JARFLAGS:=cvf

JAVADOC:=$(JAVA_HOME)/bin/javadoc#javadoc compling optionsJDFLAGS:=-sourcepath $(SOURCE_DIR)-d $(OUT_DOC_DIR)-linkhttp://java.sun.com/j2se/1.5.0/docs/api#JarsLOG4J_JARS:=$(PROJLIB_DIR)/log4j-1.2.16.jar#Set the Java classpathclass_path:=OUT_CLASS_DIR LOG4J_JARS#space - A blank spacespace:=$(empty) $(empty)#Build classpath functions

# $(call build-classpath, variable-list)define build-classpath

$(strip\$(patsubst:%,%,\$(subst:,:,\$(strip\$(foreachj,$1,$(call get-file,$j):)))))

endef#$(call get-file, variable-name)define get-file

$(strip\$($1)\$(if$(call file-exists-eval,$1),,\$(warning The file referenced by variable\'$1'($($1)) cannot be found)))

endef#$(call file-exists-eval, variable-name)define file-exists-eval$(strip\$(if$($1),,$(warning'$1'hasnovalue))\$(wildcard $($1)))

endef#Check whether file exists

# $(call file-exists, wildcard-pattern)file-exists=$(wildcard $1)#$(call check-file, file-list)define check-file

$(foreachf,$1,\$(if$(call file-exists,$($f)),,\$(warning$f($($f)) is missing)))

endef#Jar MANIFEST file operations

# MANIFEST_TEMPLATE: We should use this template to customize our manifest file

# Pay attention NOT to use these PATTERN keywords because these keywords are replaced when making

# Manifest-Version: 1.0

# Built-By: PATTERN-BUILTBY

# Tool: PATTERN-TOOL

# Bundle-Name: PATTERN-BUNDLENAME

# Bundle-Vendor: PATTERN-BUNDLEVENDOR

# Bundle-Version: PATTERN-BUNDLEVERSION

# Name: PATTERN-NAME

# Implementation-Vendor: PATTERN-IMPLVENDOR

# Implementation-Title: PATTERN-IMPLTITLE

# Implementation-Version: PATTERN-IMPLVERSIONMANIFEST_TEMPLATE:=src/manifest/manifest.mf

TMP_JAR_DIR:=$(shell $(MKTEMP)-u-t make.XXXXXXXXXX)

TMP_MANIFEST:=$(TMP_JAR_DIR)/manifest.mf#$(call add-manifest, bundlename, packagename, jarfile)define add-manifest

$(MKDIR) $(TMP_JAR_DIR)

$(SED)-e"s/PATTERN-BUILTBY/Super.Zhang/g"\-e"s/PATTERN-TOOL/$(MAKE_VERSION)/g"\-e"s/PATTERN-BUNDLENAME/$1/g"\-e"s/PATTERN-BUNDLEVENDOR/Super.Zhang/g"\-e"s/PATTERN-BUNDLEVERSION/$(VERSION_NUMBER)/g"\-e"s/PATTERN-NAME/$2/g"\-e"s/PATTERN-IMPLVENDOR/Super.Zhang/g"\-e"s/PATTERN-IMPLTITLE/$1/g"\-e"s/PATTERN-IMPLVERSION/$(VERSION_NUMBER)/g"\$(MANIFEST_TEMPLATE)>$(TMP_MANIFEST)

$(JAR)-ufm $3$(TMP_MANIFEST)

$(RM) $(TMP_JAR_DIR)

endef#$(call make-jar,jar-variable-prefix)

# Be careful, "cd" will not change current working directory because Make start saparate

# processes for every command. So, just like next, if we wanna cd to a directory and do something,

# we should connect "cd" & corrosponding commands. And, next we don't need to "cd" back to orignal dir.define make-jar.PHONY:$1$($1_file)

$1:$($1_file)

$($1_file):$(MKDIR) $(OUT_JAR_DIR)

cd $(OUT_CLASS_DIR); $(JAR) $(JARFLAGS) $(notdir $@) $($1_packages)

$(MV) $(OUT_CLASS_DIR)/$(notdir $@) $(OUT_JAR_DIR)

$(call add-manifest,$($1_bundlename),$($1_packagename),$@)

endef#Set the CLASSPATH. GNU Make's export command can bring this variable into environment variablesexport CLASSPATH:=$(call build-classpath,$(class_path))#help - The default goal.PHONY:help

help:@echo'Help: make targets: all(compile, jars, javadoc), clean, classpath, check-config'#all - Perform all tasks for a complete build.PHONY:all

all:compile jars javadoc#all_javas - Temp file for holding source file listall_javas:=$(OUT_CLASS_DIR)/all.javas#compile - Compile the source.PHONY:compile

compile:$(all_javas)

$(JAVAC) $(JFLAGS)@mce_markerlt;#all_javas - Gather source file list..INTERMEDIATE:$(all_javas)

$(all_javas):$(MKDIR) $(OUT_CLASS_DIR)

$(FIND) $(SOURCE_DIR)-name'*.java'>$@#jar_list - List of all jars to createjar_list:=testcodes_jar#file, bundlename, packagename, packages are mandatorytestcodes_jar_file:=$(OUT_JAR_DIR)/testcodes.jar

testcodes_jar_bundlename:=JDK5 TestCodes

testcodes_jar_packagename:=testcodes

testcodes_jar_packages:=testcodes#jars - Create all jars.PHONY:jars

jars:$(jar_list)#Create jars$(foreachj,$(jar_list),$(eval$(call make-jar,$j)))#javadoc - Generate the Java doc from sources.PHONY:javadoc

javadoc:$(all_javas)

$(MKDIR) $(OUT_DOC_DIR)

$(JAVADOC) $(JDFLAGS)@mce_markerlt;.PHONY:clean

clean:$(RM) $(OUT_CLASS_DIR) $(OUT_DOC_DIR) $(OUT_JAR_DIR).PHONY:classpath

classpath:@echoCLASSPATH=$(strip $(CLASSPATH)).PHONY:check-config

check-config:@echoChecking configuration...$(call check-file,$(class_path) JAVA_HOME)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值