Makefile 无法理解注释

发布于 2024-08-02 08:28:59 字数 2227 浏览 1 评论 0原文

如果我在 Makefile 中添加注释 (# ...),make 会给我一个错误并退出。如果我删除注释,makefile 就可以正常工作。

Makefile:1: *** missing separator. Stop.
  • Make 版本:3.81
  • Linux:Ubuntu 9.04

Makefile:

# Backup Makefile
#
# Create backups from various services and the system itself. This
# script is used to perform single backup tasks or a whole backup
# from the system. For more information about this file and how to
# use it, read the README file in the same directory.

BACKUP_ROOT = /srv/backup
ETC_PATH = /srv/config
SVN_PATH = /srv/svn/
TRAC_PATH = /srv/trac/sysinventory
PR10_PATH = /swsd/project/vmimages/...
PR10_MOUNT_PATH = /tmp/temp_sshfs_pr10

MYSQL_USER = "xxx"
MYSQL_PASSWORD = "xxx"


DATE = `date +%F`

help :
        cat README

init-environment :
        mkdir -p $(BACKUP_ROOT)
        mkdir $(BACKUP_ROOT)/tmp
        mkdir -p $(PR10_MOUNT_PATH)

backup : backup-mysql backup-configuration backup-svn backup-trac

upload-to-pr10 : mount-pr10
        tar cf $(DATE)-backup-blizzard.tar -C $(BACKUP_ROOT) *.-backup.tar.gz
        mv $(BACKUP_ROOT)/*-backup-blizzard.tar $(PR10_MOUNT_PATH)/
        umount $(PR10_MOUNT_PATH)

mount-pr10 :
        su xxx -d "sshfs -o allow_root xxx@xxx:$(PR10_PATH) $(PR10_MOUNT_PATH)"
        fusermount -u $(PR10_MOUNT_PATH)

backup-mysql :
        mysqldump --comments --user=$(MYSQL_USER) --password=$(MYSQL_PASSWORD) --all-databases --result-file=$(BACKUP_ROOT)/tmp/mysql_dump.sql
        tar czf $(BACKUP_ROOT)/$(DATE)-mysql-backup.tar.gz -C 
        $(BACKUP_ROOT)/tmp/mysql_dump.sql

backup-configuration :
        tar czf $(BACKUP_ROOT)/$(DATE)-configuration-backup.tar.gz $(ETC_PATH)/

backup-svn :
        svnadmin dump $(SVN_PATH)/repository > $(BACKUP_ROOT)/tmp/svn_repository.dump
        tar czf $(BACKUP_ROOT)/$(DATE)-subversion-backup.tar.gz -C $(BACKUP_ROOT)/tmp/svn_repository.dump

backup-trac :
        tar czf $(BACKUP_ROOT)/$(DATE)-trac-backup.tar.gz $(TRAC_PATH)/

clean :
        rm -f $(BACKUP_ROOT)/tmp/mysql_dump.sql
        rm -f $(BACKUP_ROOT)/tmp/svn_repository.dump
        rm -f $(BACKUP_ROOT)/*-backup.tar.gz
        rm -f $(BACKUP_ROOT)/*-backup-blizzard.tar

If I put comments (# ...) in my Makefile, make gives me an error and quit. If I remove the comments, the makefile works fine.

Makefile:1: *** missing separator. Stop.
  • Make-version: 3.81
  • Linux: Ubuntu 9.04

The Makefile:

# Backup Makefile
#
# Create backups from various services and the system itself. This
# script is used to perform single backup tasks or a whole backup
# from the system. For more information about this file and how to
# use it, read the README file in the same directory.

BACKUP_ROOT = /srv/backup
ETC_PATH = /srv/config
SVN_PATH = /srv/svn/
TRAC_PATH = /srv/trac/sysinventory
PR10_PATH = /swsd/project/vmimages/...
PR10_MOUNT_PATH = /tmp/temp_sshfs_pr10

MYSQL_USER = "xxx"
MYSQL_PASSWORD = "xxx"


DATE = `date +%F`

help :
        cat README

init-environment :
        mkdir -p $(BACKUP_ROOT)
        mkdir $(BACKUP_ROOT)/tmp
        mkdir -p $(PR10_MOUNT_PATH)

backup : backup-mysql backup-configuration backup-svn backup-trac

upload-to-pr10 : mount-pr10
        tar cf $(DATE)-backup-blizzard.tar -C $(BACKUP_ROOT) *.-backup.tar.gz
        mv $(BACKUP_ROOT)/*-backup-blizzard.tar $(PR10_MOUNT_PATH)/
        umount $(PR10_MOUNT_PATH)

mount-pr10 :
        su xxx -d "sshfs -o allow_root xxx@xxx:$(PR10_PATH) $(PR10_MOUNT_PATH)"
        fusermount -u $(PR10_MOUNT_PATH)

backup-mysql :
        mysqldump --comments --user=$(MYSQL_USER) --password=$(MYSQL_PASSWORD) --all-databases --result-file=$(BACKUP_ROOT)/tmp/mysql_dump.sql
        tar czf $(BACKUP_ROOT)/$(DATE)-mysql-backup.tar.gz -C 
        $(BACKUP_ROOT)/tmp/mysql_dump.sql

backup-configuration :
        tar czf $(BACKUP_ROOT)/$(DATE)-configuration-backup.tar.gz $(ETC_PATH)/

backup-svn :
        svnadmin dump $(SVN_PATH)/repository > $(BACKUP_ROOT)/tmp/svn_repository.dump
        tar czf $(BACKUP_ROOT)/$(DATE)-subversion-backup.tar.gz -C $(BACKUP_ROOT)/tmp/svn_repository.dump

backup-trac :
        tar czf $(BACKUP_ROOT)/$(DATE)-trac-backup.tar.gz $(TRAC_PATH)/

clean :
        rm -f $(BACKUP_ROOT)/tmp/mysql_dump.sql
        rm -f $(BACKUP_ROOT)/tmp/svn_repository.dump
        rm -f $(BACKUP_ROOT)/*-backup.tar.gz
        rm -f $(BACKUP_ROOT)/*-backup-blizzard.tar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假装不在乎 2024-08-09 08:28:59

你的 Makefile 对我有用(用制表符替换空格),所以听起来你有一个杂散的非打印字符的情况。

尝试检查“cat -vet Makefile”的输出。这将显示 EOL、TAB 和其他看不见的字符的位置。

您将希望看到类似这样的内容:

# Backup Makefile$
#$
# Create backups from various services and the system itself. This$
# script is used to perform single backup tasks or a whole backup$
# from the system. For more information about this file and how to$
# use it, read the README file in the same directory.$
$
BACKUP_ROOT = /srv/backup$
ETC_PATH = /srv/config$
SVN_PATH = /srv/svn/$
TRAC_PATH = /srv/trac/sysinventory$
PR10_PATH = /swsd/project/vmimages/...$
PR10_MOUNT_PATH = /tmp/temp_sshfs_pr10$
$
MYSQL_USER = "xxx"$
MYSQL_PASSWORD = "xxx"$
$
$
DATE = `date +%F`$
$
help :$
^Icat README$
$
$
init-environment :$
^Imkdir -p $(BACKUP_ROOT)$
^Imkdir $(BACKUP_ROOT)/tmp$
^Imkdir -p $(PR10_MOUNT_PATH)$
$

确保所有命令都以“^I”开头。

您还可以尝试使用以下方法查找杂散字符:

cat -vet Makefile | grep "\^[^I]" --colour=auto

Your Makefile works for me (with spaces replaced by tabs), so it sounds like you have a case of stray non-printing chars.

Try inspecting the output of "cat -vet Makefile". That will show where EOL, TAB and other unseen chars are.

You'll want to see something like this:

# Backup Makefile$
#$
# Create backups from various services and the system itself. This$
# script is used to perform single backup tasks or a whole backup$
# from the system. For more information about this file and how to$
# use it, read the README file in the same directory.$
$
BACKUP_ROOT = /srv/backup$
ETC_PATH = /srv/config$
SVN_PATH = /srv/svn/$
TRAC_PATH = /srv/trac/sysinventory$
PR10_PATH = /swsd/project/vmimages/...$
PR10_MOUNT_PATH = /tmp/temp_sshfs_pr10$
$
MYSQL_USER = "xxx"$
MYSQL_PASSWORD = "xxx"$
$
$
DATE = `date +%F`$
$
help :$
^Icat README$
$
$
init-environment :$
^Imkdir -p $(BACKUP_ROOT)$
^Imkdir $(BACKUP_ROOT)/tmp$
^Imkdir -p $(PR10_MOUNT_PATH)$
$

Make sure all commands are preceeded by "^I".

You could also try to looking for stray chars using something like:

cat -vet Makefile | grep "\^[^I]" --colour=auto
红ご颜醉 2024-08-09 08:28:59

您的评论可能使用了空格而不是制表符。
请发布 makefile,这样我们就不必猜测。

You may have used spaces instead of tabs for your comment.
Please post the makefile so we don't have to guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文