Makefile作为shebang的可执行脚本?

时间:2011-08-19 14:41:36

标签: makefile shebang

是否可以创建一个可由make?

解释的可执行脚本

我试过了:

#!/usr/bin/env make --makefile=/dev/stdin

main:
        @echo Hello!

但它不起作用 - 挂起直到按 Ctrl-c

2 个答案:

答案 0 :(得分:23)

#!/usr/bin/make -f

main:
        @echo Hello World!

通常是标准make文件中所需的全部内容。文件名隐式传递为最后一个参数。 /dev/stdin这里(通常)是tty。如果有理由,你可以做整个env的事情,但通常没有必要。

ajw@rapunzel:~/code/videocc/tools > vi Makefile                       
ajw@rapunzel:~/code/videocc/tools > chmod a+x Makefile         
ajw@rapunzel:~/code/videocc/tools > ./Makefile                 
Hello World!

答案 1 :(得分:2)

下面增加了一个间接级别,但它是我为自动执行的makefile而不是“makefile”提出的最佳解决方案:

@Entity
@Table(name="lecturer")
public class LecturerEntity extends BaseEntity implements Serializable{
    private static final long serialVersionUID = 446089492592652000L;
    @Id
    @Column(name="id")
    @GeneratedValue
    private int id;
    @Column(name="lecturer_name")
    private String lecturerName;
    @ManyToOne
    @JoinColumn(name="department_id")
    private DepartmentEntity department;
}


@Entity
@Table(name="Department")
public class DepartmentEntity extends BaseEntity implements Serializable {
    private static final long serialVersionUID = -6221599323765325196L;
    @Id
    @Column(name="id")
    @GeneratedValue
    private int id;
    @Column(name="department_name")
    private String departmentName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy="department")
    private List<LecturerEntity> lecturers;
}



/*
 * One to Many Bidirectional DepartmentEntity and LecturerEntity
 */
departmentRepository = ctx.getBean(DepartmentRepository.class);
lecturerRepository = ctx.getBean(LecturerRepository.class);
department = new DepartmentEntity("Department");
List<LecturerEntity> lecturers = new ArrayList();
lecturers.add(new LecturerEntity("Lecturer 1"));
lecturers.add(new LecturerEntity("Lecturer 2"));
department.setDepartments(lecturers);
departmentRepository.saveDepartment(department);

我正在努力收集#! env hacks for each language / program here