I have this small Makefile here
SHELL = /bin/sh
.PHONY: clean all
all: ../../htdocs/css
../../htdocs/css: ../sass
cd ../../ && compass compile -e `cat .env | cut -d " " -f 1`
clean:
rm -f ../../htdocs/css/*
It does always rebuild. The directory '../../htdocs/css' does exist. Any ideas?
Related
I have a Makefile that looks like this:
RENDER_HTML=jupyter nbconvert --execute --to html
MATE40001_TARGETS=$(wildcard MATE40001/notes/*.ipynb)
.phony: all
all: MATE40001
.phony: variables
variables:
#echo MATE40001_TARGETS:
#echo ${MATE40001_TARGETS} | sed 's/ /\n/' | sed 's/MATE/\tMATE/'
.phony: MATE40001
MATE40001: ${MATE40001_TARGETS}
mkdir -p $#/html/
${RENDER_HTML} $^
mv $#/notes/*.html $#/html/
.phony: clean
clean:
rm -rf */html/ *~ */notes/*.html
When I run:
make
make clean
make
make MATE40001
I get the following output:
...
<normal output>
...
rm -rf */html/ *~ */notes/*.html
make: Nothing to be done for 'all'.
make: 'MATE40001' is up to date.
As far as I understand, make is looking for the file MATE40001 which exists as a folder and then stops because there are no updated files. However I do not want this to happen, and I thought that adding .phony: MATE40001 would stop this problem.
What do I need to add/change to fix this issue?
from comment by #G.M.
Use .PHONY instead of .phony
I'm trying to create my first RPM packages cross-compiled with Go.
Here is the Makefile which contains all the required information:
APPNAME?=helloworld
VERSION?=v1.0.0
APPANDVER := ${APPNAME}-$(VERSION)
# Build flags
LDFLAGS := -ldflags "-s -w -X=main.VERSION=$(VERSION)"
# Temporary directory for common files when creating tarballs
RELEASETMPDIR := $(shell mktemp -d -t ${APPNAME}-${VERSION}-release-XXXXXX)
# Cross-compile to these CPUs
# https://golang.org/doc/install/source#environment
LINUX_ARCHS := amd64 arm arm64 ppc64 ppc64le
default: release-bin
main.go:
#echo 'package main' > $#
#echo 'import "fmt"' >> $#
#echo '// Replaced with version when building' >> $#
#echo 'var VERSION = "v0.0.0"' >> $#
#echo 'func main() {' >> $#
#echo ' fmt.Println("Hello, world!")' >> $#
#echo '}' >> $#
#go fmt $#
README.md:
#echo 'This is a README for $(APPNAME) $(VERSION)' > $#
#echo '$(APPNAME) simply prints "Hello, world!"' >> $#
LICENSE:
#echo 'You can do what ever you want with $(APPNAME).' > $#
#echo 'You have all the responsibility!' >> $#
# Build for all listed architectures
linux-build: main.go
#for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux build... $$arch"; \
CGO_ENABLED=0 GOOS=linux GOARCH=$$arch go build $(LDFLAGS) -v -o ./bin/linux-$$arch/${APPNAME} . ; \
done
# Copy common files used in binary tarball releases
copycommon: README.md LICENSE
#echo "Copying common files to temporary release directory '$(RELEASETMPDIR)'.."
#mkdir "$(RELEASETMPDIR)/bin"
#cp -v "LICENSE" "$(RELEASETMPDIR)"
#cp -v "README.md" "$(RELEASETMPDIR)"
#mkdir --parents "$(PWD)/release/${VERSION}"
# Create binary release tarballs for each CPU architecture
compress-linux: linux-build
#for arch in $(LINUX_ARCHS); do \
echo "GNU/Linux tar... $$arch"; \
cp -v "$(PWD)/bin/linux-$$arch/${APPNAME}" "$(RELEASETMPDIR)/bin"; \
cd "$(RELEASETMPDIR)"; \
tar --numeric-owner --owner=0 --group=0 -zcvf "$(PWD)/release/${VERSION}/$(APPANDVER)-linux-$$arch.tar.gz" . ; \
rm "$(RELEASETMPDIR)/bin/${APPNAME}"; \
done
# Move all to temporary directory and compress with common files
compress-everything: copycommon compress-linux
#echo "$# ..."
rm -rf "$(RELEASETMPDIR)/*"
# Create tarballs which has common files and different bin/${APPNAME} per CPU architecture
release-bin: linux-build compress-everything
#echo "release done..."
# Linux distributions
release-ldistros: ldistro-rpm
#echo "Linux distros release done..."
release/linux/rpm:
#mkdir --parents ./release/linux/rpm
# RPM spec file (probably wrong)
release/linux/rpm/package.spec: release/linux/rpm
#echo 'Name: ${APPNAME}' > $#
#echo 'Version: %{_version}' >> $#
#echo 'Release: 1%{?dist}' >> $#
#echo 'Summary: Hello world' >> $#
#echo 'URL: https://example.org/${APPANDVER}/' >> $#
#echo 'Group: Applications/Utilities' >> $#
#echo 'License: Apache-2.0' >> $#
#echo '%description' >> $#
#echo '${APPNAME} is a command line program which prints "Hello, world!"' >> $#
#echo '%setup -q' >> $#
#echo '%clean' >> $#
#echo '%files' >> $#
#echo '%license /usr/share/licenses/%{NAME}/LICENSE' >> $#
#echo '%doc /usr/share/doc/%{NAME}/README.md' >> $#
#echo '/usr/bin/${APPNAME}' >> $#
#echo '%install' >> $#
#echo 'install -Dm755 "usr/bin/%{NAME}" -t "/usr/bin"' >> $#
# Create RPM package for each CPU architecture from tarballs (probably wrong)
ldistro-rpm: "release/linux/rpm/package.spec
#for arch in $(LINUX_ARCHS); do \
echo "Generating RPM... $$arch"; \
tempdir=$$(mktemp -d -t $(APPANDVER)-rpm-XXXXXX) ; \
echo " >> Using temporary directory $$tempdir" ; \
cd "$$tempdir" ; \
mkdir --parents {SOURCES,RPMS,SPECS,SRPMS,BUILD,tmp} ; \
cp "$(PWD)/release/linux/rpm/package.spec" "SPECS/${APPNAME}" ; \
cd "BUILD"; \
echo " >> Extracting source binary package.." ; \
tar -xzf "$(PWD)/release/${VERSION}/$(APPANDVER)-linux-$$arch.tar.gz" . ; \
echo " >> Generating directory structure in temp dir.." ; \
mkdir --parents ./usr/bin/ ; \
mv ./bin/${APPNAME} ./usr/bin/ ; \
rm -rf ./bin ; \
mkdir --parents ./usr/share/licenses/${APPNAME}/ ; \
mv LICENSE ./usr/share/licenses/${APPNAME} ; \
mkdir --parents ./usr/share/doc/${APPNAME}/ ; \
mv README.md ./usr/share/doc/${APPNAME} ; \
cd .. ; \
echo " >> Building RPM package.." ; \
sudo rpmbuild -vv --nosignature --nodebuginfo --dbpath "$$tempdir" --root "$$tempdir" --buildroot "./BUILD" --target $$arch --define "_tmppath /tmp" --define "_topdir ." --define "_version ${VERSION}" --define "_buildhost localhost" --define "_rpmfilename $(APPANDVER)-$$arch.rpm" -bb "SPECS/${APPNAME}" && \
rpm -qlp --info "./RPMS/$(APPANDVER)-$$arch.rpm" && \
cp "./RPMS/$(APPANDVER)-$$arch.rpm" "$(PWD)/release/${VERSION}/" ; \
echo "------------------------------------------------------------"; \
done
Create bin/$os-$cpuarch/$appname binaries:
% make linux-build
Create the binary source tarballs to release/$version/$appname-$version-$os-$cpuarch.tar.gz:
% make compress-everything
Created file tree structure inside tarballs:
bin/$appname (different for each architecture)
LICENSE
README.md
This structure is locked in as there are also different OS tarballs too. Different OS build targets are removed in this minimized example for readability reasons.
Generate RPMs for each CPU architecture:
% make ldistro-rpm
The current problem is that during RPM build the actual executables are being installed to the running system. AFAIK this should not happen. What I might be missing from the spec file or ldistro-rpm target? Also some rpmbuild examples seemed to only use -bb parameter but I couldn't find examples or figure out how to modify the spec file so that could work. The ldistro-rpm target seems overly complicated. Should some commands be in the spec file's %install, %prep, etc? Can you somehow use the Source0 in the spec file and point it to the tarball instead of generating the directory structure in the ldistro-rpm target?
#echo 'install -Dm755 "usr/bin/%{NAME}" -t "/usr/bin"'
Is where you are installing to /usr/bin You should install to $RPM_BUILD_ROOT/usr/bin instead.
I have this Makefile:
default:
mv presentacion.pdf /tmp
pdflatex presentacion.tex
clean:
rm -f *.{aux,log,nav,out,snm,toc}
The order make works well but when I try to do a make clean the shell outputs:
rm -f *.{aux,log,nav,out,snm,toc}
And does not remove the files. What's wrong in the code?
Try to set the shell to bash in your makefile (according docs)
SHELL=/bin/bash
default:
mv presentacion.pdf /tmp
pdflatex presentacion.tex
clean:
rm -f *.{aux,log,nav,out,snm,toc}
You can let make add the prefix to your files (instead of bash), by using addprefix:
PREFIXES := aux log nav out snm toc
FILES := $(addprefix *., $(PREFIXES))
default:
mv presentacion.pdf /tmp
pdflatex presentacion.tex
clean:
rm -f $(FILES)
My current Makefile.am looks something like this:
bin_PROGRAMS = MyProgram
AM_CPPFLAGS = -I../shared
MyProgram_SOURCES = main.cpp Source1.cpp ../shared/Source2.cpp
clean : clean-am
rm -f *~
rm -f DEADJOE
distclean: distclean-am
rm -f *~
rm -f DEADJOE
rm -f Makefile
rm -f *log
This creates all the .o files in the current directory. How can I specify a different object directory in a Makefile.am? I failed to find this in the GNU documentation, although I am sure it must be there somewhere.
You can't do this in Makefile.am. This approach is not generally supported by autoconf and automake at all.
Instead, Automake supports configuring and building outside the source tree. So in your current tree, "make distclean", then:
mkdir ../build
cd ../build
../src/configure
make
I have this rule in my Makefile, that responds to flags I pass:
$(BUILD_DIR)/disable_%:
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR)/disable_$*
rm -f $(BUILD_DIR)/enable_$*
cd $(BUILD_DIR) && rm -f Makefile
$(BUILD_DIR)/enable_%:
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR)/enable_$*
rm -f $(BUILD_DIR)/disable_$*
cd $(BUILD_DIR) && rm -f Makefile
What this means is that when changing the flags by which I invoke the makefile, I can trigger some recompilations that could depend on these flags.
The code presented above is a bit redundant: you see that I remove a file, touch another and remove a Makefile in both cases. The only thing that changes is the name of the files that I touch/remove, and they are related.
For instance,
make clean
make enable_debug=yes enable_video=no # will compile from zero
make enable_debug=no enable_video=no # flag change detected -> recompile some submodules that depend on this flag
Provided that the only thing that changes between the two rules ( [en|dis]able ), what I would like is to only have 1 generic rule, something like that:
# match 2 parts in the rule
$(BUILD_DIR)/%ble_%:
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR)/(???)ble_$* # should be $#
rm -f $(BUILD_DIR)/(???)able_$* # should be disable if $# is enable and inverse
cd $(BUILD_DIR) && rm -f Makefile
Is this possible ?
PS: Sorry if I didn't get the title correctly, I couldn't figure how to explain it better.
$(BUILD_DIR)/enable_% $(BUILD_DIR)/disable_%:
mkdir -p $(BUILD_DIR)
rm -f $(BUILD_DIR)/*able_$*
touch $#
cd $(BUILD_DIR) && rm -f Makefile
Not literally what you wanted (multi-wildcards are forbidden in make), but does quite the same.