Makefile - hqzhang/cloudtestbed GitHub Wiki

1.make for each item

LIST=hello world
all: hello world
	echo $^
$(SUBDIRS):
	gcc -o my [email protected]
run:
	./my
  1. make for each subdir
SUBDIRS := $(wildcard */.)
all: $(SUBDIRS)
$(SUBDIRS):
        $(MAKE) -C $@
.PHONY: all $(SUBDIRS)
  1. universal makefile

universal makefile

  1. makefile advanced

advanced makefile

  1. maven compiler
1). write pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jenkov</groupId>
    <artifactId>hello-world</artifactId>
    <version>1.0.0</version>
</project>

2). mkdir -p src/main/java/com/jenkov/app 
and then create App.java in it
package com.jenkov.app;
public class App {
        public static void main(String args[]){
                System.out.println("Hello World, Maven");
        }
}

3) mvn compile     //compile it into target/classes

4) mvn dependency:tree  /f/show deps

5) mvn package     // jar it into target/

6) mvn exec:exec   //run it by pom.xml
   java -cp target/classes  com.jenkov.app.App               //run it by class
   java -cp target/my-app-1.0-SNAPSHOT.jar com.jenkov.app.App //run it by jar

  1. ant compiler
write build.xml file
<?xml version="1.0"?>
<project name="Hello" default="compile">
    <target name="clean" description="remove intermediate files">
        <delete dir="classes"/>
    </target>
    <target name="clobber" depends="clean" description="remove all artifact files">
        <delete file="hello.jar"/>
    </target>
    <target name="compile" description="compile the Java source code to class files">
        <mkdir dir="classes"/>
        <javac srcdir="." destdir="classes"/>
    </target>
    <target name="jar" depends="compile" description="create a Jar file for the application">
        <jar destfile="hello.jar">
            <fileset dir="classes" includes="**/*.class"/>
            <manifest>
                <attribute name="Main-Class" value="HelloProgram"/>
            </manifest>
        </jar>
    </target>
</project>
write code file Hello.java
public class Hello {
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}
compile and running
ant compile  
ant jar
compile jar are defined in build.xml
⚠️ **GitHub.com Fallback** ⚠️